From: Rafael Espindola Date: Fri, 18 Sep 2015 15:17:53 +0000 (+0000) Subject: Remove temporary file on signal. X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=e016c66756f9a47c169c352ca900fe5b376a896a Remove temporary file on signal. Without this lld leaves temporary files behind when it crashes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247994 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Support/FileOutputBuffer.cpp b/lib/Support/FileOutputBuffer.cpp index e68ecaaa98c..651e679f2cb 100644 --- a/lib/Support/FileOutputBuffer.cpp +++ b/lib/Support/FileOutputBuffer.cpp @@ -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 #if !defined(_MSC_VER) && !defined(__MINGW32__) @@ -74,6 +75,8 @@ FileOutputBuffer::create(StringRef FilePath, size_t Size, unsigned Flags) { 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