summaryrefslogtreecommitdiff
path: root/src/cp.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1996-02-16 05:08:04 +0000
committerJim Meyering <jim@meyering.net>1996-02-16 05:08:04 +0000
commit816194943b6b42ddd3b0adb27b7d7e886683f858 (patch)
tree2ea877bca607166d354c5f96ee310fc7e942c4c2 /src/cp.c
parent2eabfeeea898d36922842e16449ba11c003e39bd (diff)
downloadcoreutils-816194943b6b42ddd3b0adb27b7d7e886683f858.tar.xz
(copy): Detect (and fail) when creating backup file would destroy source.
Reported by Martin C. Martin <mcm@cs.cmu.edu>.
Diffstat (limited to 'src/cp.c')
-rw-r--r--src/cp.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/cp.c b/src/cp.c
index 84385b641..af322438d 100644
--- a/src/cp.c
+++ b/src/cp.c
@@ -620,6 +620,14 @@ copy (char *src_path, char *dst_path, int new_dst, dev_t device,
char *tmp_backup = find_backup_file_name (dst_path);
if (tmp_backup == NULL)
error (1, 0, _("virtual memory exhausted"));
+ if (strcmp (tmp_backup, src_path) == 0)
+ {
+ error (0, 0,
+ _("backing up `%s' would destroy source; `%s' not copied"),
+ dst_path, src_path);
+ return 1;
+
+ }
dst_backup = (char *) alloca (strlen (tmp_backup) + 1);
strcpy (dst_backup, tmp_backup);
free (tmp_backup);