On 17/05/17 22:46, 積丹尼 Dan Jacobson wrote:
> PB> So this is working across file systems
> Yes.
>>> '/home/jidanni/jidanni.org/location/grow/programs' -> '/tmp/programs'
> This says to me "I, the mv command, have just moved  A to B.
> 
> PB> create dir /tmp/programs
> If that (create B) is what it is doing in that step, then it should not
> mention the unrelated A.
> 
>>> '/home/jidanni/jidanni.org/location/grow/programs/grow.tgz' -> 
>>> '/tmp/programs/grow.tgz'
> This says to me "I am moving A/C to B/C". But there is no more A... at
> least that is what the user thinks... so how could it still move it.
> 
> 
> PB> I suppose we could distinguish the creation operations, though
> PB> note if the first attempted rename() worked for the source dir,
> PB> then there would have been just a single operation output like:
> 
> PB>   '/home/jidanni/jidanni.org/location/grow/programs' -> '/tmp/programs'
> 
> Well all I know is if the user always can do something on one line, then he
> would expect a consistent number of -v output lines.

Well I'm not sure about having a consistent number of output lines,
but I do see that the output can be confusing.  The attached patch
distinguishes the different operations for mv, as follows:

$ mkdir /tmp/mv-test && touch /tmp/mv-test/file

$ src/mv -v /tmp/mv-test .
created directory './mv-test'
copied '/tmp/mv-test/file' -> './mv-test/file'
removed '/tmp/mv-test/file'
removed directory '/tmp/mv-test'

$ src/mv -v mv-test mv-test-2
renamed 'mv-test' -> 'mv-test-2'

$ src/mv -v mv-test-2/file mv-test-2/file2
renamed 'mv-test-2/file' -> 'mv-test-2/file2'

cheers,
Pádraig
From 62c6f1fc7836ad654cbf701ae2a845ce93a561ba Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]>
Date: Thu, 18 May 2017 02:05:27 +0100
Subject: [PATCH] mv: distinguish copy and rename operations with --verbose

* 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                     |  4 ++++
 src/copy.c               | 27 +++++++++++++++++++++------
 tests/mv/backup-dir.sh   |  2 +-
 tests/mv/mv-n.sh         |  2 +-
 tests/mv/mv-special-1.sh |  3 +++
 5 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/NEWS b/NEWS
index 559bcb3..7c4429d 100644
--- 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]
 
diff --git a/src/copy.c b/src/copy.c
index 7bfbcfc..e96ecdd 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -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
         {
diff --git a/tests/mv/backup-dir.sh b/tests/mv/backup-dir.sh
index de5d153..497384e 100755
--- a/tests/mv/backup-dir.sh
+++ b/tests/mv/backup-dir.sh
@@ -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
diff --git a/tests/mv/mv-n.sh b/tests/mv/mv-n.sh
index b81347f..2af27e8 100755
--- a/tests/mv/mv-n.sh
+++ b/tests/mv/mv-n.sh
@@ -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
diff --git a/tests/mv/mv-special-1.sh b/tests/mv/mv-special-1.sh
index 6fcbee8..63487aa 100755
--- a/tests/mv/mv-special-1.sh
+++ b/tests/mv/mv-special-1.sh
@@ -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
-- 
2.9.3

Reply via email to