[PATCH] D39778: Remove a given file even if openFileForRead fails.
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 7 20:18:42 PST 2017
LGTM
Rui Ueyama via Phabricator <reviews at reviews.llvm.org> writes:
> 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
> }
>
>
>
> 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
> }
>
More information about the llvm-commits
mailing list