]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
mv: distinguish copy and rename operations with --verbose
authorPádraig Brady <P@draigBrady.com>
Thu, 18 May 2017 01:05:27 +0000 (02:05 +0100)
committerPádraig Brady <P@draigBrady.com>
Thu, 18 May 2017 01:08:42 +0000 (02:08 +0100)
* src/copy.c (copy_internal): In x->move_mode distinguish
whether we're copying, creating directory, or renaming.
* tests/mv/backup-dir.sh: Adjust to new output.
* tests/mv/mv-n.sh: Likewise.
* tests/mv/mv-special-1.sh: Likewise.
* NEWS: Mention the improvement.
Fixes http://bugs.gnu.org/26971

NEWS
src/copy.c
tests/mv/backup-dir.sh
tests/mv/mv-n.sh
tests/mv/mv-special-1.sh

diff --git a/NEWS b/NEWS
index 559bcb377852e529bb1687b048842eb5e945451c..7c4429ddc473f913c015bfd166ae91f2f5d2549e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -39,6 +39,10 @@ GNU coreutils NEWS                                    -*- outline -*-
   split supports a new --hex-suffixes[=from] option to create files with
   lower case hexadecimal suffixes, similar to the --numeric-suffixes option.
 
+** Improvements
+
+  mv --verbose now distinguishes rename and copy operations.
+
 
 * Noteworthy changes in release 8.27 (2017-03-08) [stable]
 
index 7bfbcfcd088df2851b135494598864f455abf7c7..e96ecdd5465083bf3aba1f070eebcc7928f554eb 100644 (file)
@@ -2192,8 +2192,9 @@ copy_internal (char const *src_name, char const *dst_name,
 
   /* If the source is a directory, we don't always create the destination
      directory.  So --verbose should not announce anything until we're
-     sure we'll create a directory. */
-  if (x->verbose && !S_ISDIR (src_mode))
+     sure we'll create a directory.  Also don't announce yet when moving
+     so we can distinguish renames versus copies.  */
+  if (x->verbose && !x->move_mode && !S_ISDIR (src_mode))
     emit_verbose (src_name, dst_name, backup_succeeded ? dst_backup : NULL);
 
   /* Associate the destination file name with the source device and inode
@@ -2314,9 +2315,12 @@ copy_internal (char const *src_name, char const *dst_name,
     {
       if (rename (src_name, dst_name) == 0)
         {
-          if (x->verbose && S_ISDIR (src_mode))
-            emit_verbose (src_name, dst_name,
-                          backup_succeeded ? dst_backup : NULL);
+          if (x->verbose)
+            {
+              printf (_("renamed "));
+              emit_verbose (src_name, dst_name,
+                            backup_succeeded ? dst_backup : NULL);
+            }
 
           if (x->set_security_context)
             {
@@ -2417,6 +2421,12 @@ copy_internal (char const *src_name, char const *dst_name,
           return false;
         }
 
+      if (x->verbose && !S_ISDIR (src_mode))
+        {
+          printf (_("copied "));
+          emit_verbose (src_name, dst_name,
+                        backup_succeeded ? dst_backup : NULL);
+        }
       new_dst = true;
     }
 
@@ -2511,7 +2521,12 @@ copy_internal (char const *src_name, char const *dst_name,
             }
 
           if (x->verbose)
-            emit_verbose (src_name, dst_name, NULL);
+            {
+              if (x->move_mode)
+                printf (_("created directory %s\n"), quoteaf (dst_name));
+              else
+                emit_verbose (src_name, dst_name, NULL);
+            }
         }
       else
         {
index de5d153a9cc189300b1c14cbb11296e6cce31148..497384e717e79fbf392db475a3a398aef5c7c90c 100755 (executable)
@@ -26,7 +26,7 @@ touch X Y || framework_failure_
 # Before coreutils-6.2, the " (backup: 'B.~1~')" suffix was not printed.
 mv --verbose --backup=numbered -T A B > out || fail=1
 cat <<\EOF > exp || fail=1
-'A' -> 'B' (backup: 'B.~1~')
+renamed 'A' -> 'B' (backup: 'B.~1~')
 EOF
 
 compare exp out || fail=1
index b81347f98cdfd1feb97d4ba6137e870577159245..2af27e8a0af291cfe9943bef5e684fd128741500 100755 (executable)
@@ -22,7 +22,7 @@ print_ver_ mv
 
 # test miscellaneous combinations of -f -i -n parameters
 touch a b || framework_failure_
-echo "'a' -> 'b'" > out_move
+echo "renamed 'a' -> 'b'" > out_move
 > out_empty
 
 # ask for overwrite, answer no
index 6fcbee8ad9529158bbc888f38ee8530fd580b1bd..63487aa22f84bd8a07a106e1e50588e8392026ef 100755 (executable)
@@ -48,7 +48,10 @@ test -d "$other_partition_tmpdir/$dir/a/b/c" || fail=1
 # so ignore chatter about when files are removed and copied rather than renamed.
 sed "
   /^removed /d
+  s,renamed ,,
+  s,copied ,,
   s,$other_partition_tmpdir,XXX,
+  s,created directory 'XXX/\(.*\)','\1' -> 'XXX/\1',
 " out | sort > out2
 
 cat <<EOF | sort > exp