Ensure that we have write permission before overwriting a file.
authorNick Clifton <nickc@redhat.com>
Thu, 27 Nov 2003 08:24:01 +0000 (08:24 +0000)
committerNick Clifton <nickc@redhat.com>
Thu, 27 Nov 2003 08:24:01 +0000 (08:24 +0000)
binutils/ChangeLog
binutils/rename.c

index e7d53091dcebf0c3f97f1cd686488e04890aa83a..208f96e6c1be0ed0ae19b66b52d142cd4d5b5baa 100644 (file)
@@ -1,3 +1,8 @@
+2003-11-27  Nick Clifton  <nickc@redhat.com>
+
+       * rename.c (smart_rename): Make sure that we have write
+       permission on the destination file before renaming.
+
 2003-11-26  Daniel Jacobowitz <drow@mvista.com>
             Nick Clifton  <nickc@redhat.com>
 
index 99561c47bcfc5369e78dc9fde1ef24f536e75fd1..398152e05f10e79cd037d60eec5360f6897e5079 100644 (file)
@@ -159,14 +159,18 @@ smart_rename (const char *from, const char *to, int preserve_dates)
   if (ret != 0)
     {
       /* We have to clean up here.  */
-
-      non_fatal (_("%s: rename: %s"), to, strerror (errno));
+      non_fatal (_("unable to rename '%s' reason: %s"), to, strerror (errno));
       unlink (from);
     }
 #else
   /* Use rename only if TO is not a symbolic link and has
-     only one hard link.  */
-  if (! exists || (!S_ISLNK (s.st_mode) && s.st_nlink == 1))
+     only one hard link, and we have permission to write to it.  */
+  if (! exists
+      || (!S_ISLNK (s.st_mode)
+         && S_ISREG (s.st_mode)
+         && (s.st_mode & S_IWUSR)
+         && s.st_nlink == 1)
+      )
     {
       ret = rename (from, to);
       if (ret == 0)
@@ -193,7 +197,7 @@ smart_rename (const char *from, const char *to, int preserve_dates)
       else
        {
          /* We have to clean up here.  */
-         non_fatal (_("%s: rename: %s"), to, strerror (errno));
+         non_fatal (_("unable to rename '%s' reason: %s"), to, strerror (errno));
          unlink (from);
        }
     }
@@ -201,7 +205,7 @@ smart_rename (const char *from, const char *to, int preserve_dates)
     {
       ret = simple_copy (from, to);
       if (ret != 0)
-       non_fatal (_("%s: simple_copy: %s"), to, strerror (errno));
+       non_fatal (_("unable to copy file '%s' reason: %s"), to, strerror (errno));
 
       if (preserve_dates)
        set_times (to, &s);
This page took 0.027516 seconds and 4 git commands to generate.