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.
.TP
.BR \-n , " \-\-no\-act"
Do not make any changes.
Do not make any changes; add
.BR \-\-verbose
to see what would be made.
.TP
.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
.BR \-V , " \-\-version"
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))
ret = 0;
if (ret == 1 && nooverwrite && lstat(newname, &sb) == 0) {
if (ret == 1 && nooverwrite && lstat(target, &sb) == 0) {
if (verbose)
printf(_("Skipping existing link: `%s'\n"), newname);
printf(_("Skipping existing link: `%s' -> `%s'\n"), s, target);
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))
return 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;
}
else if (!noact && rename(s, newname) != 0) {
@ -173,13 +174,13 @@ int main(int argc, char **argv)
switch (c) {
case 'n':
noact = 1;
/* fallthrough */
case 'o':
nooverwrite = 1;
break;
break;
case 'v':
verbose = 1;
break;
case 'o':
nooverwrite = 1;
break;
case 's':
do_rename = do_symlink;
break;