[PATCH] D57960: [Support] Fix TempFile::discard to not leave behind temporary files

Andrew Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 12 04:02:24 PST 2019


andrewng updated this revision to Diff 186437.
andrewng added a comment.

Updated the patch based on review suggestion.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57960/new/

https://reviews.llvm.org/D57960

Files:
  lib/Support/Path.cpp


Index: lib/Support/Path.cpp
===================================================================
--- lib/Support/Path.cpp
+++ lib/Support/Path.cpp
@@ -1128,26 +1128,27 @@
 
 Error TempFile::discard() {
   Done = true;
-  std::error_code RemoveEC;
-// On windows closing will remove the file.
-#ifndef _WIN32
-  // Always try to close and remove.
-  if (!TmpName.empty()) {
-    RemoveEC = fs::remove(TmpName);
-    sys::DontRemoveFileOnSignal(TmpName);
-  }
-#endif
-
-  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;
 
+#ifdef _WIN32
+  // On windows closing will remove the file.
+  TmpName = "";
+  return Error::success();
+#else
+  // Always try to close and remove.
+  std::error_code RemoveEC;
+  if (!TmpName.empty()) {
+    RemoveEC = fs::remove(TmpName);
+    sys::DontRemoveFileOnSignal(TmpName);
+    if (!RemoveEC)
+      TmpName = "";
+  }
   return errorCodeToError(RemoveEC);
+#endif
 }
 
 Error TempFile::keep(const Twine &Name) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57960.186437.patch
Type: text/x-patch
Size: 1100 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190212/7e0b6c59/attachment.bin>


More information about the llvm-commits mailing list