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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@318322 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2017-11-15 19:09:22 +00:00
parent 0fe98240bd
commit 58a331a982
2 changed files with 46 additions and 30 deletions
+12 -5
View File
@@ -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);
}