summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Path.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2017-11-15 19:09:22 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2017-11-15 19:09:22 +0000
commita17fca06ee312baac84c39204982327f6f75ac83 (patch)
tree62565e3d4ea9c07870978406f3a5fef246aa2d6c /llvm/lib/Support/Path.cpp
parent0f0837e84e16f0b88213b372ced02e9eb35fcf3c (diff)
downloadbcm5719-llvm-a17fca06ee312baac84c39204982327f6f75ac83.tar.gz
bcm5719-llvm-a17fca06ee312baac84c39204982327f6f75ac83.zip
Use TempFile in lto caching.
This requires a small change to TempFile: allowing a discard after a failed keep. With this the cache now handles signals and reuses a fd instead of reopening the file. llvm-svn: 318322
Diffstat (limited to 'llvm/lib/Support/Path.cpp')
-rw-r--r--llvm/lib/Support/Path.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp
index 63ea9119fab..5f0adb337b9 100644
--- a/llvm/lib/Support/Path.cpp
+++ b/llvm/lib/Support/Path.cpp
@@ -772,13 +772,14 @@ TempFile &TempFile::operator=(TempFile &&Other) {
TempFile::~TempFile() { assert(Done); }
Error TempFile::discard() {
- if (Done)
- return Error::success();
Done = true;
// Always try to close and remove.
- std::error_code RemoveEC = fs::remove(TmpName);
- sys::DontRemoveFileOnSignal(TmpName);
- if (close(FD) == -1) {
+ std::error_code RemoveEC;
+ if (!TmpName.empty()) {
+ RemoveEC = fs::remove(TmpName);
+ sys::DontRemoveFileOnSignal(TmpName);
+ }
+ if (FD != -1 && close(FD) == -1) {
std::error_code EC = std::error_code(errno, std::generic_category());
return errorCodeToError(EC);
}
@@ -791,10 +792,16 @@ Error TempFile::keep(const Twine &Name) {
// Always try to close and rename.
std::error_code RenameEC = fs::rename(TmpName, Name);
sys::DontRemoveFileOnSignal(TmpName);
+
+ if (!RenameEC)
+ TmpName = "";
+
if (close(FD) == -1) {
std::error_code EC(errno, std::generic_category());
return errorCodeToError(EC);
}
+ FD = -1;
+
return errorCodeToError(RenameEC);
}
OpenPOWER on IntegriCloud