diff options
| author | Kamil Dudka <kdudka@redhat.com> | 2009-01-13 18:35:00 +0100 |
|---|---|---|
| committer | Jim Meyering <meyering@redhat.com> | 2009-01-14 09:09:22 +0100 |
| commit | d01338eb3d30e5634f1b4d4179c229f54eea0b44 (patch) | |
| tree | 6ed873717bb12faed3300b9be390aaabee40fa74 /src/mv.c | |
| parent | option handling: make exceptions more consistent (diff) | |
| download | coreutils-d01338eb3d30e5634f1b4d4179c229f54eea0b44.tar.gz coreutils-d01338eb3d30e5634f1b4d4179c229f54eea0b44.zip | |
cp/mv: add --no-clobber (-n) option to not overwrite target
* src/cp.c (usage): Show new option -n in --help.
(main): Handle new option -n.
* src/mv.c (usage): Show new option -n in --help.
(main): Handle new option -n.
* doc/coreutils.texi: Document new cp/mv option -n.
* tests/cp/cp-i: Add tests for -f, -i and -n options.
* tests/mv/mv-n: New test for mv -n.
* tests/Makefile.am: Add test mv/mv-n to the list.
* NEWS: Mention the change.
Diffstat (limited to 'src/mv.c')
| -rw-r--r-- | src/mv.c | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -1,5 +1,5 @@ /* mv -- move or rename files - Copyright (C) 86, 89, 90, 91, 1995-2008 Free Software Foundation, Inc. + Copyright (C) 86, 89, 90, 91, 1995-2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -62,6 +62,7 @@ static struct option const long_options[] = {"backup", optional_argument, NULL, 'b'}, {"force", no_argument, NULL, 'f'}, {"interactive", no_argument, NULL, 'i'}, + {"no-clobber", no_argument, NULL, 'n'}, {"no-target-directory", no_argument, NULL, 'T'}, {"strip-trailing-slashes", no_argument, NULL, STRIP_TRAILING_SLASHES_OPTION}, {"suffix", required_argument, NULL, 'S'}, @@ -296,6 +297,8 @@ Mandatory arguments to long options are mandatory for short options too.\n\ -b like --backup but does not accept an argument\n\ -f, --force do not prompt before overwriting\n\ -i, --interactive prompt before overwrite\n\ + -n, --no-clobber do not overwrite an existing file\n\ +If you specify more than one of -i, -f, -n, only the final one takes effect.\n\ "), stdout); fputs (_("\ --strip-trailing-slashes remove any trailing slashes from each SOURCE\n\ @@ -358,7 +361,7 @@ main (int argc, char **argv) we'll actually use backup_suffix_string. */ backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX"); - while ((c = getopt_long (argc, argv, "bfit:uvS:T", long_options, NULL)) + while ((c = getopt_long (argc, argv, "bfint:uvS:T", long_options, NULL)) != -1) { switch (c) @@ -374,6 +377,9 @@ main (int argc, char **argv) case 'i': x.interactive = I_ASK_USER; break; + case 'n': + x.interactive = I_ALWAYS_NO; + break; case STRIP_TRAILING_SLASHES_OPTION: remove_trailing_slashes = true; break; @@ -446,6 +452,13 @@ main (int argc, char **argv) quote (file[n_files - 1])); } + if (make_backups && x.interactive == I_ALWAYS_NO) + { + error (0, 0, + _("options --backup and --no-clobber are mutually exclusive")); + usage (EXIT_FAILURE); + } + if (backup_suffix_string) simple_backup_suffix = xstrdup (backup_suffix_string); |
