[PATCH] D39778: Remove a given file even if openFileForRead fails.

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 7 18:45:40 PST 2017


ruiu created this revision.
Herald added subscribers: arichardson, emaste.

I think the constract of this function is to remove a file in some way,
whether in background or in foreground. This patch makes sure that it
removes a given file.


https://reviews.llvm.org/D39778

Files:
  lld/ELF/Filesystem.cpp


Index: lld/ELF/Filesystem.cpp
===================================================================
--- lld/ELF/Filesystem.cpp
+++ lld/ELF/Filesystem.cpp
@@ -56,13 +56,12 @@
   // Instead we open the file and unlink it on this thread. The unlink is fast
   // since the open fd guarantees that it is not removing the last reference.
   int FD;
-  if (sys::fs::openFileForRead(Path, FD))
-    return;
-
+  std::error_code EC = sys::fs::openFileForRead(Path, FD);
   sys::fs::remove(Path);
 
   // close and therefore remove TempPath in background.
-  std::thread([=] { ::close(FD); }).detach();
+  if (!EC)
+    std::thread([=] { ::close(FD); }).detach();
 #endif
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39778.122025.patch
Type: text/x-patch
Size: 666 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171108/e4b72abd/attachment.bin>


More information about the llvm-commits mailing list