[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH]: add an option for quiet copy operations
From: |
Guido Trentalancia |
Subject: |
[PATCH]: add an option for quiet copy operations |
Date: |
Thu, 16 Feb 2012 08:21:43 +0100 |
Hello.
I am writing to propose a simple patch for review. The patch adds an
option "-q" or "--quiet" to cp, mv and install so that they can support
quiet operation on missing SOURCE files.
Such behavior might be useful for example when using any of the above
commands from scripts.
The patch can be applied both to the git tree and to the latest release.
Add an option "-q, --quiet" for cp, mv and install so that the program
does not complain about any missing SOURCE file.
Signed-off-by: Guido Trentalancia <address@hidden>
---
doc/coreutils.texi | 14 ++++++++++++++
src/copy.c | 3 ++-
src/copy.h | 3 +++
src/cp.c | 11 ++++++++++-
src/install.c | 8 +++++++-
src/mv.c | 10 +++++++++-
6 files changed, 45 insertions(+), 4 deletions(-)
diff -pru coreutils-8.15-original/doc/coreutils.texi
coreutils-8.15/doc/coreutils.texi
--- coreutils-8.15-original/doc/coreutils.texi 2012-01-03 16:48:48.000000000
+0100
+++ coreutils-8.15/doc/coreutils.texi 2012-02-16 07:00:21.482160794 +0100
@@ -7837,6 +7837,13 @@ cp --parents a/b/c existing_dir
copies the file @file{a/b/c} to @file{existing_dir/a/b/c}, creating
any missing intermediate directories.
+@item -q
+@itemx --quiet
+@opindex -q
+@opindex --quiet
+Do not produce an error message if any of the SOURCE arguments does not
+exist.
+
@item -R
@itemx -r
@itemx --recursive
@@ -8527,6 +8534,13 @@ This option is useful if you want to use
of installed files to keep track of when they were last built as opposed
to when they were last installed.
+@item -q
+@itemx --quiet
+@opindex -q
+@opindex --quiet
+Do not produce an error message if any of the SOURCE arguments does not
+exist.
+
@item -s
@itemx --strip
@opindex -s
diff -pru coreutils-8.15-original/src/copy.c coreutils-8.15/src/copy.c
--- coreutils-8.15-original/src/copy.c 2012-01-05 15:24:19.000000000 +0100
+++ coreutils-8.15/src/copy.c 2012-02-16 06:00:41.074544259 +0100
@@ -1572,7 +1572,8 @@ copy_internal (char const *src_name, cha
if (XSTAT (x, src_name, &src_sb) != 0)
{
- error (0, errno, _("cannot stat %s"), quote (src_name));
+ if (!x->quiet)
+ error (0, errno, _("cannot stat %s"), quote (src_name));
return false;
}
diff -pru coreutils-8.15-original/src/copy.h coreutils-8.15/src/copy.h
--- coreutils-8.15-original/src/copy.h 2012-01-01 10:04:06.000000000 +0100
+++ coreutils-8.15/src/copy.h 2012-02-16 05:50:26.251633846 +0100
@@ -215,6 +215,9 @@ struct cp_options
*/
bool reduce_diagnostics;
+ /* If true, do not complain when a SOURCE argument does not exist. */
+ bool quiet;
+
/* If true, copy directories recursively and copy special files
as themselves rather than copying their contents. */
bool recursive;
diff -pru coreutils-8.15-original/src/cp.c coreutils-8.15/src/cp.c
--- coreutils-8.15-original/src/cp.c 2012-01-01 10:04:06.000000000 +0100
+++ coreutils-8.15/src/cp.c 2012-02-16 06:41:26.235023924 +0100
@@ -131,6 +131,7 @@ static struct option const long_opts[] =
{"parents", no_argument, NULL, PARENTS_OPTION},
{"path", no_argument, NULL, PARENTS_OPTION}, /* Deprecated. */
{"preserve", optional_argument, NULL, PRESERVE_ATTRIBUTES_OPTION},
+ {"quiet", no_argument, NULL, 'q'},
{"recursive", no_argument, NULL, 'R'},
{"remove-destination", no_argument, NULL, UNLINK_DEST_BEFORE_OPENING},
{"sparse", required_argument, NULL, SPARSE_OPTION},
@@ -208,6 +209,9 @@ Mandatory arguments to long options are
--parents use full source file name under DIRECTORY\n\
"), stdout);
fputs (_("\
+ -q, --quiet do not complain about missing SOURCE files\n\
+"), stdout);
+ fputs (_("\
-R, -r, --recursive copy directories recursively\n\
--reflink[=WHEN] control clone/CoW copies. See below\n\
--remove-destination remove each existing destination file before\n\
@@ -792,6 +796,7 @@ cp_option_init (struct cp_options *x)
x->data_copy_required = true;
x->require_preserve = false;
+ x->quiet = false;
x->recursive = false;
x->sparse_mode = SPARSE_AUTO;
x->symbolic_link = false;
@@ -933,7 +938,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, "abdfHilLnprst:uvxPRS:T",
+ while ((c = getopt_long (argc, argv, "abdfHilLnpqrst:uvxPRS:T",
long_opts, NULL))
!= -1)
{
@@ -1041,6 +1046,10 @@ main (int argc, char **argv)
parents_option = true;
break;
+ case 'q':
+ x.quiet = true;
+ break;
+
case 'r':
case 'R':
x.recursive = true;
diff -pru coreutils-8.15-original/src/install.c coreutils-8.15/src/install.c
--- coreutils-8.15-original/src/install.c 2012-02-16 06:54:21.258922905
+0100
+++ coreutils-8.15/src/install.c 2012-02-16 06:55:19.465285193 +0100
@@ -129,6 +129,7 @@ static struct option const long_options[
{"owner", required_argument, NULL, 'o'},
{"preserve-timestamps", no_argument, NULL, 'p'},
{"preserve-context", no_argument, NULL, PRESERVE_CONTEXT_OPTION},
+ {"quiet", no_argument, NULL, 'q'},
{"strip", no_argument, NULL, 's'},
{"strip-program", required_argument, NULL, STRIP_PROGRAM_OPTION},
{"suffix", required_argument, NULL, 'S'},
@@ -280,6 +281,7 @@ cp_option_init (struct cp_options *x)
x->require_preserve = false;
x->require_preserve_context = false;
x->require_preserve_xattr = false;
+ x->quiet = false;
x->recursive = false;
x->sparse_mode = SPARSE_AUTO;
x->symbolic_link = false;
@@ -632,6 +634,7 @@ Mandatory arguments to long options are
fputs (_("\
-p, --preserve-timestamps apply access/modification times of SOURCE
files\n\
to corresponding destination files\n\
+ -q, --quiet do not complain about missing SOURCE files\n\
-s, --strip strip symbol tables\n\
--strip-program=PROGRAM program used to strip binaries\n\
-S, --suffix=SUFFIX override the usual backup suffix\n\
@@ -783,7 +786,7 @@ main (int argc, char **argv)
we'll actually use backup_suffix_string. */
backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
- while ((optc = getopt_long (argc, argv, "bcCsDdg:m:o:pt:TvS:Z:",
long_options,
+ while ((optc = getopt_long (argc, argv, "bcCsDdg:m:o:pqt:TvS:Z:",
long_options,
NULL)) != -1)
{
switch (optc)
@@ -830,6 +833,9 @@ main (int argc, char **argv)
case 'p':
x.preserve_timestamps = true;
break;
+ case 'q':
+ x.quiet = true;
+ break;
case 'S':
make_backups = true;
backup_suffix_string = optarg;
diff -pru coreutils-8.15-original/src/mv.c coreutils-8.15/src/mv.c
--- coreutils-8.15-original/src/mv.c 2012-02-16 06:34:23.893273201 +0100
+++ coreutils-8.15/src/mv.c 2012-02-16 06:54:10.913858428 +0100
@@ -59,6 +59,7 @@ static struct option const long_options[
{"interactive", no_argument, NULL, 'i'},
{"no-clobber", no_argument, NULL, 'n'},
{"no-target-directory", no_argument, NULL, 'T'},
+ {"quiet", no_argument, NULL, 'q'},
{"strip-trailing-slashes", no_argument, NULL, STRIP_TRAILING_SLASHES_OPTION},
{"suffix", required_argument, NULL, 'S'},
{"target-directory", required_argument, NULL, 't'},
@@ -124,6 +125,7 @@ cp_option_init (struct cp_options *x)
x->require_preserve_context = false;
x->preserve_xattr = true;
x->require_preserve_xattr = false;
+ x->quiet = false;
x->recursive = true;
x->sparse_mode = SPARSE_AUTO; /* FIXME: maybe make this an option */
x->symbolic_link = false;
@@ -305,6 +307,9 @@ Mandatory arguments to long options are
If you specify more than one of -i, -f, -n, only the final one takes effect.\n\
"), stdout);
fputs (_("\
+ -q, --quiet do not complain about missing SOURCE files\n\
+"), stdout);
+ fputs (_("\
--strip-trailing-slashes remove any trailing slashes from each SOURCE\n\
argument\n\
-S, --suffix=SUFFIX override the usual backup suffix\n\
@@ -368,7 +373,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, "bfint:uvS:T", long_options, NULL))
+ while ((c = getopt_long (argc, argv, "bfinqt:uvS:T", long_options, NULL))
!= -1)
{
switch (c)
@@ -390,6 +395,9 @@ main (int argc, char **argv)
case STRIP_TRAILING_SLASHES_OPTION:
remove_trailing_slashes = true;
break;
+ case 'q':
+ x.quiet = true;
+ break;
case 't':
if (target_directory)
error (EXIT_FAILURE, 0, _("multiple target directories
specified"));
- [PATCH]: add an option for quiet copy operations,
Guido Trentalancia <=