Hi,
> On Tue, May 13, 2008 at 03:31:46PM +0200, Jim Meyering wrote:
> > Erik Auerswald <[EMAIL PROTECTED]> wrote:
> > > OK, thanks. Do you want me to send an updated patch after coreutils-6.12
> > > is released?
> >
> > It'd be nice, and would serve as a reminder to me.
And here it is... (attached).
Erik
--
In the beginning, there were not enough colors.
-- Guy Keren
>From a5496e3fc63b9d4bfa73527bde20c9d1a3606098 Mon Sep 17 00:00:00 2001
From: Erik Auerswald <[EMAIL PROTECTED]>
Date: Sun, 1 Jun 2008 12:40:40 +0200
Subject: [PATCH] md5sum+sha*sum: add option --quiet to suppress OK messages
* src/md5sum.c: add option --quiet to suppress OK messages
* doc/coreutils.texi: document option --quiet
* tests/misc/md5sum: add test for option --quiet
* NEWS: mention new option --quiet for md5sum+sha*sum in "New
features" section
Signed-off-by: Erik Auerswald <[EMAIL PROTECTED]>
---
NEWS | 5 +++++
doc/coreutils.texi | 9 +++++++++
src/md5sum.c | 30 ++++++++++++++++++++++++++----
tests/misc/md5sum | 9 +++++++++
4 files changed, 49 insertions(+), 4 deletions(-)
diff --git a/NEWS b/NEWS
index 02be5c2..194dde8 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,11 @@ GNU coreutils NEWS -*- outline -*-
* Noteworthy changes in release 7.0 (????-??-??) [beta]
+** New features
+
+ md5sum and sha*sum now know an option --quiet to suppress the printing
+ of 'OK' messages.
+
* Noteworthy changes in release 6.12 (2008-05-31) [stable]
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index dbc8a8b..21ed1c0 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -3289,6 +3289,15 @@ If all listed files are readable and are consistent with the associated
MD5 checksums, exit successfully. Otherwise exit with a status code
indicating there was a failure.
[EMAIL PROTECTED] --quiet
[EMAIL PROTECTED] --quiet
[EMAIL PROTECTED] verifying MD5 checksums
+This option is useful only when verifying checksums.
+When verifying checksums, don't generate an 'OK' message per successfully
+checked file. Files that fail the verification are reported in the
+default one-line-per-file format. If any files failed verification,
+a warning summarizing any failures is printed to standard error.
+
@item -t
@itemx --text
@opindex -t
diff --git a/src/md5sum.c b/src/md5sum.c
index df812b9..5fe17c5 100644
--- a/src/md5sum.c
+++ b/src/md5sum.c
@@ -117,6 +117,9 @@ static bool status_only = false;
improperly formatted checksum line. */
static bool warn = false;
+/* With --quiet, don't print a message for successfully verified files */
+static bool quiet = false;
+
/* The name this program was run with. */
char *program_name;
@@ -124,7 +127,8 @@ char *program_name;
non-character as a pseudo short option, starting with CHAR_MAX + 1. */
enum
{
- STATUS_OPTION = CHAR_MAX + 1
+ STATUS_OPTION = CHAR_MAX + 1,
+ QUIET_OPTION
};
static const struct option long_options[] =
@@ -134,6 +138,7 @@ static const struct option long_options[] =
{ "status", no_argument, NULL, STATUS_OPTION },
{ "text", no_argument, NULL, 't' },
{ "warn", no_argument, NULL, 'w' },
+ { "quiet", no_argument, NULL, QUIET_OPTION },
{ GETOPT_HELP_OPTION_DECL },
{ GETOPT_VERSION_OPTION_DECL },
{ NULL, 0, NULL, 0 }
@@ -177,8 +182,9 @@ With no FILE, or when FILE is -, read standard input.\n\
"), stdout);
fputs (_("\
\n\
-The following two options are useful only when verifying checksums:\n\
+The following three options are useful only when verifying checksums:\n\
--status don't output anything, status code shows success\n\
+ --quiet no output for successfully verified files\n\
-w, --warn warn about improperly formatted checksum lines\n\
\n\
"), stdout);
@@ -530,8 +536,10 @@ digest_check (const char *checkfile_name)
if (!status_only)
{
- printf ("%s: %s\n", filename,
- (cnt != digest_bin_bytes ? _("FAILED") : _("OK")));
+ if (cnt != digest_bin_bytes)
+ printf ("%s: %s\n", filename, _("FAILED"));
+ else if (!quiet)
+ printf ("%s: %s\n", filename, _("OK"));
fflush (stdout);
}
}
@@ -624,6 +632,7 @@ main (int argc, char **argv)
case STATUS_OPTION:
status_only = true;
warn = false;
+ quiet = false;
break;
case 't':
binary = 0;
@@ -631,6 +640,12 @@ main (int argc, char **argv)
case 'w':
status_only = false;
warn = true;
+ quiet = false;
+ break;
+ case QUIET_OPTION:
+ status_only = false;
+ warn = false;
+ quiet = true;
break;
case_GETOPT_HELP_CHAR;
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
@@ -662,6 +677,13 @@ main (int argc, char **argv)
usage (EXIT_FAILURE);
}
+ if (quiet & !do_check)
+ {
+ error (0, 0,
+ _("the --quiet option is meaningful only when verifying checksums"));
+ usage (EXIT_FAILURE);
+ }
+
if (!O_BINARY && binary < 0)
binary = 0;
diff --git a/tests/misc/md5sum b/tests/misc/md5sum
index c99d6bb..bc1ac08 100755
--- a/tests/misc/md5sum
+++ b/tests/misc/md5sum
@@ -45,6 +45,15 @@ my @Tests =
{OUT=>"f: OK\n"}],
['check-2', '--check', '--status', {IN=>{'f.md5' => "$degenerate f\n"}},
{AUX=> {f=> 'foo'}}, {EXIT=> 1}],
+ ['check-quiet1', '--check', '--quiet', {AUX=> {f=> ''}},
+ {IN=> {'f.md5' => "$degenerate f\n"}},
+ {OUT=>""}],
+ ['check-quiet2', '--check', '--quiet',
+ {IN=>{'f.md5' => "$degenerate f\n"}},
+ {AUX=> {f=> 'foo'}}, {OUT=>"f: FAILED\n"},
+ {ERR=>"md5sum: WARNING: 1 of 1 computed"
+ . " checksum did NOT match\n"},
+ {EXIT=> 1}],
# The sha1sum and md5sum drivers share a lot of code.
# Ensure that md5sum does *not* share the part that makes
# sha1sum accept BSD format.
--
1.5.5.3
_______________________________________________
Bug-coreutils mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-coreutils