[llvm] r338841 - [Windows FS] Allow moving files in TempFile::keep
Jeremy Morse via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 3 03:13:35 PDT 2018
Author: jmorse
Date: Fri Aug 3 03:13:35 2018
New Revision: 338841
URL: http://llvm.org/viewvc/llvm-project?rev=338841&view=rev
Log:
[Windows FS] Allow moving files in TempFile::keep
In r338216 / D49860 TempFile::keep was extended to allow keeping across
filesystems. The aim on Windows was to have this happen in rename_internal
using the existing system API. However, to fix an issue and preserve the
idea of "renaming" not being a move, put Windows keep-across-filesystem in
TempFile::keep.
Differential Revision: https://reviews.llvm.org/D50048
Modified:
llvm/trunk/lib/Support/Path.cpp
llvm/trunk/lib/Support/Windows/Path.inc
Modified: llvm/trunk/lib/Support/Path.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Path.cpp?rev=338841&r1=338840&r2=338841&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Path.cpp (original)
+++ llvm/trunk/lib/Support/Path.cpp Fri Aug 3 03:13:35 2018
@@ -1159,8 +1159,16 @@ Error TempFile::keep(const Twine &Name)
// If we can't cancel the delete don't rename.
auto H = reinterpret_cast<HANDLE>(_get_osfhandle(FD));
std::error_code RenameEC = setDeleteDisposition(H, false);
- if (!RenameEC)
+ if (!RenameEC) {
RenameEC = rename_fd(FD, Name);
+ // If rename failed because it's cross-device, copy instead
+ if (RenameEC ==
+ std::error_code(ERROR_NOT_SAME_DEVICE, std::system_category())) {
+ RenameEC = copy_file(TmpName, Name);
+ setDeleteDisposition(H, true);
+ }
+ }
+
// If we can't rename, discard the temporary file.
if (RenameEC)
setDeleteDisposition(H, true);
Modified: llvm/trunk/lib/Support/Windows/Path.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Path.inc?rev=338841&r1=338840&r2=338841&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/Path.inc (original)
+++ llvm/trunk/lib/Support/Windows/Path.inc Fri Aug 3 03:13:35 2018
@@ -450,7 +450,7 @@ static std::error_code rename_handle(HAN
if (std::error_code EC2 = realPathFromHandle(FromHandle, WideFrom))
return EC2;
if (::MoveFileExW(WideFrom.begin(), WideTo.begin(),
- MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED))
+ MOVEFILE_REPLACE_EXISTING))
return std::error_code();
return mapWindowsError(GetLastError());
}
More information about the llvm-commits
mailing list