summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1996-03-09 04:59:22 +0000
committerJim Meyering <jim@meyering.net>1996-03-09 04:59:22 +0000
commit8ddd60a387c96da371f32c157974dd164e061a52 (patch)
tree9af2d2a9e467d0140eb2e7d17339ae9adc06a3b7 /src
parenteaf359df0c2674158628fb0932560d2b10feb195 (diff)
downloadcoreutils-8ddd60a387c96da371f32c157974dd164e061a52.tar.xz
(copy): Comment change to avoid overwriting source with backup.
Diffstat (limited to 'src')
-rw-r--r--src/cp.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/cp.c b/src/cp.c
index af322438d..3b0886e76 100644
--- a/src/cp.c
+++ b/src/cp.c
@@ -620,6 +620,11 @@ 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"));
+
+ /* Detect (and fail) when creating the backup file would
+ destroy the source file. Before, running the commands
+ cd /tmp; rm -f a a~; : > a; echo A > a~; cp -b -V simple a~ a
+ would leave two zero-length files: a and a~. */
if (strcmp (tmp_backup, src_path) == 0)
{
error (0, 0,