Skip to content

Commit

Permalink
Added alternate file rename strategy for when MoveFile fails with acc…
Browse files Browse the repository at this point in the history
…ess denied
  • Loading branch information
ccw808 committed Mar 7, 2019
1 parent 3a7c803 commit e9ce827
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Shared/sdk/SharedUtil.File.hpp
Expand Up @@ -91,8 +91,18 @@ bool SharedUtil::FileRename(const SString& strFilenameOld, const SString& strFil
#ifdef WIN32
if (MoveFileExW(FromUTF8(strFilenameOld), FromUTF8(strFilenameNew), MOVEFILE_COPY_ALLOWED) == 0)
{
int errorCode = GetLastError();
if (errorCode == ERROR_ACCESS_DENIED)
{
// Try alternate rename strategy
if (!FileExists(strFilenameNew) && FileCopy(strFilenameOld, strFilenameNew))
{
FileDelete(strFilenameOld);
return true;
}
}
if (pOutErrorCode)
*pOutErrorCode = GetLastError();
*pOutErrorCode = errorCode;
return false;
}
return true;
Expand Down

0 comments on commit e9ce827

Please sign in to comment.