[llvm] r318725 - Split a rename_handle out of rename on windows.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 20 17:52:44 PST 2017
Author: rafael
Date: Mon Nov 20 17:52:44 2017
New Revision: 318725
URL: http://llvm.org/viewvc/llvm-project?rev=318725&view=rev
Log:
Split a rename_handle out of rename on windows.
Modified:
llvm/trunk/lib/Support/Windows/Path.inc
Modified: llvm/trunk/lib/Support/Windows/Path.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Path.inc?rev=318725&r1=318724&r2=318725&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/Path.inc (original)
+++ llvm/trunk/lib/Support/Windows/Path.inc Mon Nov 20 17:52:44 2017
@@ -418,14 +418,13 @@ static std::error_code rename_internal(H
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;
- SmallVector<wchar_t, 128> WideTo;
if (std::error_code EC = widenPath(From, WideFrom))
return EC;
- if (std::error_code EC = widenPath(To, WideTo))
- return EC;
ScopedFileHandle FromHandle;
// Retry this a few times to defeat badly behaved file system scanners.
@@ -442,6 +441,14 @@ std::error_code rename(const Twine &From
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))
+ return EC;
+
// We normally expect this loop to succeed after a few iterations. If it
// requires more than 200 tries, it's more likely that the failures are due to
// a true error, so stop trying.
@@ -452,6 +459,9 @@ std::error_code rename(const Twine &From
std::error_code(ERROR_CALL_NOT_IMPLEMENTED, std::system_category())) {
// Wine doesn't support SetFileInformationByHandle in rename_internal.
// Fall back to MoveFileEx.
+ SmallVector<wchar_t, MAX_PATH> WideFrom;
+ if (std::error_code EC2 = realPathFromHandle(FromHandle, WideFrom))
+ return EC2;
if (::MoveFileExW(WideFrom.begin(), WideTo.begin(),
MOVEFILE_REPLACE_EXISTING))
return std::error_code();
More information about the llvm-commits
mailing list