From 8ddd60a387c96da371f32c157974dd164e061a52 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sat, 9 Mar 1996 04:59:22 +0000 Subject: [PATCH] (copy): Comment change to avoid overwriting source with backup. --- src/cp.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/cp.c b/src/cp.c index af322438d2..3b0886e766 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, -- 2.47.2