coreutils
[Top][All Lists]
Advanced

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

Re: [PATCH] md5sum: Implemented --pedantic option to be more strict in v


From: Jim Meyering
Subject: Re: [PATCH] md5sum: Implemented --pedantic option to be more strict in verification mode
Date: Thu, 07 Jul 2011 12:16:32 +0200

Jim Meyering wrote:

> schoenfeld / in-medias-res wrote:
>>>From 156d7e829da3ab9d895a275c2cd02e52388bcd0d Mon Sep 17 00:00:00 2001
>> From: Patrick Schoenfeld <address@hidden>
>> Date: Mon, 17 Nov 2008 20:54:08 +0100
>> Subject: [PATCH] md5sum: Implemented --pedantic option to be more strict in 
>> verification mode
>>
>> * md5sum: Implemented a --pedantic option in --check mode, which lets md5sum
>>   bail out with a non-zero exit code, if one or more improperly formatted 
>> line
>>   is found. Feature request by Dan Jacobson.
>>   (http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=353911)
> ...
>> Please note that I'm still in process of copyright assignment.
>> Send a mail to assign@... but got no reply yet.
> ...
>
>> + md5sum now recognizes a new option --pedantic when verifying
>> md5sums in a file
>> +  (with --check) to let it return a non-zero exit code if one or more 
>> invalid
>> +  lines are found
>> +
>>  ** Bug fixes
>
> Thanks for the patch.
> Your copyright assignment did go through.
>
> I've rebased your patch and made a few minor changes (NEWS, --help,
> indentation).
> More will be required:
>   - also describe the option in sections for sha1sum and the other
>     sha*sum programs; probably use a macro to avoid duplication

It turns out this is not necessary.
The sha* section already defers to the md5sum description
saying they have exactly the same options.

>   - when checking two or more files, don't stop processing (exit) upon
>     an invalid line in the first.  i.e., process all files before exiting.

This was trivial to adjust.

>   - decide on the option name: I prefer --strict;  --pedantic comes
>     with connotations that seem unjustified.

I made that change

>   - exercise all of this via the test suite

Added below.
I'll squash the first three commits into Patrick's commit.

>From c5d9c1ac87d919c7d7cdb39d47c17702768a4285 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Thu, 7 Jul 2011 11:22:07 +0200
Subject: [PATCH 1/4] don't exit on first losing file

---
 src/md5sum.c |   14 +++-----------
 1 files changed, 3 insertions(+), 11 deletions(-)

diff --git a/src/md5sum.c b/src/md5sum.c
index 9da9942..987428f 100644
--- a/src/md5sum.c
+++ b/src/md5sum.c
@@ -611,20 +611,12 @@ digest_check (const char *checkfile_name)
                      select_plural (n_mismatched_checksums))),
                    n_mismatched_checksums);
         }
-
-      if (n_improperly_formatted_lines != 0)
-        {
-          if (pedantic)
-            {
-              /* Bail out if more then one improperly formatted line is found
-                 and pedantic option is set */
-              exit (EXIT_FAILURE);
-            }
-        }
     }
+
   return (n_properly_formatted_lines != 0
           && n_mismatched_checksums == 0
-          && n_open_or_read_failures == 0);
+          && n_open_or_read_failures == 0
+          && (!pedantic || n_improperly_formatted_lines == 0));
 }

 int
--
1.7.6.430.g34be2


>From 3b73dd4c8cad3e961f79653fb9c3af9bc792ee5b Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Thu, 7 Jul 2011 11:44:59 +0200
Subject: [PATCH 2/4] clarify texi description

---
 doc/coreutils.texi |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 8ccff69..7ce74b6 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -3705,8 +3705,9 @@ md5sum invocation
 @itemx --pedantic
 @opindex --pedantic
 @cindex verifying MD5 checksums
-When verifying checksums, fail if one or more improperly formatted MD5 checksum
-line is found.
+When verifying checksums,
+if one or more input line is invalid,
+exit nonzero after all warnings have been issued.

 @end table

--
1.7.6.430.g34be2


>From 6bdaa6bf83b6168d7b07da7137d810d61ba4b7c8 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Thu, 7 Jul 2011 11:46:38 +0200
Subject: [PATCH 3/4] s/pedantic/strict/i

---
 NEWS               |    2 +-
 doc/coreutils.texi |    4 ++--
 src/md5sum.c       |   20 ++++++++++----------
 3 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/NEWS b/NEWS
index 499084e..a545834 100644
--- a/NEWS
+++ b/NEWS
@@ -29,7 +29,7 @@ GNU coreutils NEWS                                    -*- 
outline -*-
   Note the use of single quotes, not double quotes.
   That creates files named xaa.xz, xab.xz and xac.xz.

-  md5sum accepts the new --pedantic option.  With --check, it makes the
+  md5sum accepts the new --strict option.  With --check, it makes the
   tool exit non-zero for any invalid input line, rather than just warning.
   This also affects sha1sum, sha224sum, sha384sum and sha512sum.

diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 7ce74b6..95cc44a 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -3702,8 +3702,8 @@ md5sum invocation
 This option is useful only if all but a few lines in the checked input
 are valid.

-@itemx --pedantic
-@opindex --pedantic
+@itemx --strict
+@opindex --strict
 @cindex verifying MD5 checksums
 When verifying checksums,
 if one or more input line is invalid,
diff --git a/src/md5sum.c b/src/md5sum.c
index 987428f..ff9538a 100644
--- a/src/md5sum.c
+++ b/src/md5sum.c
@@ -122,9 +122,9 @@ static bool warn = false;
 /* With --check, suppress the "OK" printed for each verified file.  */
 static bool quiet = false;

-/* With --check, exit with a non-zero return code, if any line is
+/* With --check, exit with a non-zero return code if any line is
    improperly formatted. */
-static bool pedantic = false;
+static bool strict = false;

 /* For long options that have no equivalent short option, use a
    non-character as a pseudo short option, starting with CHAR_MAX + 1.  */
@@ -132,7 +132,7 @@ enum
 {
   STATUS_OPTION = CHAR_MAX + 1,
   QUIET_OPTION,
-  PEDANTIC_OPTION
+  STRICT_OPTION
 };

 static struct option const long_options[] =
@@ -143,7 +143,7 @@ static struct option const long_options[] =
   { "status", no_argument, NULL, STATUS_OPTION },
   { "text", no_argument, NULL, 't' },
   { "warn", no_argument, NULL, 'w' },
-  { "pedantic", no_argument, NULL, PEDANTIC_OPTION },
+  { "strict", no_argument, NULL, STRICT_OPTION },
   { GETOPT_HELP_OPTION_DECL },
   { GETOPT_VERSION_OPTION_DECL },
   { NULL, 0, NULL, 0 }
@@ -194,7 +194,7 @@ The following three options are useful only when verifying 
checksums:\n\
 \n\
 "), stdout);
       fputs (_("\
-      --pedantic       with --check, exit non-zero for any invalid input\n\
+      --strict         with --check, exit non-zero for any invalid input\n\
 "), stdout);
       fputs (HELP_OPTION_DESCRIPTION, stdout);
       fputs (VERSION_OPTION_DESCRIPTION, stdout);
@@ -616,7 +616,7 @@ digest_check (const char *checkfile_name)
   return (n_properly_formatted_lines != 0
           && n_mismatched_checksums == 0
           && n_open_or_read_failures == 0
-          && (!pedantic || n_improperly_formatted_lines == 0));
+          && (!strict || n_improperly_formatted_lines == 0));
 }

 int
@@ -670,8 +670,8 @@ main (int argc, char **argv)
         warn = false;
         quiet = true;
         break;
-      case PEDANTIC_OPTION:
-        pedantic = true;
+      case STRICT_OPTION:
+        strict = true;
         break;
       case_GETOPT_HELP_CHAR;
       case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
@@ -710,10 +710,10 @@ main (int argc, char **argv)
       usage (EXIT_FAILURE);
     }

-  if (pedantic & !do_check)
+  if (strict & !do_check)
    {
      error (0, 0,
-        _("the --pedantic option is meaningful only when verifying 
checksums"));
+        _("the --strict option is meaningful only when verifying checksums"));
      usage (EXIT_FAILURE);
    }

--
1.7.6.430.g34be2


>From 25a157c470e4c1c1f9d37916e90070246309cc3d Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Thu, 7 Jul 2011 12:12:40 +0200
Subject: [PATCH 4/4] tests: exercise md5sum's new --strict option

* tests/misc/md5sum: Exercise new --strict option.
---
 tests/misc/md5sum |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/tests/misc/md5sum b/tests/misc/md5sum
index f09a200..e8877e0 100755
--- a/tests/misc/md5sum
+++ b/tests/misc/md5sum
@@ -43,6 +43,23 @@ my @Tests =
      ['check-1', '--check', {AUX=> {f=> ''}},
                                 {IN=> {'f.md5' => "$degenerate  f\n"}},
                                 {OUT=>"f: OK\n"}],
+
+     # Same as above, but with an added empty line, to provoke --strict.
+     ['ck-strict-1', '--check --strict', {AUX=> {f=> ''}},
+                                {IN=> {'f.md5' => "$degenerate  f\n\n"}},
+                                {OUT=>"f: OK\n"},
+                                {ERR=>"md5sum: "
+                                 . "WARNING: 1 line is improperly 
formatted\n"},
+                                {EXIT=> 1}],
+
+     # As above, but with the invalid line first, to ensure that following
+     # lines are processed in spite of the preceding invalid input line.
+     ['ck-strict-2', '--check --strict', {AUX=> {f=> ''}},
+                                {IN=> {'in.md5' => "\n$degenerate  f\n"}},
+                                {OUT=>"f: OK\n"},
+                                {ERR=>"md5sum: "
+                                 . "WARNING: 1 line is improperly 
formatted\n"},
+                                {EXIT=> 1}],
      ['check-2', '--check', '--status', {IN=>{'f.md5' => "$degenerate  f\n"}},
                                 {AUX=> {f=> 'foo'}}, {EXIT=> 1}],
      ['check-quiet1', '--check', '--quiet', {AUX=> {f=> ''}},
--
1.7.6.430.g34be2



reply via email to

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