]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
rename: notice when expression and replacement are the same string
authorSami Kerola <kerolasa@iki.fi>
Sat, 20 May 2017 09:41:23 +0000 (10:41 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 14 Jun 2017 10:17:27 +0000 (12:17 +0200)
The rename(1) can exit early when replace expression and replacement are
identical string.  It is also appropriate to change return value in this
case to 'nothing was renamed'.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
misc-utils/rename.c

index b06a2d969b3f5d00910ba1900dff17d7ff27a5d0..8230ac3da02a11d40671dc4ed6d49bc99ac805f7 100644 (file)
@@ -204,6 +204,9 @@ int main(int argc, char **argv)
        from = argv[0];
        to = argv[1];
 
+       if (!strcmp(from, to))
+               return RENAME_EXIT_NOTHING;
+
        for (i = 2; i < argc; i++)
                ret |= do_rename(from, to, argv[i], verbose, noact, nooverwrite);