tst: winfsp-tests: --resilient command line option

This commit is contained in:
Bill Zissimopoulos
2016-10-25 14:50:12 -07:00
parent 66d5fe98df
commit 319e5d4ee6
3 changed files with 51 additions and 7 deletions

View File

@ -17,6 +17,7 @@ int NtfsTests = 0;
int WinFspDiskTests = 1;
int WinFspNetTests = 1;
BOOLEAN OptResilient = FALSE;
BOOLEAN OptCaseInsensitive = FALSE;
BOOLEAN OptCaseRandomize = FALSE;
WCHAR OptMountPointBuf[MAX_PATH], *OptMountPoint;
@ -201,6 +202,37 @@ HANDLE HookCreateFileW(
return h;
}
#undef DeleteFileW
BOOL HookDeleteFileW(
LPCWSTR lpFileName)
{
BOOL Success;
DWORD LastError;
Success = DeleteFileW(lpFileName);
LastError = GetLastError();
if (OptResilient && !Success)
{
ULONG MaxTries = 10;
while (!Success && ERROR_SHARING_VIOLATION == LastError && 0 != MaxTries--)
{
Sleep(300);
Success = DeleteFileW(lpFileName);
}
}
else
{
ULONG MaxTries = 3;
while (INVALID_FILE_ATTRIBUTES != GetFileAttributes(lpFileName) && 0 != MaxTries--)
{
Sleep(300);
}
}
SetLastError(LastError);
return Success;
}
static VOID DisableBackupRestorePrivileges(VOID)
{
union
@ -227,7 +259,7 @@ static VOID DisableBackupRestorePrivileges(VOID)
CloseHandle(Token);
}
VOID AddNetShareIfNeeded(VOID)
static VOID AddNetShareIfNeeded(VOID)
{
if (!OptShareName)
return;
@ -247,7 +279,7 @@ VOID AddNetShareIfNeeded(VOID)
ABORT("cannot add network share");
}
VOID RemoveNetShareIfNeeded(VOID)
static VOID RemoveNetShareIfNeeded(VOID)
{
if (!OptShareName)
return;
@ -308,6 +340,11 @@ int main(int argc, char *argv[])
WinFspNetTests = 0;
rmarg(argv, argc, argi);
}
else if (0 == strcmp("--resilient", a))
{
OptResilient = TRUE;
rmarg(argv, argc, argi);
}
else if (0 == strcmp("--case-insensitive", a))
{
OptCaseInsensitive = TRUE;