Hi,

I just realized that this is still open. Unfortunately
in the meanwhile I lost the git checkout in which I worked
on this, so I had to merge the changes from the borked
patch I sent to the mailing list.

On Sun, Mar 22, 2009 at 03:36:53PM +0100, Jim Meyering wrote:
> >>   http://www.mail-archive.com/bug-coreutils@gnu.org/msg14650.html
> >>
> >> I was waiting for an updated patch, but
> >> as far as I can see, that never reached the list.
> >
> > I think I did. I sent it in an own mail as outlined in one of your 
> > documents:
> >
> > http://lists.gnu.org/archive/html/bug-coreutils/2008-11/msg00107.html
> 
> Ah, yes.  Thanks.
> Different thread.
> 
> If it's no trouble, would you please rebase and re-post it to the
> mailing list as an attachment or using a mail client that doesn't
> mangle patches?  At least two lines have been split, and that renders
> the patch non-applicable.  I could join them manually, but...

The attached patch is rebased against the current master branch
(last commit: bb4cb10e89607437154d84b47b9f93869a9484b7)

Note, that my assignment is active, so it should be okay to
include it, if you accept it from a technical pov.

> Finally, in this block, please correct the inconsistent indentation:
> 
> +  if (pedantic & !do_check)
> +   {
> +      error (0, 0,
> +       _("the --pedantic option is meaningful only when verifying 
> checksums"));
> +     usage (EXIT_FAILURE);
> +   }

I'm not exactly sure what you mean and weither I did it right in the new
version of the patch. Indenting like it is done in coreutils is really
weird with vim IMHO. But with

cinoptions=>4,n-2,{2,^-2,:2,=2,g0,h2,p5,t0,+2,(0,u0,w1,m1
shiftwidth=2
tabstop=8

it at leasts looks right (as in: consistent with the other option
checks) in vim.

> Hmm.. re NEWS, maybe it's not worth it, since adding a new feature,
> even one this small, in a bug-fix-only release (upcoming 7.2) is
> not the best idea.  Since it'll have to go into the to-be-created
> section for 7.3.

I have ommitted the NEWS entry for now. If it should get back,
please clarify whats actually needd.

And please remember that I asked you to write the test case, back
when I wrote the patch originally. The test cases I've tested are
still the same as in my mail as linked above.

Best Regards,
Patrick
>From f8867b9242be82745a5c3868b014498d4f0d65c8 Mon Sep 17 00:00:00 2001
From: Patrick Schoenfeld <patrick.schoenf...@credativ.de>
Date: Thu, 10 Dec 2009 15:00:38 +0100
Subject: [PATCH] md5sum: Implemented --pedantic option

* 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)
---
 doc/coreutils.texi |    6 ++++++
 src/md5sum.c       |   32 +++++++++++++++++++++++++++++++-
 2 files changed, 37 insertions(+), 1 deletions(-)

diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 3721bee..a047dff 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -3487,6 +3487,12 @@ checked file.  Files that fail the verification are reported in the
 default one-line-per-file format.  If there is any checksum mismatch,
 print a warning summarizing the failures to standard error.
 
+...@itemx --pedantic
+...@opindex --pedantic
+...@cindex verifying MD5 checksums
+When verifying checksums, fail if one or more improperly formatted MD5 checksum
+line is found.
+
 @itemx --status
 @opindex --status
 @cindex verifying MD5 checksums
diff --git a/src/md5sum.c b/src/md5sum.c
index b7db03e..7fc6def 100644
--- a/src/md5sum.c
+++ b/src/md5sum.c
@@ -121,12 +121,17 @@ 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
+ * improperly formatted. */
+static bool pedantic;
+
 /* For long options that have no equivalent short option, use a
    non-character as a pseudo short option, starting with CHAR_MAX + 1.  */
 enum
 {
   STATUS_OPTION = CHAR_MAX + 1,
-  QUIET_OPTION
+  QUIET_OPTION,
+  PEDANTIC_OPTION
 };
 
 static struct option const long_options[] =
@@ -137,6 +142,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 },
   { GETOPT_HELP_OPTION_DECL },
   { GETOPT_VERSION_OPTION_DECL },
   { NULL, 0, NULL, 0 }
@@ -184,6 +190,8 @@ The following three options are useful only when verifying checksums:\n\
       --quiet             don't print OK for each successfully verified file\n\
       --status            don't output anything, status code shows success\n\
   -w, --warn              warn about improperly formatted checksum lines\n\
+      --pedantic          return a non-zero exit code if one or more improperly\n\
+                          formatted checksume line is found\n\
 \n\
 "), stdout);
       fputs (HELP_OPTION_DESCRIPTION, stdout);
@@ -429,6 +437,7 @@ digest_check (const char *checkfile_name)
 {
   FILE *checkfile_stream;
   uintmax_t n_properly_formatted_lines = 0;
+  uintmax_t n_improperly_formatted_lines = 0;
   uintmax_t n_mismatched_checksums = 0;
   uintmax_t n_open_or_read_failures = 0;
   unsigned char bin_buffer_unaligned[DIGEST_BIN_BYTES + DIGEST_ALIGN];
@@ -494,6 +503,7 @@ digest_check (const char *checkfile_name)
                      checkfile_name, line_number,
                      DIGEST_TYPE_STRING);
             }
+          ++n_improperly_formatted_lines;
         }
       else
         {
@@ -590,6 +600,16 @@ digest_check (const char *checkfile_name)
                      n_mismatched_checksums, n_computed_checksums);
             }
         }
+
+    if (n_improperly_formatted_lines != 0)
+      {
+        if (pedantic)
+          {
+            /* Bail out of if more then one improperly formatted line is found
+             * and pedantic option is set */
+            exit (EXIT_FAILURE);
+          }
+      }
     }
 
   return (n_properly_formatted_lines != 0
@@ -648,6 +668,9 @@ main (int argc, char **argv)
         warn = false;
         quiet = true;
         break;
+      case PEDANTIC_OPTION:
+        pedantic = true;
+        break;
       case_GETOPT_HELP_CHAR;
       case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
       default:
@@ -685,6 +708,13 @@ main (int argc, char **argv)
       usage (EXIT_FAILURE);
     }
 
+  if (pedantic && !do_check)
+    {
+      error(0, 0,
+       _("the --pedantic option is meaningful only when verifying checksums"));
+      usage (EXIT_FAILURE);
+    }
+
   if (!O_BINARY && binary < 0)
     binary = 0;
 
-- 
1.6.5.4

Reply via email to