diff options
author | Jonas Devlieghere <jonas@devlieghere.com> | 2018-07-29 14:56:15 +0000 |
---|---|---|
committer | Jonas Devlieghere <jonas@devlieghere.com> | 2018-07-29 14:56:15 +0000 |
commit | ae1727e3ddf100a20f0c760c57fe8866756ea494 (patch) | |
tree | f996c3eb783307b68d371dc8849b39b60adab3ae /llvm/lib | |
parent | f52eeb11237af5bda4516668d3ee1784fd3b16c5 (diff) | |
download | bcm5719-llvm-ae1727e3ddf100a20f0c760c57fe8866756ea494.tar.gz bcm5719-llvm-ae1727e3ddf100a20f0c760c57fe8866756ea494.zip |
[dsymutil] Simplify temporary file handling.
Dsymutil's update functionality was broken on Windows because we tried
to rename a file while we're holding open handles to that file. TempFile
provides a solution for this through its keep(Twine) method. This patch
changes dsymutil to make use of that functionality.
Differential revision: https://reviews.llvm.org/D49860
llvm-svn: 338216
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Support/Path.cpp | 10 | ||||
-rw-r--r-- | llvm/lib/Support/Windows/Path.inc | 2 |
2 files changed, 8 insertions, 4 deletions
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp index a806da23ec5..098230290ed 100644 --- a/llvm/lib/Support/Path.cpp +++ b/llvm/lib/Support/Path.cpp @@ -1157,9 +1157,13 @@ Error TempFile::keep(const Twine &Name) { setDeleteDisposition(H, true); #else std::error_code RenameEC = fs::rename(TmpName, Name); - // If we can't rename, discard the temporary file. - if (RenameEC) - remove(TmpName); + if (RenameEC) { + // If we can't rename, try to copy to work around cross-device link issues. + RenameEC = sys::fs::copy_file(TmpName, Name); + // If we can't rename or copy, discard the temporary file. + if (RenameEC) + remove(TmpName); + } sys::DontRemoveFileOnSignal(TmpName); #endif diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc index f425d607af4..b64b013d740 100644 --- a/llvm/lib/Support/Windows/Path.inc +++ b/llvm/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_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED)) return std::error_code(); return mapWindowsError(GetLastError()); } |