[PATCH] binutils: Avoid renaming over existing files
Fangrui Song
i@maskray.me
Tue Feb 9 03:33:14 GMT 2021
On 2021-02-09, Siddhesh Poyarekar wrote:
>Renaming over existing files needs additional care to restore
>permissions and ownership, which may not always succeed.
>Additionally, other properties of the file such as extended attributes
>may be lost, making the operation flaky.
>
>For predictable results, resort to rename() only if the file does not
>exist, otherwise copy the file contents into the existing file. This
>ensures that no additional tricks are needed to retain file
>properties.
>
>This also allows dropping of the redundant set_times on the tmpfile in
>objcopy/strip since now we no longer rename over existing files.
Thanks for the patch! I am doing similar thing in llvm-objcopy as some
users want to preserve owner/group for an in-place operation like `strip exe`.
I observe that `strip a -o b` when b is present keeps the traditional
behavior (b's owner/group is the effective user/group. That is nice,
truncate+overwrite should probably only apply for in-place operations),
but they probably should be clarified.
More information about the Binutils
mailing list