From a17fca06ee312baac84c39204982327f6f75ac83 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 15 Nov 2017 19:09:22 +0000 Subject: 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 --- llvm/lib/Support/Path.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'llvm/lib/Support') 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); } -- cgit v1.2.3