Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry directory creation when ERROR_ALREADY_EXISTS is returned. #118

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions src/stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,23 +246,30 @@ BOOL OpCreateInstDirectory(LPVOID* p)
GetTempPath(MAX_PATH, TempPath);
}

UINT tempResult = GetTempFileName(TempPath, _T("ocrastub"), 0, InstDir);
if (tempResult == 0u)
while (TRUE)
{
FATAL("Failed to get temp file name.");
return FALSE;
}
UINT tempResult = GetTempFileName(TempPath, _T("ocrastub"), 0, InstDir);
if (tempResult == 0u)
{
FATAL("Failed to get temp file name.");
return FALSE;
}

DEBUG("Creating installation directory: '%s'", InstDir);
DEBUG("Creating installation directory: '%s'", InstDir);

/* Attempt to delete the temp file created by GetTempFileName.
Ignore errors, i.e. if it doesn't exist. */
(void)DeleteFile(InstDir);
/* Attempt to delete the temp file created by GetTempFileName.
Ignore errors, i.e. if it doesn't exist. */
(void)DeleteFile(InstDir);

if (!CreateDirectory(InstDir, NULL))
{
FATAL("Failed to create installation directory.");
return FALSE;
if (CreateDirectory(InstDir, NULL))
{
break;
}
else if (GetLastError() != ERROR_ALREADY_EXISTS)
{
FATAL("Failed to create installation directory.");
return FALSE;
}
}
return TRUE;
}
Expand Down