forked from OSchip/llvm-project
parent
fc1ff29966
commit
811d5e86a2
|
@ -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))
|
||||
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue