(do_move): Add &copy_into_self arg in call to copy.
authorJim Meyering <jim@meyering.net>
Fri, 13 Mar 1998 23:38:50 +0000 (23:38 +0000)
committerJim Meyering <jim@meyering.net>
Fri, 13 Mar 1998 23:38:50 +0000 (23:38 +0000)
Don't remove source directory when copy_into_self is nonzero.
Reported by Arne Henrik Juul.

src/mv.c

index 9b869b7..e9d94a9 100644 (file)
--- a/src/mv.c
+++ b/src/mv.c
@@ -272,6 +272,7 @@ do_move (const char *source, const char *dest, const struct cp_options *x)
         and set errno to EXDEV.  */
 
       static int first = 1;
+      int copy_into_self;
 
       if (first)
        {
@@ -281,13 +282,18 @@ do_move (const char *source, const char *dest, const struct cp_options *x)
          hash_init (INITIAL_HASH_MODULE, INITIAL_ENTRY_TAB_SIZE);
        }
 
-      fail = copy (source, dest, nonexistent_dst, x);
+      fail = copy (source, dest, nonexistent_dst, x, &copy_into_self);
       if (fail)
        {
          /* Restore original destination file DEST if made a backup.  */
          if (dest_backup && rename (dest_backup, dest))
            error (0, errno, _("cannot un-backup `%s'"), dest);
        }
+      else if (copy_into_self)
+       {
+         /* Do *not* remove SOURCE if it is the same as or a parent of DEST.
+            Otherwise, mv would be removing the original *and* the copy.  */
+       }
       else
        {
          struct rm_options rm_options;