From: Pádraig Brady Date: Thu, 18 May 2017 01:05:27 +0000 (+0100) Subject: mv: distinguish copy and rename operations with --verbose X-Git-Tag: v8.28~75 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=62c6f1fc7836ad654cbf701ae2a845ce93a561ba;p=thirdparty%2Fcoreutils.git 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 --- diff --git a/NEWS b/NEWS index 559bcb3778..7c4429ddc4 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 7bfbcfcd08..e96ecdd546 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 de5d153a9c..497384e717 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 b81347f98c..2af27e8a0a 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 6fcbee8ad9..63487aa22f 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 < exp