[llvm] r354017 - [Support] Fix TempFile::discard to not leave behind temporary files
Andrew Ng via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 14 03:08:49 PST 2019
Author: anng
Date: Thu Feb 14 03:08:49 2019
New Revision: 354017
URL: http://llvm.org/viewvc/llvm-project?rev=354017&view=rev
Log:
[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
Modified:
llvm/trunk/lib/Support/Path.cpp
Modified: llvm/trunk/lib/Support/Path.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Path.cpp?rev=354017&r1=354016&r2=354017&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Path.cpp (original)
+++ llvm/trunk/lib/Support/Path.cpp Thu Feb 14 03:08:49 2019
@@ -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) {
More information about the llvm-commits
mailing list