summaryrefslogtreecommitdiffstats
path: root/misc-utils/rename.c
Commit message (Collapse)AuthorAgeFilesLines
* misc: consolidate version printing and close_stdout()Karel Zak2019-04-161-3/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* rename: avoid undefined function prototype for `fpurge`Patrick Steinhardt2018-10-041-1/+3
| | | | | | | | | | | | | | | | | | | | | In case where the non-standard `fpurge` function is available, we redefine `__fpurge` to `fpurge`. We can do so because the only difference between both functions is that one returns an error code while the other does not. But as we do not check the error code either way, we do not care about which one of them we use. The above redefinition happens unconditionally if we know that `fpurge` exists. Most notably, we also redefine it if we already do have an `__fpurge` function available that could be used. This causes problems on musl-based platforms, where we detect availability of `fpurge` in libc, but where no function declaration for it exists in "stdio_ext.h". The compiler thus prints a warning due to an unknown function, even though it will link just fine. Avoid this warning by only redefining `__fpurge` to `fpurge` when HAVE___FPURGE is not defined. Signed-off-by: Patrick Steinhardt <ps@pks.im>
* rename: fixup & style (no functional changes)G.raud Meyer2018-04-091-6/+5Star
|
* rename: test availability of __fpurge() and fpurge()G.raud Meyer2018-04-091-1/+9
|
* rename: ask(): call __fpurge() to cater for multi-byte charactersG.raud Meyer2018-04-091-1/+9
| | | | | | | | Making a purge in cbreak mode also makes the code compatible with canonical mode. This can be useful in the case a shell, like bash, does not restore the tty state of stopped jobs before restarting them. An alternative fix to this minor shortcoming would be to retest the tty state each time inside ask().
* rename: ask(): print n when EOF on inputG.raud Meyer2018-04-091-3/+4
|
* rename: detect tty in cbreak mode to make ask() read a single byteG.raud Meyer2018-04-091-1/+15
| | | | | | | Set tty_cbreak only when tty has a VMIN of 1 to avoid having to purge at all in cbreak mode. The prompt is still compatible with a non interactive input from a pipe.
* rename: add option --interactive to ask before overwritingG.raud Meyer2018-04-091-9/+49
| | | | | | | The option name -i/--interactive is picked from mv(1) and cp(1) from GNU and BSD. Also update the manpage.
* rename: skip faccessat() failure if AT_SYMLINK_NOFOLLOW is not a valid flagG.raud Meyer2018-04-091-1/+5
| | | | | AT_SYMLINK_NOFOLLOW is not required by POSIX and it is not a valid flag on Mac OSX.
* rename: check source file access earlyG.raud Meyer2018-04-091-0/+12
| | | | | | | | | | This change makes rename detect inexisting files given on the command line and consider them faliures. This is particularly useful with --no-act (to detect extraneous arguments). It also prevents skipping non existing files (when the modified name happens to exist). This makes --verbose not print skipping messages of false positives (the access error is printed instead).
* rename: prevent --no-act from setting --no-overwriteG.raud Meyer2018-03-291-4/+4
| | | | | | | | | | | This fixes a bug introduced by commit fabb90676 ("Added --no-override option to rename.", 2017-05-27) where the fallthrough meant to let --no-act set --verbose was changed to set --no-override (the previous code was too smart). Do not let --no-act set --verbose anymore but update the manual to recommend adding option --verbose. This is to be able to make --no-act detect only non existing file arguments (in a future commit).
* rename: when --no-overwrite skip verbosily only when --verboseG.raud Meyer2018-03-271-1/+2
|
* rename: consolidate printing the symlink in addition to its targetG.raud Meyer2018-03-271-1/+1
|
* rename: fix/reverse the semantics of --no-overwrite in --symlink modeG.raud Meyer2018-03-271-2/+2
| | | | | | | | | | The previous behaviour was to overwrite a symlink only when the new destination did not exist, i.e. to avoid creating a symlink to an existing file! It had not been documented and it seems counter-intuitive to me. So the new behavior protects symlinks pointing to existing targets from being changed. Also update manpage to document this mode.
* rename: use access(3) to check if a file existsSami Kerola2017-12-041-2/+1Star
| | | | | | | This is more lightweight than calling stat(3). In same go add a regression test to ensure changes like this will not break --no-overwrite option. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* misc: consolidate macro style USAGE_HELP_OPTIONSRuediger Meier2017-06-291-2/+2
| | | | | | | | | changed in include/c.h and applied via sed: sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c") sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c") Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: introduce print_usage_help_options()Ruediger Meier2017-06-271-2/+1Star
| | | | | | | | | | | | Consolidate --help and --version descriptions. We are now able to align them to the other options. We changed include/c.h. The rest of this patch was generated by sed, plus manually setting the right alignment numbers. We do not change anything but white spaces in the --help output. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: never use usage(stderr)Ruediger Meier2017-06-261-4/+5
| | | | | | | Here we fix all cases where we have usage(FILE*) functions. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* rename: notice when expression and replacement are the same stringSami Kerola2017-06-141-0/+3
| | | | | | | | 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: fix ggc-7 fallthrough warningsSami Kerola2017-06-141-1/+0Star
| | | | | | | | | | | | | | | | | | | (Original patch and commit message edited by Rudi.) gcc-7 adds -Wimplicit-fallthrough=3 to our default flag -Wextra. This warning can be silenced by using comment /* fallthrough */ which is also recognized by other tools like coverity. There are also other valid comments (see man gcc-7) but we consolidate this style now. We could have also used __attribute__((fallthrough)) but the comment looks nice and does not need to be ifdef'ed for compatibility. Reference: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=7652 Reference: https://developers.redhat.com/blog/2017/03/10/wimplicit-fallthrough-in-gcc-7/ Reviewed-by: Ruediger Meier <ruediger.meier@ga-group.nl> Suggested-by: Karel Zak <kzak@redhat.com> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* Changed "override" to "overwrite" rename option.Dov Grobgeld2017-06-031-13/+13
|
* Added --no-override option to rename.Dov Grobgeld2017-05-271-16/+37
|
* rename: make --no-act to imply --verboseSami Kerola2017-05-191-3/+3
| | | | | | | | It is reasonable to assume use of --no-act means one wants to always see what would have happen if rename is done. To say same slightly differently, if there is sn use case for silent rename --no-act run I cannot think one. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* rename: add --no-act optionAlexander F Rødseth2017-02-151-11/+17
| | | | | | | [kzak@redhat.com: - rename --dry-run to --no-act] Signed-off-by: Alexander F Rødseth <xyproto@archlinux.org> Signed-off-by: Karel Zak <kzak@redhat.com>
* Use --help suggestion on invalid optionKarel Zak2016-12-191-1/+1
| | | | | | | | The current default is to print all usage() output. This is overkill in many case. Addresses: https://github.com/karelzak/util-linux/issues/338 Signed-off-by: Karel Zak <kzak@redhat.com>
* rename: allow full-path renamesAndreas Henriksson2015-06-251-2/+3
| | | | | | | | | | | The command "touch b0;rename.ul -v ./b0 ./b1 ./b0" used to work before "allow renaming in subdirectories" change. (regression in commit bd9ced628bb86) Addresses: https://bugs.debian.org/789240 Reported-by: gregrwm <bug-grub@whitleymott.net> Reviewed-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Andreas Henriksson <andreas@fatal.se>
* rename: use strrchr() instead of rindex()Sami Kerola2015-02-101-1/+1
| | | | | | | | | The rindex() is marked legacy in POSIX.1-2001, and apparently Androids bionic libc does not even have it so it is best not to use the legacy interface. Reference: https://lists.gnu.org/archive/html/weechat-dev/2014-02/msg00004.html Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* textual: grammarize and harmonize the stat error messageBenno Schulenberg2015-02-021-1/+1
| | | | | | | | | The message "stat failed %s" seems to say that stat() failed to do something, or failed to pass a test, but of course it means that the statting of something failed. So say so. Also make two very similar messages equal to this one. Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* textual: add a docstring to most of the utilitiesBenno Schulenberg2015-01-061-0/+4
| | | | | | | | | This adds a concise description of a tool to its usage text. A first form of this patch was proposed by Steven Honeyman (see http://www.spinics.net/lists/util-linux-ng/msg09994.html). Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* textual: fix some typos and inconsistencies in various messagesBenno Schulenberg2014-07-231-2/+2
| | | | | | | | Fixing plain typos, miswordings, inconsistent periods, some missing angular brackets, and a proper pluralization (even when it involves a constant, because for some languages the precise value matters). Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* rename: use function pointer to select file or symlink operationSami Kerola2014-07-181-75/+67Star
| | | | | | | Add separate functions to different functionality, and add a function for the stuff that is in common for both. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* rename: continue despite something failedSami Kerola2014-07-181-21/+51
| | | | | | | Try to do all file operations even when one or some of them fail, and use exit value to inform what happen. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* rename: allow renaming in subdirectoriesSami Kerola2014-07-181-2/+7
| | | | | | | | | | | | | | | Earlier the rename(1) considered path as possible string to be renamed, could lead to an issue with none existing destination. See below for demonstration of this issue. After this change all directory elements are ignored when the match finding happens. $ cd $(mktemp -d) $ mkdir aa ab $ touch a{a,b}/aa $ rename -v a x */aa rename: aa/aa: rename to xa/aa failed: No such file or directory Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* rename: fix mem leak [coverity scan]Karel Zak2014-01-141-1/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* rename: fix memory leak [coverity scan]Karel Zak2013-03-271-1/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* rename: make usage() translator friendlySami Kerola2013-01-251-8/+8
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* textual: gettextize several overlooked messagesBenno Schulenberg2013-01-251-2/+1Star
| | | | | | Also improve the clarity of some of them. Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* rename: use macro to print versionKarel Zak2012-12-101-3/+1Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* rename: add --symlink option for renaming symlink targetJan (yac) Matějka2012-12-101-13/+51
| | | | | | [kzak@redhat.com: - coding style clean up] Signed-off-by: Karel Zak <kzak@redhat.com>
* misc-utils: verify writing to streams was successfulSami Kerola2012-04-041-0/+2
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* rename: cleanup usage()Karel Zak2011-08-161-5/+6
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* rename: verbose option & maintenance fixesSami Kerola2011-06-251-32/+61
| | | | | | | | The rename has new verbose option which will print which files where renamed. Maintenance fixes includes long options, coding style and freeing memory after usage. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* misc-utils: use new xmalloc() wrapperDavidlohr Bueso2010-10-211-5/+3Star
| | | | Signed-off-by: Davidlohr Bueso <dave@gnu.org>
* rename: remove useless variableLi Zefan2007-09-051-3/+2Star
| | | | | | | The number of files successfully renamed is calculated and stored in variable ct, > but actually the variable is not used afterwards. Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
* Imported from util-linux-2.13-pre2 tarball.Karel Zak2006-12-071-2/+2
|
* Imported from util-linux-2.13-pre1 tarball.Karel Zak2006-12-071-2/+2
|
* Imported from util-linux-2.10m tarball.Karel Zak2006-12-071-2/+2
|
* Imported from util-linux-2.10f tarball.Karel Zak2006-12-071-0/+97