[llvm] r247994 - Remove temporary file on signal.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 18 08:17:53 PDT 2015


Author: rafael
Date: Fri Sep 18 10:17:53 2015
New Revision: 247994

URL: http://llvm.org/viewvc/llvm-project?rev=247994&view=rev
Log:
Remove temporary file on signal.

Without this lld leaves temporary files behind when it crashes.

Modified:
    llvm/trunk/lib/Support/FileOutputBuffer.cpp

Modified: llvm/trunk/lib/Support/FileOutputBuffer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/FileOutputBuffer.cpp?rev=247994&r1=247993&r2=247994&view=diff
==============================================================================
--- llvm/trunk/lib/Support/FileOutputBuffer.cpp (original)
+++ llvm/trunk/lib/Support/FileOutputBuffer.cpp Fri Sep 18 10:17:53 2015
@@ -15,6 +15,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/Errc.h"
+#include "llvm/Support/Signals.h"
 #include <system_error>
 
 #if !defined(_MSC_VER) && !defined(__MINGW32__)
@@ -74,6 +75,8 @@ FileOutputBuffer::create(StringRef FileP
   if (EC)
     return EC;
 
+  sys::RemoveFileOnSignal(TempFilePath);
+
 #ifndef LLVM_ON_WIN32
   // On Windows, CreateFileMapping (the mmap function on Windows)
   // automatically extends the underlying file. We don't need to
@@ -104,6 +107,8 @@ std::error_code FileOutputBuffer::commit
 
 
   // Rename file to final name.
-  return sys::fs::rename(Twine(TempPath), Twine(FinalPath));
+  std::error_code EC = sys::fs::rename(Twine(TempPath), Twine(FinalPath));
+  sys::DontRemoveFileOnSignal(TempPath);
+  return EC;
 }
 } // namespace




More information about the llvm-commits mailing list