diff options
author | Siddhesh Poyarekar <siddhesh@gotplt.org> | 2021-02-19 08:05:33 +0530 |
---|---|---|
committer | Siddhesh Poyarekar <siddhesh@gotplt.org> | 2021-02-19 08:05:33 +0530 |
commit | 3685de750e6a091663a0abe42528cad29e960e35 (patch) | |
tree | 2c71a3c3f24af21550fde8cef7431a3f9d248659 /binutils/arsup.c | |
parent | 668c18f17fc4ea91675a2b638c31bfbefa29665f (diff) | |
download | gdb-3685de750e6a091663a0abe42528cad29e960e35.zip gdb-3685de750e6a091663a0abe42528cad29e960e35.tar.gz gdb-3685de750e6a091663a0abe42528cad29e960e35.tar.bz2 |
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): Remove TARGET_STAT. Adjust call to
SMART_RENAME.
* arsup.c (ar_save): Likewise.
* objcopy (strip_main): Don't copy TMPFD. 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): Remove FD, PRESERVE_DATES arguments. Use
rename system call only if TO does not exist.
* bucomm.h (smart_rename): Adjust declaration.
Diffstat (limited to 'binutils/arsup.c')
-rw-r--r-- | binutils/arsup.c | 13 |
1 files changed, 1 insertions, 12 deletions
diff --git a/binutils/arsup.c b/binutils/arsup.c index fa7706f..f7ce8f0 100644 --- a/binutils/arsup.c +++ b/binutils/arsup.c @@ -343,18 +343,11 @@ ar_save (void) } else { - bfd_boolean skip_stat = FALSE; struct stat target_stat; - int ofd = real_ofd; if (deterministic > 0) obfd->flags |= BFD_DETERMINISTIC_OUTPUT; -#if !defined (_WIN32) || defined (__CYGWIN32__) - /* It's OK to fail; at worst it will result in SMART_RENAME using a slow - copy fallback to write the output. */ - ofd = dup (ofd); -#endif bfd_close (obfd); if (stat (real_name, &target_stat) != 0) @@ -363,9 +356,6 @@ ar_save (void) Create the real empty output file here so smart_rename will update the mode according to the process umask. */ obfd = bfd_openw (real_name, NULL); - if (obfd == NULL - || bfd_stat (obfd, &target_stat) != 0) - skip_stat = TRUE; if (obfd != NULL) { bfd_set_format (obfd, bfd_archive); @@ -373,8 +363,7 @@ ar_save (void) } } - smart_rename (temp_name, real_name, ofd, - skip_stat ? NULL : &target_stat, 0); + smart_rename (temp_name, real_name, NULL); obfd = 0; free (temp_name); free (real_name); |