From: Jim Meyering Date: Fri, 16 Feb 1996 05:08:04 +0000 (+0000) Subject: (copy): Detect (and fail) when creating backup file would destroy source. X-Git-Tag: FILEUTILS-3_12j~86 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=816194943b6b42ddd3b0adb27b7d7e886683f858;p=thirdparty%2Fcoreutils.git (copy): Detect (and fail) when creating backup file would destroy source. Reported by Martin C. Martin . --- diff --git a/src/cp.c b/src/cp.c index 84385b6416..af322438d2 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);