From e40b2aea7427bb8e40636af150ca3ccba6c72cd7 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sat, 5 Feb 2000 06:02:23 +0000 Subject: [PATCH] (copy_internal): Don't allow mv to move a directory onto a non-directory. Reported by Brian Kimball via Michael Stone. --- src/copy.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/copy.c b/src/copy.c index 12d5df8d27..ad52c186d6 100644 --- a/src/copy.c +++ b/src/copy.c @@ -507,11 +507,23 @@ copy_internal (const char *src_path, const char *dst_path, return (move_mode ? 1 : 0); } - /* In move_mode, DEST may not be an existing directory. */ - if (move_mode && S_ISDIR (dst_sb.st_mode)) + if (move_mode) { - error (0, 0, _("%s: cannot overwrite directory"), dst_path); - return 1; + /* In move_mode, DEST may not be an existing directory. */ + if (S_ISDIR (dst_sb.st_mode)) + { + error (0, 0, _("%s: cannot overwrite directory"), dst_path); + return 1; + } + + /* Don't allow user to move a directory onto a non-directory. */ + if (S_ISDIR (src_sb.st_mode) && !S_ISDIR (dst_sb.st_mode)) + { + error (0, 0, + _("cannot move directory onto non-directory: %s -> %s"), + src_path, dst_path); + return 1; + } } if (x->backup_type != none && !S_ISDIR (dst_sb.st_mode)) -- 2.47.3