summaryrefslogtreecommitdiff
path: root/binutils/rename.c
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2003-11-27 08:24:01 +0000
committerNick Clifton <nickc@redhat.com>2003-11-27 08:24:01 +0000
commitf5ca92c3e994b47e6a18a9fb4fda103526d9f152 (patch)
treea28fb8084e0acb98f4b812b9692cbf5c58dacb27 /binutils/rename.c
parent869f1a6698e1bea70a04783037aa882668608911 (diff)
downloadbinutils-redhat-f5ca92c3e994b47e6a18a9fb4fda103526d9f152.tar.gz
Ensure that we have write permission before overwriting a file.
Diffstat (limited to 'binutils/rename.c')
-rw-r--r--binutils/rename.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/binutils/rename.c b/binutils/rename.c
index 99561c47bc..398152e05f 100644
--- a/binutils/rename.c
+++ b/binutils/rename.c
@@ -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);