Tags 353911 + patch
thanks

Hi,

I just gave this wishlist bug some attention and implemented an
additional option --pedantic, -p which if given additional to the check
command causes md5sum to exit with a non-zero exit code.

Attached is the patch which implements the functionality.
It works with the specified test case:

[EMAIL PROTECTED] .../coreutils-6.10/coreutils-6.10.patched % md5sum test/*|sed 
'1s/./Z/'|>/dev/null src/md5sum -c --warn -p 
src/md5sum: standard input: 1: improperly formatted MD5 checksum line
zsh: done       md5sum test/* | sed '1s/./Z/' | 
zsh: exit 1     src/md5sum -c --warn -p > /dev/null

Please test if is appropriate for your usage.
Maintainer, please consider forwarding the patch upstream for inclusion.

Best Regards,
Patrick
--- coreutils-6.10/src/md5sum.c	2007-11-25 14:23:31.000000000 +0100
+++ coreutils-6.10.patched/src/md5sum.c	2008-11-13 21:12:14.960672077 +0100
@@ -114,6 +114,10 @@
    improperly formatted checksum line.  */
 static bool warn = false;
 
+/* With --check, exit with a non-zero return code, if any line is
+   improperly formatted. */
+static bool pedantic = false;
+
 /* The name this program was run with.  */
 char *program_name;
 
@@ -131,6 +135,7 @@
   { "status", no_argument, NULL, STATUS_OPTION },
   { "text", no_argument, NULL, 't' },
   { "warn", no_argument, NULL, 'w' },
+  { "pedantic", no_argument, NULL, 'p' },
   { GETOPT_HELP_OPTION_DECL },
   { GETOPT_VERSION_OPTION_DECL },
   { NULL, 0, NULL, 0 }
@@ -177,6 +182,8 @@
 The following two options are useful only when verifying checksums:\n\
       --status            don't output anything, status code shows success\n\
   -w, --warn              warn about improperly formatted checksum lines\n\
+  -p, --pedantic          return a non-zero exit code when an improperly\n\
+                          formatted checksum line is found\n\
 \n\
 "), stdout);
       fputs (HELP_OPTION_DESCRIPTION, stdout);
@@ -480,6 +487,10 @@
 		     checkfile_name, line_number,
 		     DIGEST_TYPE_STRING);
 	    }
+	  if (pedantic)
+	    {
+	      return false;
+	    }
 	}
       else
 	{
@@ -603,7 +614,7 @@
 
   atexit (close_stdout);
 
-  while ((opt = getopt_long (argc, argv, "bctw", long_options, NULL)) != -1)
+  while ((opt = getopt_long (argc, argv, "bctwp", long_options, NULL)) != -1)
     switch (opt)
       {
       case 'b':
@@ -623,6 +634,9 @@
 	status_only = false;
 	warn = true;
 	break;
+      case 'p':
+        pedantic = true;
+	break;
       case_GETOPT_HELP_CHAR;
       case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
       default:
@@ -653,6 +667,13 @@
       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;
 

Attachment: signature.asc
Description: Digital signature

Reply via email to