summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/FileOutputBuffer.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2015-09-18 15:17:53 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2015-09-18 15:17:53 +0000
commit7dbb577826247abd146b44398e32849f1c87ef2c (patch)
treeb1f2bc77adbc917318899f1b5a60984172e45d74 /llvm/lib/Support/FileOutputBuffer.cpp
parenta89b833c4f7a43e33f888176dd4aea2e45762564 (diff)
downloadbcm5719-llvm-7dbb577826247abd146b44398e32849f1c87ef2c.tar.gz
bcm5719-llvm-7dbb577826247abd146b44398e32849f1c87ef2c.zip
Remove temporary file on signal.
Without this lld leaves temporary files behind when it crashes. llvm-svn: 247994
Diffstat (limited to 'llvm/lib/Support/FileOutputBuffer.cpp')
-rw-r--r--llvm/lib/Support/FileOutputBuffer.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/llvm/lib/Support/FileOutputBuffer.cpp b/llvm/lib/Support/FileOutputBuffer.cpp
index e68ecaaa98c..651e679f2cb 100644
--- a/llvm/lib/Support/FileOutputBuffer.cpp
+++ b/llvm/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 <system_error>
#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
OpenPOWER on IntegriCloud