Hi,

On Sun, May 04, 2008 at 06:33:45PM +0200, Erik Auerswald wrote:
> On Tue, Apr 22, 2008 at 07:10:58PM +0200, Jim Meyering wrote:
> > Erik Auerswald <[EMAIL PROTECTED]> wrote:
> > > On Tue, Apr 22, 2008 at 06:05:48PM +0200, Jim Meyering wrote:
> > >> Erik Auerswald <[EMAIL PROTECTED]> wrote:
> > >> > IMHO md5sum and sha*sum are too verbose by default, especially when
> > >> > checking a large collection of files with only a few failing 
> > >> > validation.
> > >> > Therefore I'd like to see an option added to suppress just the output
> > >> > for successfully verified files.
> > >>
> > >> The only suggestion I can make so far is to omit the short-named "-q" 
> > >> option.
> > >> The "--q" abbreviation of --quiet is only one byte longer.
> 
> The attached patch adds the above feature and adds an option --quiet to
> md5sum and sha*sum (no short option added).
> 
> The signed copyright assignment is on it's way, the patch is against the
> current git HEAD.

The copyright assignment process with the FSF is completed, find the
patch against current HEAD as an attachment.

Erik
-- 
I don't want to see the state of the file when I'm editing.
                        -- Ken Thompson
>From f776112966d6771b3c7dd8228fa09fb129c8edde Mon Sep 17 00:00:00 2001
From: Erik Auerswald <[EMAIL PROTECTED]>
Date: Tue, 13 May 2008 14:13:30 +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 8cee7f5..69f5444 100644
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,11 @@ GNU coreutils NEWS                                    -*- outline -*-
   tac: avoid segfault with --regex (-r) and multiple files, e.g.,
   "echo > x; tac -r x x".  [bug present at least in textutils-1.8b, from 1992]
 
+** New features
+
+  md5sum and sha*sum now know an option --quiet to suppress the printing
+  of 'OK' messages.
+
 
 * Noteworthy changes in release 6.11 (2008-04-19) [stable]
 
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 206f8dd..8a03581 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -3287,6 +3287,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 f83a7b1..1327ced 100644
--- a/src/md5sum.c
+++ b/src/md5sum.c
@@ -114,6 +114,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;
 
@@ -121,7 +124,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[] =
@@ -131,6 +135,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 }
@@ -174,8 +179,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);
@@ -527,8 +533,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);
 		}
 	    }
@@ -621,6 +629,7 @@ main (int argc, char **argv)
       case STATUS_OPTION:
 	status_only = true;
 	warn = false;
+	quiet = false;
 	break;
       case 't':
 	binary = 0;
@@ -628,6 +637,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);
@@ -659,6 +674,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 28927f5..dafadb3 100755
--- a/tests/misc/md5sum
+++ b/tests/misc/md5sum
@@ -51,6 +51,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.1

_______________________________________________
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils

Reply via email to