diff options
author | Jim Meyering <jim@meyering.net> | 2000-02-05 06:02:23 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2000-02-05 06:02:23 +0000 |
commit | e40b2aea7427bb8e40636af150ca3ccba6c72cd7 (patch) | |
tree | d5bd242a9bae98edf2624be6ba04a1051d4b514e | |
parent | 980db8d94bc1becb14fa42a7aa8f695d1b161333 (diff) | |
download | coreutils-e40b2aea7427bb8e40636af150ca3ccba6c72cd7.tar.xz |
(copy_internal): Don't allow mv to move a directory onto
a non-directory. Reported by Brian Kimball via Michael Stone.
-rw-r--r-- | src/copy.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/copy.c b/src/copy.c index 12d5df8d2..ad52c186d 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)) |