summaryrefslogtreecommitdiff
path: root/src/cp.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1996-06-19 01:59:12 +0000
committerJim Meyering <jim@meyering.net>1996-06-19 01:59:12 +0000
commit6099222717e97badb90a01ca948a2482f9177038 (patch)
tree3b0317e35a07e98034312912f63f35a93424c8d1 /src/cp.c
parent608e78053617c4ea1151b655b6d394d442b36c28 (diff)
downloadcoreutils-6099222717e97badb90a01ca948a2482f9177038.tar.xz
(do_copy): When the force and backup options have been
specified and the source and destination are the same name for an existing, regular file, convert the user's command, e.g. `cp --force --backup foo foo' to `cp --force foo fooSUFFIX' where SUFFIX is determined by any version control options used. At urging of (most recently) Karl Berry.
Diffstat (limited to 'src/cp.c')
-rw-r--r--src/cp.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/cp.c b/src/cp.c
index a48f4e540..aa8548da6 100644
--- a/src/cp.c
+++ b/src/cp.c
@@ -502,11 +502,28 @@ do_copy (int argc, char **argv)
source = argv[optind];
+ /* When the force and backup options have been specified and
+ the source and destination are the same name for an existing
+ regular file, convert the user's command, e.g.
+ `cp --force --backup foo foo' to `cp --force foo fooSUFFIX'
+ where SUFFIX is determined by any version control options used. */
+
+ if (flag_force
+ && backup_type != none
+ && STREQ (source, dest)
+ && !new_dst && S_ISREG (sb.st_mode))
+ {
+ backup_type = none;
+ new_dest = find_backup_file_name (dest);
+ if (new_dest == NULL)
+ error (1, 0, _("virtual memory exhausted"));
+ }
+
/* When the destination is specified with a trailing slash and the
source exists but is not a directory, convert the user's command
`cp source dest/' to `cp source dest/basename(source)'. */
- if (dest[strlen (dest) - 1] == '/'
+ else if (dest[strlen (dest) - 1] == '/'
&& lstat (source, &source_stats) == 0
&& !S_ISDIR (source_stats.st_mode))
{