From 20569e96e9403780e1229f31c48add56c3fc284a Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 5 Dec 2017 16:40:56 +0000 Subject: Delete temp file if rename fails. Without this when lld failed to replace the output file it would leave the temporary behind. The problem is that the existing logic is - cancel the delete flag - rename We have to cancel first to avoid renaming and then crashing and deleting the old version. What is missing then is deleting the temporary file if the rename fails. This can be an issue on both unix and windows, but I am not sure how to cause the rename to fail reliably on unix. I think it can be done on ZFS since it has an ACL system similar to what windows uses, but adding support for checking that in llvm-lit is probably not worth it. llvm-svn: 319786 --- llvm/lib/Support/Path.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'llvm/lib/Support/Path.cpp') diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp index d4b9d02e030..f229f23a4f8 100644 --- a/llvm/lib/Support/Path.cpp +++ b/llvm/lib/Support/Path.cpp @@ -1099,8 +1099,14 @@ Error TempFile::keep(const Twine &Name) { std::error_code RenameEC = cancelDeleteOnClose(FD); if (!RenameEC) RenameEC = rename_fd(FD, Name); + // If we can't rename, discard the temporary file. + if (RenameEC) + removeFD(FD); #else std::error_code RenameEC = fs::rename(TmpName, Name); + // If we can't rename, discard the temporary file. + if (RenameEC) + remove(TmpName); sys::DontRemoveFileOnSignal(TmpName); #endif -- cgit v1.2.3