]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(copy_internal): Don't allow mv to move a directory onto
authorJim Meyering <jim@meyering.net>
Sat, 5 Feb 2000 06:02:23 +0000 (06:02 +0000)
committerJim Meyering <jim@meyering.net>
Sat, 5 Feb 2000 06:02:23 +0000 (06:02 +0000)
a non-directory.  Reported by Brian Kimball via Michael Stone.

src/copy.c

index 12d5df8d273dfd52a224e92272fa13835e775cce..ad52c186d6eedb89bf8f11faa9942e010ba808d6 100644 (file)
@@ -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))