From fe161b9d961218996a33cfec135d77bc8c96afc7 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 22 Nov 2017 19:59:05 +0000 Subject: Allow TempFile::discard to be called twice. We already allowed keep+discard. It is important to be able to discard a temporary if a rename fail. It is also convenient as it allows the use of RAII for discarding. Allow discarding twice for similar reasons. llvm-svn: 318867 --- llvm/lib/Support/Path.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'llvm/lib') diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp index b96396a3846..cb8e5a8d5f7 100644 --- a/llvm/lib/Support/Path.cpp +++ b/llvm/lib/Support/Path.cpp @@ -779,10 +779,16 @@ Error TempFile::discard() { RemoveEC = fs::remove(TmpName); sys::DontRemoveFileOnSignal(TmpName); } + + if (!RemoveEC) + TmpName = ""; + if (FD != -1 && close(FD) == -1) { std::error_code EC = std::error_code(errno, std::generic_category()); return errorCodeToError(EC); } + FD = -1; + return errorCodeToError(RemoveEC); } -- cgit v1.2.3