Normally, when I use md5sum, it's when I download a file and an MD5SUMS file that comes with it. This MD5SUMS file usually lists many files including the one I downloaded. When I run 'md5sum -c MD5SUMS', I get many error messages about files that I don't have. Obviously, I don't care about the files I didn't download, and the error messages make it difficult to see the output relating to the file that I do care about.
I suggest a new option, -i/--ignore-missing, which ignores any filenames that do not exist on the filesystem. In my patch, the option simply suppresses both relevant error messages. Another approach might be to have digest_check check to see if the file exists. If it doesn't, don't call digest_file or print the 'FAILED' message. Sorry if my patch is a little messy, being in 3 parts. I'm not used to using git. HTH, and let me know what you think... Luther -- Please do not send me Microsoft Office/Apple iWork documents. Send OpenDocument instead! http://fsf.org/campaigns/opendocument/
>From 55c1749bed8092d27fdd3938b220e9c22425871f Mon Sep 17 00:00:00 2001 From: Luther Thompson <[email protected]> Date: Wed, 8 Dec 2010 19:56:32 -0500 Subject: [PATCH 1/3] md5sum: Added option '--ignore-missing' With '--check', suppresses error messages for nonexistant files. * src/md5sum.c (ignore_missing, long_options, usage, main): Add option -i/--ignore-missing. (digest_file): If fopen fails, ignore_missing suppresses the error message. (digest_check): ignore_missing suppresses the 'FAILED' message. --- src/md5sum.c | 24 ++++++++++++++++++++---- 1 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/md5sum.c b/src/md5sum.c index a660e3b..9635692 100644 --- a/src/md5sum.c +++ b/src/md5sum.c @@ -122,6 +122,9 @@ static bool warn = false; /* With --check, suppress the "OK" printed for each verified file. */ static bool quiet = false; +/* With --check, suppress the error message for each non-existant file. */ +static bool ignore_missing = false; + /* For long options that have no equivalent short option, use a non-character as a pseudo short option, starting with CHAR_MAX + 1. */ enum @@ -138,6 +141,7 @@ static struct option const long_options[] = { "status", no_argument, NULL, STATUS_OPTION }, { "text", no_argument, NULL, 't' }, { "warn", no_argument, NULL, 'w' }, + { "ignore-missing", no_argument, NULL, 'i' }, { GETOPT_HELP_OPTION_DECL }, { GETOPT_VERSION_OPTION_DECL }, { NULL, 0, NULL, 0 } @@ -181,10 +185,11 @@ With no FILE, or when FILE is -, read standard input.\n\ "), stdout); fputs (_("\ \n\ -The following three options are useful only when verifying checksums:\n\ +The following four 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\ + -i, --ignore-missing don't report errors for missing files\n\ \n\ "), stdout); fputs (HELP_OPTION_DESCRIPTION, stdout); @@ -402,7 +407,8 @@ digest_file (const char *filename, int *binary, unsigned char *bin_result) fp = fopen (filename, (O_BINARY && *binary ? "rb" : "r")); if (fp == NULL) { - error (0, errno, "%s", filename); + if (!ignore_missing) + error (0, errno, "%s", filename); return false; } } @@ -516,7 +522,7 @@ digest_check (const char *checkfile_name) if (!ok) { ++n_open_or_read_failures; - if (!status_only) + if (!status_only && !ignore_missing) { printf (_("%s: FAILED open or read\n"), filename); } @@ -626,7 +632,7 @@ main (int argc, char **argv) so that processes running in parallel do not intersperse their output. */ setvbuf (stdout, NULL, _IOLBF, 0); - while ((opt = getopt_long (argc, argv, "bctw", long_options, NULL)) != -1) + while ((opt = getopt_long (argc, argv, "bcitw", long_options, NULL)) != -1) switch (opt) { case 'b': @@ -653,6 +659,9 @@ main (int argc, char **argv) warn = false; quiet = true; break; + case 'i': + ignore_missing = true; + break; case_GETOPT_HELP_CHAR; case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS); default: @@ -690,6 +699,13 @@ main (int argc, char **argv) usage (EXIT_FAILURE); } + if (ignore_missing && !do_check) + { + error (0, 0, + _("the --ignore-missing option is meaningful only when verifying checksums")); + usage (EXIT_FAILURE); + } + if (!O_BINARY && binary < 0) binary = 0; -- 1.7.0.4
>From dc430aa13d76b67937860c538c52854663c2ebf4 Mon Sep 17 00:00:00 2001 From: Luther Thompson <[email protected]> Date: Wed, 8 Dec 2010 20:56:48 -0500 Subject: [PATCH 2/3] src/md5sum: Change tabs to spaces. --- src/md5sum.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/md5sum.c b/src/md5sum.c index 9635692..b2f345f 100644 --- a/src/md5sum.c +++ b/src/md5sum.c @@ -407,8 +407,8 @@ digest_file (const char *filename, int *binary, unsigned char *bin_result) fp = fopen (filename, (O_BINARY && *binary ? "rb" : "r")); if (fp == NULL) { - if (!ignore_missing) - error (0, errno, "%s", filename); + if (!ignore_missing) + error (0, errno, "%s", filename); return false; } } @@ -660,8 +660,8 @@ main (int argc, char **argv) quiet = true; break; case 'i': - ignore_missing = true; - break; + ignore_missing = true; + break; case_GETOPT_HELP_CHAR; case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS); default: -- 1.7.0.4
>From 688e5e1231ea917e006613bc89f9cf750e05d4ec Mon Sep 17 00:00:00 2001 From: Luther Thompson <[email protected]> Date: Wed, 8 Dec 2010 21:29:00 -0500 Subject: [PATCH 3/3] * doc/coreutils.texi: Document md5sum -i. --- doc/coreutils.texi | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-) diff --git a/doc/coreutils.texi b/doc/coreutils.texi index 34d9ff0..b893898 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -3531,6 +3531,14 @@ an MD5 checksum inconsistent with the associated file, or if no valid line is found, @command{md5sum} exits with nonzero status. Otherwise, it exits successfully. +...@item -i +...@itemx --ignore-missing +...@cindex verifying MD5 checksums +This option is useful only when verifying checksums. +When verifying checksums, don't generate a 'No such file or directory' or +'FAILED open or read' message for any file listed in the input but which is not +present on the filesystem. + @itemx --quiet @opindex --quiet @cindex verifying MD5 checksums -- 1.7.0.4
