bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] add in a --mismatch-only option to {md5,sha1}sum


From: Kelley Cook
Subject: [PATCH] add in a --mismatch-only option to {md5,sha1}sum
Date: Mon, 04 Oct 2004 16:17:28 -0400
User-agent: Mozilla Thunderbird 0.8 (Windows/20040913)

I've always found it somewhat annoying to have to type "md5sum -c MD5SUMS | grep -v OK$" to get a readable output of which files have been modified since a tarball was created.

This small patch adds in a "-m --mismatch-only" option which neatly accomplishes the same thing.

Kelley Cook
2004-10-04  Kelley Cook  <address@hidden>

        * src/md5sum.c: Add in --mismatch-only option.
        * doc/coreutils.texi: Document it.

diff -prud coreutils-5.2.1.orig/doc/coreutils.texi 
coreutils-5.2.1/doc/coreutils.texi
--- coreutils-5.2.1.orig/doc/coreutils.texi     2004-03-10 12:50:52.000000000 
-0500
+++ coreutils-5.2.1/doc/coreutils.texi  2004-10-04 11:58:32.826177000 -0400
@@ -2945,6 +2945,16 @@ an MD5 checksum inconsistent with the as
 line is found, @command{md5sum} exits with nonzero status.  Otherwise,
 it exits successfully.
 
address@hidden -m
address@hidden --mismatch-only
address@hidden -m
address@hidden --mismatch-only
address@hidden verifying MD5 checksums
+This option is useful only when verifying checksums.
+When verifying checksums, suppress the the one-line-per-file diagnostic
+whenever a file's computed checksum matches the checksum given for
+it in the input file.
+
 @itemx --status
 @opindex --status
 @cindex verifying MD5 checksums
diff -prud coreutils-5.2.1.orig/src/md5sum.c coreutils-5.2.1/src/md5sum.c
--- coreutils-5.2.1.orig/src/md5sum.c   2004-01-21 17:27:02.000000000 -0500
+++ coreutils-5.2.1/src/md5sum.c        2004-10-04 15:54:10.499591500 -0400
@@ -86,6 +86,9 @@ static size_t min_digest_line_length;
 /* Set to the length of a digest hex string for the selected algorithm.  */
 static size_t digest_hex_bytes;
 
+/* With --check, don't output on matched checksums.  */
+static int mismatch_only = 0;
+
 /* With --check, don't generate any output.
    The exit code indicates success or failure.  */
 static int status_only = 0;
@@ -104,6 +107,7 @@ static const struct option long_options[
 {
   { "binary", no_argument, 0, 'b' },
   { "check", no_argument, 0, 'c' },
+  { "mismatch-only", no_argument, 0, 'm' },
   { "status", no_argument, 0, 2 },
   { "string", required_argument, 0, 1 },
   { "text", no_argument, 0, 't' },
@@ -140,6 +144,7 @@ With no FILE, or when FILE is -, read st
              DIGEST_TYPE_STRING (algorithm));
       fputs (_("\
 The following two options are useful only when verifying checksums:\n\
+  -m, --mismatch-only     only output mismatched checksums\n\
       --status            don't output anything, status code shows success\n\
   -w, --warn              warn about improperly formated checksum lines\n\
 \n\
@@ -477,8 +482,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 (!mismatch_only)
+                   printf ("%s: %s\n", filename, _("OK"));
                  fflush (stdout);
                }
            }
@@ -567,7 +574,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, "bcmtw", long_options, NULL)) != -1)
     switch (opt)
       {
       case 0:                  /* long option */
@@ -589,6 +596,10 @@ main (int argc, char **argv)
       case 'c':
        do_check = 1;
        break;
+      case 'm':
+       status_only = 0;
+       mismatch_only = 1;
+       break;
       case 2:
        status_only = 1;
        warn = 0;
@@ -624,6 +635,12 @@ verifying checksums"));
       usage (EXIT_FAILURE);
     }
 
+  if (mismatch_only && !do_check)
+    {
+      error (0, 0,
+       _("the --mismatch-only option is meaningful only when verifying 
checksums"));
+      usage (EXIT_FAILURE);
+    }
   if (status_only && !do_check)
     {
       error (0, 0,

reply via email to

[Prev in Thread] Current Thread [Next in Thread]