diff options
author | Martin Storsjö <martin@martin.st> | 2021-10-28 10:57:27 +0300 |
---|---|---|
committer | Martin Storsjö <martin@martin.st> | 2021-11-03 21:29:37 +0200 |
commit | a39eba720744e6936cbf4ea6cc0a7fb1d7527e57 (patch) | |
tree | de78f343d5d3088346fdd4ce9ec876af3c82c6e6 /llvm/lib/Support/Path.cpp | |
parent | 7ff943a9ed878e3b8ffe162b2af41a81da1a11a2 (diff) | |
download | llvm-a39eba720744e6936cbf4ea6cc0a7fb1d7527e57.zip llvm-a39eba720744e6936cbf4ea6cc0a7fb1d7527e57.tar.gz llvm-a39eba720744e6936cbf4ea6cc0a7fb1d7527e57.tar.bz2 |
[Support] [Windows] Use RemoveFileOnSignal if unable to use the delete-on-close flag
This takes care of cleaning up the temp files on crashes. It doesn't
handle cleanup when explicitly killed though.
Differential Revision: https://reviews.llvm.org/D112710
Diffstat (limited to 'llvm/lib/Support/Path.cpp')
-rw-r--r-- | llvm/lib/Support/Path.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp index a5045f6..536d114 100644 --- a/llvm/lib/Support/Path.cpp +++ b/llvm/lib/Support/Path.cpp @@ -1212,9 +1212,7 @@ Error TempFile::discard() { std::error_code RemoveEC; if (Remove && !TmpName.empty()) { RemoveEC = fs::remove(TmpName); -#ifndef _WIN32 sys::DontRemoveFileOnSignal(TmpName); -#endif if (!RemoveEC) TmpName = ""; } else { @@ -1260,8 +1258,8 @@ Error TempFile::keep(const Twine &Name) { if (RenameEC) remove(TmpName); } - sys::DontRemoveFileOnSignal(TmpName); #endif + sys::DontRemoveFileOnSignal(TmpName); if (!RenameEC) TmpName = ""; @@ -1283,9 +1281,8 @@ Error TempFile::keep() { auto H = reinterpret_cast<HANDLE>(_get_osfhandle(FD)); if (std::error_code EC = setDeleteDisposition(H, false)) return errorCodeToError(EC); -#else - sys::DontRemoveFileOnSignal(TmpName); #endif + sys::DontRemoveFileOnSignal(TmpName); TmpName = ""; @@ -1309,17 +1306,20 @@ Expected<TempFile> TempFile::create(const Twine &Model, unsigned Mode, TempFile Ret(ResultPath, FD); #ifdef _WIN32 auto H = reinterpret_cast<HANDLE>(_get_osfhandle(FD)); + bool SetSignalHandler = false; if (std::error_code EC = setDeleteDisposition(H, true)) { Ret.RemoveOnClose = true; + SetSignalHandler = true; } #else - if (sys::RemoveFileOnSignal(ResultPath)) { + bool SetSignalHandler = true; +#endif + if (SetSignalHandler && sys::RemoveFileOnSignal(ResultPath)) { // Make sure we delete the file when RemoveFileOnSignal fails. consumeError(Ret.discard()); std::error_code EC(errc::operation_not_permitted); return errorCodeToError(EC); } -#endif return std::move(Ret); } } // namespace fs |