summaryrefslogtreecommitdiff
path: root/binutils/ar.c
diff options
context:
space:
mode:
authorSiddhesh Poyarekar <siddhesh@gotplt.org>2021-02-19 08:05:33 +0530
committerSiddhesh Poyarekar <siddhesh@gotplt.org>2021-02-19 08:05:33 +0530
commit3685de750e6a091663a0abe42528cad29e960e35 (patch)
tree2c71a3c3f24af21550fde8cef7431a3f9d248659 /binutils/ar.c
parent668c18f17fc4ea91675a2b638c31bfbefa29665f (diff)
downloadbinutils-gdb-3685de750e6a091663a0abe42528cad29e960e35.tar.gz
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/ar.c')
-rw-r--r--binutils/ar.c9
1 files changed, 1 insertions, 8 deletions
diff --git a/binutils/ar.c b/binutils/ar.c
index 0ecfa337228..44df48c5c67 100644
--- a/binutils/ar.c
+++ b/binutils/ar.c
@@ -1253,7 +1253,6 @@ write_archive (bfd *iarch)
char *old_name, *new_name;
bfd *contents_head = iarch->archive_next;
int ofd = -1;
- struct stat target_stat;
old_name = xstrdup (bfd_get_filename (iarch));
new_name = make_tempname (old_name, &ofd);
@@ -1298,12 +1297,6 @@ write_archive (bfd *iarch)
if (!bfd_set_archive_head (obfd, contents_head))
bfd_fatal (old_name);
-#if !defined (_WIN32) || defined (__CYGWIN32__)
- ofd = dup (ofd);
-#endif
- if (ofd == -1 || bfd_stat (iarch, &target_stat) != 0)
- bfd_fatal (old_name);
-
if (!bfd_close (obfd))
bfd_fatal (old_name);
@@ -1313,7 +1306,7 @@ write_archive (bfd *iarch)
/* We don't care if this fails; we might be creating the archive. */
bfd_close (iarch);
- if (smart_rename (new_name, old_name, ofd, &target_stat, 0) != 0)
+ if (smart_rename (new_name, old_name, NULL) != 0)
xexit (1);
free (old_name);
free (new_name);