Skip to content

Commit

Permalink
Remove a given file even if openFileForRead fails.
Browse files Browse the repository at this point in the history
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.

Differential Revision: https://reviews.llvm.org/D39778

llvm-svn: 317663
  • Loading branch information
rui314 committed Nov 8, 2017
1 parent 65e6d0b commit 1e8813c
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lld/ELF/Filesystem.cpp
Expand Up @@ -56,13 +56,12 @@ void elf::unlinkAsync(StringRef Path) {
// 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
}

Expand Down

0 comments on commit 1e8813c

Please sign in to comment.