mirror of
https://github.com/RPCS3/llvm.git
synced 2026-07-19 15:13:49 -04:00
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:
+12
-5
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user