summaryrefslogtreecommitdiff
path: root/src/md5sum.c
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2015-11-23 17:11:26 +0000
committerPádraig Brady <P@draigBrady.com>2015-11-23 18:06:38 +0000
commit6df26278d6cf5c6fad04d3fbaed4c06a223fb0bd (patch)
tree7ba12d8c55aa67520373e668d50d1dfc0a27f27f /src/md5sum.c
parent9fd0662faa4db68dea4fb4ba3f918b6a8f9598c4 (diff)
downloadcoreutils-6df26278d6cf5c6fad04d3fbaed4c06a223fb0bd.tar.xz
md5sum,sha*sum: ensure --ignore-missing fails when no file verified
* src/md5sum.c (digest_check): Update a matched_checksums bool upon matched checksum, and fail (loudly unless --status is specified) if there were no matches. Also change properly_formatted_lines to a bool while at it since we don't need to track the plurality. * tests/misc/md5sum.pl: Add a test case. Suggested by Jim Meyering.
Diffstat (limited to 'src/md5sum.c')
-rw-r--r--src/md5sum.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/md5sum.c b/src/md5sum.c
index 49da8edc4..b7de98ec6 100644
--- a/src/md5sum.c
+++ b/src/md5sum.c
@@ -523,10 +523,11 @@ digest_check (const char *checkfile_name)
{
FILE *checkfile_stream;
uintmax_t n_misformatted_lines = 0;
- 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;
+ bool properly_formatted_lines = false;
+ bool matched_checksums = false;
unsigned char bin_buffer_unaligned[DIGEST_BIN_BYTES + DIGEST_ALIGN];
/* Make sure bin_buffer is properly aligned. */
unsigned char *bin_buffer = ptr_align (bin_buffer_unaligned, DIGEST_ALIGN);
@@ -606,7 +607,7 @@ digest_check (const char *checkfile_name)
to ease automatic processing of status output. */
bool needs_escape = ! status_only && strchr (filename, '\n');
- ++n_properly_formatted_lines;
+ properly_formatted_lines = true;
*bin_buffer = '\1'; /* flag set to 0 for ignored missing files. */
ok = digest_file (filename, &binary, bin_buffer);
@@ -645,6 +646,8 @@ digest_check (const char *checkfile_name)
}
if (cnt != digest_bin_bytes)
++n_mismatched_checksums;
+ else
+ matched_checksums = true;
if (!status_only)
{
@@ -679,7 +682,7 @@ digest_check (const char *checkfile_name)
return false;
}
- if (n_properly_formatted_lines == 0)
+ if (! properly_formatted_lines)
{
/* Warn if no tests are found. */
error (0, 0, _("%s: no properly formatted %s checksum lines found"),
@@ -712,10 +715,15 @@ digest_check (const char *checkfile_name)
"WARNING: %" PRIuMAX " computed checksums did NOT match",
select_plural (n_mismatched_checksums))),
n_mismatched_checksums);
+
+ if (ignore_missing && ! matched_checksums)
+ error (0, 0, _("%s: no file was verified"),
+ quotef (checkfile_name));
}
}
- return (n_properly_formatted_lines != 0
+ return (properly_formatted_lines
+ && matched_checksums
&& n_mismatched_checksums == 0
&& n_open_or_read_failures == 0
&& (!strict || n_improperly_formatted_lines == 0));