summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2018-08-17 14:28:33 +0000
committerHans Wennborg <hans@hanshq.net>2018-08-17 14:28:33 +0000
commit98aa61ba49b54902a7afc27c9aa6c562646be76f (patch)
treef1f21953d25d59200f0ee2e4eb643cbc4cc95207
parentdff83e99c9120289d8da0cbd89ab0b9ddd3e8971 (diff)
Merging r338841:
------------------------------------------------------------------------ r338841 | jmorse | 2018-08-03 12:13:35 +0200 (Fri, 03 Aug 2018) | 11 lines [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 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_70@340030 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Support/Path.cpp10
-rw-r--r--lib/Support/Windows/Path.inc2
2 files changed, 10 insertions, 2 deletions
diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp
index 098230290ed..768a819c8d0 100644
--- a/lib/Support/Path.cpp
+++ b/lib/Support/Path.cpp
@@ -1150,8 +1150,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);
diff --git a/lib/Support/Windows/Path.inc b/lib/Support/Windows/Path.inc
index b64b013d740..f425d607af4 100644
--- a/lib/Support/Windows/Path.inc
+++ b/lib/Support/Windows/Path.inc
@@ -450,7 +450,7 @@ static std::error_code rename_handle(HANDLE FromHandle, const Twine &To) {
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());
}