diff options
author | Karel Zak | 2018-04-09 11:46:22 +0200 |
---|---|---|
committer | Karel Zak | 2018-04-09 11:46:22 +0200 |
commit | e4c58e00a0e594994d13fde0a2b8d6a0df2437bb (patch) | |
tree | 5b26721a2e580011e9c998d3cc907c9b064bdf8f | |
parent | tests: update sfdisk JSON output (diff) | |
parent | rename: prevent --no-act from setting --no-overwrite (diff) | |
download | kernel-qcow2-util-linux-e4c58e00a0e594994d13fde0a2b8d6a0df2437bb.tar.gz kernel-qcow2-util-linux-e4c58e00a0e594994d13fde0a2b8d6a0df2437bb.tar.xz kernel-qcow2-util-linux-e4c58e00a0e594994d13fde0a2b8d6a0df2437bb.zip |
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
-rw-r--r-- | misc-utils/rename.1 | 8 | ||||
-rw-r--r-- | misc-utils/rename.c | 15 |
2 files changed, 14 insertions, 9 deletions
diff --git a/misc-utils/rename.1 b/misc-utils/rename.1 index aa0b01251..df329461b 100644 --- a/misc-utils/rename.1 +++ b/misc-utils/rename.1 @@ -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. diff --git a/misc-utils/rename.c b/misc-utils/rename.c index cbda638e1..147e54fe9 100644 --- a/misc-utils/rename.c +++ b/misc-utils/rename.c @@ -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; |