diff options
author | Jim Meyering <jim@meyering.net> | 1996-02-16 05:08:04 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1996-02-16 05:08:04 +0000 |
commit | 816194943b6b42ddd3b0adb27b7d7e886683f858 (patch) | |
tree | 2ea877bca607166d354c5f96ee310fc7e942c4c2 /src | |
parent | 2eabfeeea898d36922842e16449ba11c003e39bd (diff) | |
download | coreutils-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')
-rw-r--r-- | src/cp.c | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -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); |