Merge branch 'rename-fix-noact-without-nooverwrite' of https://github.com/g-raud/util-linux

* 'rename-fix-noact-without-nooverwrite' of https://github.com/g-raud/util-linux:
  rename: prevent --no-act from setting --no-overwrite
  rename: when --no-overwrite skip verbosily only when --verbose
  rename: consolidate printing the symlink in addition to its target
  rename: fix/reverse the semantics of --no-overwrite in --symlink mode
This commit is contained in:
Karel Zak 2018-04-09 11:46:22 +02:00
commit e4c58e00a0
2 changed files with 14 additions and 9 deletions

View File

@ -23,10 +23,14 @@ Do not rename a symlink but its target.
Show which files were renamed, if any. Show which files were renamed, if any.
.TP .TP
.BR \-n , " \-\-no\-act" .BR \-n , " \-\-no\-act"
Do not make any changes. Do not make any changes; add
.BR \-\-verbose
to see what would be made.
.TP .TP
.BR \-o , " \-\-no\-overwrite" .BR \-o , " \-\-no\-overwrite"
Do not overwrite existing files. Do not overwrite existing files. When
.BR \-\-symlink
is active, do not overwrite symlinks pointing to existing targets.
.TP .TP
.BR \-V , " \-\-version" .BR \-V , " \-\-version"
Display version information and exit. Display version information and exit.

View File

@ -77,9 +77,9 @@ static int do_symlink(char *from, char *to, char *s, int verbose, int noact, int
if (string_replace(from, to, target, target, &newname)) if (string_replace(from, to, target, target, &newname))
ret = 0; ret = 0;
if (ret == 1 && nooverwrite && lstat(newname, &sb) == 0) { if (ret == 1 && nooverwrite && lstat(target, &sb) == 0) {
if (verbose) if (verbose)
printf(_("Skipping existing link: `%s'\n"), newname); printf(_("Skipping existing link: `%s' -> `%s'\n"), s, target);
ret = 0; ret = 0;
} }
@ -113,7 +113,8 @@ static int do_file(char *from, char *to, char *s, int verbose, int noact, int no
if (string_replace(from, to, file, s, &newname)) if (string_replace(from, to, file, s, &newname))
return 0; return 0;
if (nooverwrite && access(newname, F_OK) == 0) { if (nooverwrite && access(newname, F_OK) == 0) {
printf(_("Skipping existing file: `%s'\n"), newname); if (verbose)
printf(_("Skipping existing file: `%s'\n"), newname);
ret = 0; ret = 0;
} }
else if (!noact && rename(s, newname) != 0) { else if (!noact && rename(s, newname) != 0) {
@ -173,13 +174,13 @@ int main(int argc, char **argv)
switch (c) { switch (c) {
case 'n': case 'n':
noact = 1; noact = 1;
/* fallthrough */ break;
case 'o':
nooverwrite = 1;
break;
case 'v': case 'v':
verbose = 1; verbose = 1;
break; break;
case 'o':
nooverwrite = 1;
break;
case 's': case 's':
do_rename = do_symlink; do_rename = do_symlink;
break; break;