Skip to content

Commit

Permalink
move static function. NFC
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@318729 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
espindola committed Nov 21, 2017
1 parent 98ed2b2 commit d713fe1
Showing 1 changed file with 24 additions and 26 deletions.
50 changes: 24 additions & 26 deletions lib/Support/Windows/Path.inc
Original file line number Diff line number Diff line change
Expand Up @@ -418,32 +418,6 @@ static std::error_code rename_internal(HANDLE FromHandle, const Twine &To,
return std::error_code();
}

static std::error_code rename_handle(HANDLE Handle, const Twine &To);

std::error_code rename(const Twine &From, const Twine &To) {
// Convert to utf-16.
SmallVector<wchar_t, 128> WideFrom;
if (std::error_code EC = widenPath(From, WideFrom))
return EC;

ScopedFileHandle FromHandle;
// Retry this a few times to defeat badly behaved file system scanners.
for (unsigned Retry = 0; Retry != 200; ++Retry) {
if (Retry != 0)
::Sleep(10);
FromHandle =
::CreateFileW(WideFrom.begin(), GENERIC_READ | DELETE,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (FromHandle)
break;
}
if (!FromHandle)
return mapWindowsError(GetLastError());

return rename_handle(FromHandle, To);
}

static std::error_code rename_handle(HANDLE FromHandle, const Twine &To) {
SmallVector<wchar_t, 128> WideTo;
if (std::error_code EC = widenPath(To, WideTo))
Expand Down Expand Up @@ -539,6 +513,30 @@ static std::error_code rename_handle(HANDLE FromHandle, const Twine &To) {
return errc::permission_denied;
}

std::error_code rename(const Twine &From, const Twine &To) {
// Convert to utf-16.
SmallVector<wchar_t, 128> WideFrom;
if (std::error_code EC = widenPath(From, WideFrom))
return EC;

ScopedFileHandle FromHandle;
// Retry this a few times to defeat badly behaved file system scanners.
for (unsigned Retry = 0; Retry != 200; ++Retry) {
if (Retry != 0)
::Sleep(10);
FromHandle =
::CreateFileW(WideFrom.begin(), GENERIC_READ | DELETE,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (FromHandle)
break;
}
if (!FromHandle)
return mapWindowsError(GetLastError());

return rename_handle(FromHandle, To);
}

std::error_code resize_file(int FD, uint64_t Size) {
#ifdef HAVE__CHSIZE_S
errno_t error = ::_chsize_s(FD, Size);
Expand Down

0 comments on commit d713fe1

Please sign in to comment.