]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
binutils: Avoid renaming over existing files
authorSiddhesh Poyarekar <siddhesh@gotplt.org>
Mon, 22 Feb 2021 15:15:50 +0000 (20:45 +0530)
committerSiddhesh Poyarekar <siddhesh@gotplt.org>
Mon, 22 Feb 2021 15:15:50 +0000 (20:45 +0530)
commit8e03235147a9e774d3ba084e93c2da1aa94d1cec
tree54742d8e3f6571de08f01dc0c879fe4c4eb2137a
parentab285707710268d8c0052040b441fddc3d491e05
binutils: Avoid renaming over existing files

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.

binutils/

* ar.c (write_archive): Adjust call to SMART_RENAME.
* arsup.c (ar_save): Likewise.
* objcopy (strip_main): Don't set times on temporary file and
adjust call to SMART_RENAME.
(copy_main): Likewise.
* rename.c [!S_ISLNK]: Remove definitions.
(try_preserve_permissions): Remove function.
(smart_rename): Replace PRESERVE_DATES argument with
TARGET_STAT.  Use rename system call only if TO does not exist.
* bucomm.h (smart_rename): Adjust declaration.

(cherry picked from commit 3685de750e6a091663a0abe42528cad29e960e35)
binutils/ChangeLog
binutils/ar.c
binutils/arsup.c
binutils/bucomm.h
binutils/objcopy.c
binutils/rename.c