From 205a59dbc6d5cc8f7195e4b2e593d449fa3ee945 Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Wed, 26 Oct 2016 14:36:38 -0700 Subject: [PATCH] tst: winfsp-tests: ResilientRemoveDirectoryW --- tst/winfsp-tests/hooks.c | 3 ++- tst/winfsp-tests/resilient.c | 26 ++++++++++++++++++++++++++ tst/winfsp-tests/winfsp-tests.h | 2 ++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/tst/winfsp-tests/hooks.c b/tst/winfsp-tests/hooks.c index 5cdee439..1a5e2c7e 100644 --- a/tst/winfsp-tests/hooks.c +++ b/tst/winfsp-tests/hooks.c @@ -208,7 +208,8 @@ BOOL HookRemoveDirectoryW( PrepareFileName(lpPathName, FileNameBuf); MaybeAdjustTraversePrivilege(FALSE); - Success = RemoveDirectoryW(FileNameBuf); + Success = (OptResilient ? ResilientRemoveDirectoryW : RemoveDirectoryW)( + FileNameBuf); MaybeAdjustTraversePrivilege(TRUE); return Success; } diff --git a/tst/winfsp-tests/resilient.c b/tst/winfsp-tests/resilient.c index 4333732b..5ce45b71 100644 --- a/tst/winfsp-tests/resilient.c +++ b/tst/winfsp-tests/resilient.c @@ -116,6 +116,32 @@ BOOL ResilientDeleteFileW( return Success; } +BOOL ResilientRemoveDirectoryW( + LPCWSTR lpPathName) +{ + BOOL Success; + DWORD LastError; + + Success = RemoveDirectoryW(lpPathName); + LastError = GetLastError(); + + if (Success) + WaitDeletePending(lpPathName); + else + { + for (ULONG MaxTries = DeleteMaxTries; + !Success && ERROR_SHARING_VIOLATION == GetLastError() && 0 != MaxTries; + MaxTries--) + { + Sleep(DeleteSleepTimeout); + Success = RemoveDirectoryW(lpPathName); + } + } + + SetLastError(LastError); + return Success; +} + static VOID WaitDeletePending(PCWSTR FileName) { for (ULONG MaxTries = DeleteMaxTries; 0 != MaxTries; MaxTries--) diff --git a/tst/winfsp-tests/winfsp-tests.h b/tst/winfsp-tests/winfsp-tests.h index e8e89905..824303f0 100644 --- a/tst/winfsp-tests/winfsp-tests.h +++ b/tst/winfsp-tests/winfsp-tests.h @@ -105,6 +105,8 @@ BOOL ResilientCloseHandle( HANDLE hObject); BOOL ResilientDeleteFileW( LPCWSTR lpFileName); +BOOL ResilientRemoveDirectoryW( + LPCWSTR lpPathName); typedef struct {