[PATCH] D56806: [llvm-objcopy] Fix crash when writing empty binary output
Jake Ehrlich via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 24 18:22:01 PST 2019
jakehehrlich added inline comments.
================
Comment at: llvm/tools/llvm-objcopy/Buffer.cpp:25-26
+ // disk.
+ if (sys::fs::exists(FileName))
+ if (std::error_code EC = sys::fs::remove(FileName))
+ return createFileError(FileName, errorCodeToError(EC));
----------------
Remove has a default parameter that sets weather or not it errors out if the file already exists. This removes a (well for this it doesn't actually matter in any case I've seen) race condition. To eliminate the condition entirely you need to create a temporary empty file on the same partition and then rename it into place. That behaves atomically. That's what FileBuffer is doing under the hood.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D56806/new/
https://reviews.llvm.org/D56806
More information about the llvm-commits
mailing list