diff options
author | Andrew Ng <anng.sw@gmail.com> | 2019-02-14 11:08:49 +0000 |
---|---|---|
committer | Andrew Ng <anng.sw@gmail.com> | 2019-02-14 11:08:49 +0000 |
commit | d27cf27eb1fe49a244260e53df8e93a1dc10f7c8 (patch) | |
tree | e4f6a38c1977629c0970a0b3f0f2e0d51a767361 /llvm/lib/Support/Path.cpp | |
parent | 7f95f963911853cea81f01c919b46676d7a95f52 (diff) | |
download | bcm5719-llvm-d27cf27eb1fe49a244260e53df8e93a1dc10f7c8.tar.gz bcm5719-llvm-d27cf27eb1fe49a244260e53df8e93a1dc10f7c8.zip |
[Support] Fix TempFile::discard to not leave behind temporary files
Moved the remove of the temporary file to after the close to avoid
remove failures caused by ETXTBSY errors.
This issue was seen when FileOutputBuffer falls back to an in memory
buffer due to the inability to mmap the on disk file. This occurred when
running LLD on an Ubuntu VM in VirtualBox on a Windows host attempting
to write the output to a VirtualBox shared folder.
Differential Revision: https://reviews.llvm.org/D57960
llvm-svn: 354017
Diffstat (limited to 'llvm/lib/Support/Path.cpp')
-rw-r--r-- | llvm/lib/Support/Path.cpp | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp index 8f580c66d24..202248c18d8 100644 --- a/llvm/lib/Support/Path.cpp +++ b/llvm/lib/Support/Path.cpp @@ -1128,26 +1128,27 @@ TempFile::~TempFile() { assert(Done); } Error TempFile::discard() { Done = true; - std::error_code RemoveEC; -// On windows closing will remove the file. -#ifndef _WIN32 - // Always try to close and remove. - if (!TmpName.empty()) { - RemoveEC = fs::remove(TmpName); - sys::DontRemoveFileOnSignal(TmpName); - } -#endif - - if (!RemoveEC) - TmpName = ""; - if (FD != -1 && close(FD) == -1) { std::error_code EC = std::error_code(errno, std::generic_category()); return errorCodeToError(EC); } FD = -1; +#ifdef _WIN32 + // On windows closing will remove the file. + TmpName = ""; + return Error::success(); +#else + // Always try to close and remove. + std::error_code RemoveEC; + if (!TmpName.empty()) { + RemoveEC = fs::remove(TmpName); + sys::DontRemoveFileOnSignal(TmpName); + if (!RemoveEC) + TmpName = ""; + } return errorCodeToError(RemoveEC); +#endif } Error TempFile::keep(const Twine &Name) { |