[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bug#353911: md5sum --check checks only if _all_ are bad
From: |
Jim Meyering |
Subject: |
Re: Bug#353911: md5sum --check checks only if _all_ are bad |
Date: |
Fri, 14 Nov 2008 21:09:09 +0100 |
Patrick Schoenfeld <address@hidden> wrote:
> 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:
>
> address@hidden .../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.
Thanks for the suggestion/patch.
This looks reasonable and useful.
If you're serious about it, and can sign a copyright assignment,
please look through the coreutils contribution/style guidelines
http://git.sv.gnu.org/gitweb/?p=coreutils.git;a=blob;f=HACKING;hb=HEAD
and make the following changes/additions:
- see if some other md5/md5sum program has a similar option
- follow instructions in HACKING regarding copyright assignment
start this right away, since it'll take at least two weeks
- make your changes relative to the latest in git (see HACKING)
- add a NEWS entry
- update doc/coreutils.texi
- remove the -p short option
- add at least these test cases: (see tests/misc/md5sum)
- demonstrate --check --pedantic succeeding
- demonstrate --check --pedantic failing due to invalid first line
(ensure it still processes following ones -- should it warn
about each? or just the first?)
- demonstrate --check --pedantic failing with 1 invalid checksum
- demonstrate --check --pedantic failing with 1 valid checksum
If adding tests looks too daunting, don't worry about it,
(but let me know) and someone else will handle it.
Then ensure that "make check" and "make syntax-check" still succeed,
and post (per HACKING) your patch to address@hidden
> --- 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;
>
- Re: Bug#353911: md5sum --check checks only if _all_ are bad,
Jim Meyering <=
Re: Bug#353911: md5sum --check checks only if _all_ are bad, Patrick Schoenfeld, 2008/11/17