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
This commit is contained in:
Pádraig Brady 2017-05-18 02:05:27 +01:00
parent 82911c51ae
commit 62c6f1fc78
5 changed files with 30 additions and 8 deletions

4
NEWS
View File

@ -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]

View 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
{

View File

@ -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

View File

@ -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

View File

@ -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