bug-coreutils@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Erik Auerswald <auerswal@unix-ag.uni-kl.de>
To: bug-coreutils@gnu.org
Subject: (no subject)
Date: Sun, 13 Apr 2008 18:31:25 +0200	[thread overview]
Message-ID: <20080413163125.GA22848@sushi.unix-ag.uni-kl.de> (raw)

>From 0bd30949c1953fc5339fc5cf30cc2527d3e660d7 Mon Sep 17 00:00:00 2001
From: Erik Auerswald <auerswal@unix-ag.uni-kl.de>
Date: Sun, 13 Apr 2008 18:12:11 +0200
Subject: [PATCH] md5sum+sha*sum: add option --quiet/-q to suppress OK messages

* src/md5sum.c: add option --quiet/-q to suppress OK messages
* doc/coreutils.texi: document option --quiet/-q
* tests/misc/md5sum: add test for option --quiet/-q
* NEWS: mention new option --quiet/-q for md5sum+sha*sum in "New
  features" section

Signed-off-by: Erik Auerswald <auerswal@unix-ag.uni-kl.de>
---
 NEWS               |    3 +++
 doc/coreutils.texi |   11 +++++++++++
 src/md5sum.c       |   29 +++++++++++++++++++++++++----
 tests/misc/md5sum  |    8 ++++++++
 4 files changed, 47 insertions(+), 4 deletions(-)

diff --git a/NEWS b/NEWS
index e208b30..5a97f13 100644
--- a/NEWS
+++ b/NEWS
@@ -47,6 +47,9 @@ GNU coreutils NEWS                                    -*- outline -*-
 
 ** New features
 
+  md5sum and sha*sum now know an option --quiet/-q to suppress the
+  printing of 'OK' messages.
+
   join now verifies that the inputs are in sorted order.  This check can
   be turned off with the --nocheck-order option.
 
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 01c2f00..7bffd34 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -3287,6 +3287,17 @@ 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.
 
+@item -q
+@itemx --quiet
+@opindex -q
+@opindex --quiet
+@cindex 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 28bde99..821a3ad 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;
 
@@ -131,6 +134,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, 'q' },
   { GETOPT_HELP_OPTION_DECL },
   { GETOPT_VERSION_OPTION_DECL },
   { NULL, 0, NULL, 0 }
@@ -174,8 +178,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\
+  -q, --quiet             no output for successfully verified files\n\
   -w, --warn              warn about improperly formatted checksum lines\n\
 \n\
 "), stdout);
@@ -521,8 +526,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);
 		}
 	    }
@@ -603,7 +610,7 @@ main (int argc, char **argv)
 
   atexit (close_stdout);
 
-  while ((opt = getopt_long (argc, argv, "bctw", long_options, NULL)) != -1)
+  while ((opt = getopt_long (argc, argv, "bctwq", long_options, NULL)) != -1)
     switch (opt)
       {
       case 'b':
@@ -615,6 +622,7 @@ main (int argc, char **argv)
       case STATUS_OPTION:
 	status_only = true;
 	warn = false;
+	quiet = false;
 	break;
       case 't':
 	binary = 0;
@@ -622,6 +630,12 @@ main (int argc, char **argv)
       case 'w':
 	status_only = false;
 	warn = true;
+	quiet = false;
+	break;
+      case 'q':
+	status_only = false;
+	warn = false;
+	quiet = true;
 	break;
       case_GETOPT_HELP_CHAR;
       case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
@@ -653,6 +667,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 ca23d94..da58801 100755
--- a/tests/misc/md5sum
+++ b/tests/misc/md5sum
@@ -51,6 +51,14 @@ my @Tests =
 				{OUT=>"f: OK\n"}],
      ['check-2', '--check', '--status', {IN=>{'f.md5' => "$degenerate  f\n"}},
 				{AUX=> {f=> 'foo'}}, {EXIT=> 1}],
+     ['check-3', '--check', '--quiet', {AUX=> {f=> ''}},
+				{IN=> {'f.md5' => "$degenerate  f\n"}},
+				{OUT=>""}],
+     ['check-4', '--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

             reply	other threads:[~2008-04-13 17:49 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-13 16:31 Erik Auerswald [this message]
  -- strict thread matches above, loose matches on Subject: below --
2010-01-29 17:11 (no subject) Henry Hung
2010-01-29 20:10 ` Kamil Dudka
2009-03-19 10:47 lynn and jym
2009-02-03 16:01 Jeromy Keloway
2009-02-04  8:30 ` Kamil Dudka
2009-02-04 11:54 ` Pádraig Brady
2008-12-02 16:56 Jan Halla
2008-12-03 16:49 ` Alfred M. Szmidt
2008-11-29 21:15 Martin Douglas
2008-07-03 22:48 Craig Naumann
2008-07-04  7:34 ` James Youngman
2008-02-16 15:46 James Youngman
2008-02-16 17:26 ` James Youngman
2007-07-17 10:17 Elmian Shabahang
2007-04-02 20:59 ara
2007-02-06  9:29 Dima Abramian
2007-02-22 18:07 ` James Youngman
2006-12-11 14:16 newtonjunior
2006-12-11 18:04 ` Andreas Schwab
2006-09-09 12:03 Kartik K. Agaram
2006-08-27 23:43 deepesh chaudhary
2006-05-24 20:42 ralf.rabemann
2006-05-25  6:45 ` Bob Proulx
2006-05-25 12:42 ` Eric Blake
2005-12-20 16:46 Lakkimsetti, Chalapathi G
2005-12-20 20:33 ` Brian Dessent
2005-06-21  2:40 刘玉
2005-07-13  4:23 ` Bob Proulx
2005-04-08 17:04 Stephen Mc Gowan
2005-03-23 12:14 tdovera
2005-03-16 19:18 Jan Engelhardt
2003-12-16 19:50 Bruce Korb
2003-11-17 18:41 Gary Leach
2003-11-18  4:32 ` Bob Proulx
2003-07-09 17:19 Daniel de la Cruz
2003-07-09 19:42 ` Paul Jarc
2002-11-11 11:47 Bruno Haible

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-coreutils

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080413163125.GA22848@sushi.unix-ag.uni-kl.de \
    --to=auerswal@unix-ag.uni-kl.de \
    --cc=bug-coreutils@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).