mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #6782 from RenjiSann/checksum-comment
cksum/hashsum: Support for commented lines in checksum files
This commit is contained in:
commit
92e67a5a14
3 changed files with 137 additions and 2 deletions
|
@ -575,8 +575,8 @@ where
|
||||||
res.failed_cksum += 1;
|
res.failed_cksum += 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if line.is_empty() {
|
if line.is_empty() || line.starts_with("#") {
|
||||||
// Don't show any warning for empty lines
|
// Don't show any warning for empty or commented lines.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if warn {
|
if warn {
|
||||||
|
|
|
@ -1277,3 +1277,70 @@ fn test_non_utf8_filename() {
|
||||||
.stdout_is_bytes(b"SHA256 (funky\xffname) = e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\n")
|
.stdout_is_bytes(b"SHA256 (funky\xffname) = e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\n")
|
||||||
.no_stderr();
|
.no_stderr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_check_comment_line() {
|
||||||
|
// A comment in a checksum file shall be discarded unnoticed.
|
||||||
|
|
||||||
|
let scene = TestScenario::new(util_name!());
|
||||||
|
let at = &scene.fixtures;
|
||||||
|
|
||||||
|
at.write("foo", "foo-content\n");
|
||||||
|
at.write(
|
||||||
|
"CHECKSUM-sha1",
|
||||||
|
"\
|
||||||
|
# This is a comment\n\
|
||||||
|
SHA1 (foo) = 058ab38dd3603703b3a7063cf95dc51a4286b6fe\n\
|
||||||
|
# next comment is empty\n#",
|
||||||
|
);
|
||||||
|
|
||||||
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.arg("--check")
|
||||||
|
.arg("CHECKSUM-sha1")
|
||||||
|
.succeeds()
|
||||||
|
.stdout_contains("foo: OK")
|
||||||
|
.no_stderr();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_check_comment_only() {
|
||||||
|
// A file only filled with comments is equivalent to an empty file,
|
||||||
|
// and therefore produces an error.
|
||||||
|
|
||||||
|
let scene = TestScenario::new(util_name!());
|
||||||
|
let at = &scene.fixtures;
|
||||||
|
|
||||||
|
at.write("CHECKSUM", "# This is a comment\n");
|
||||||
|
|
||||||
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.arg("--check")
|
||||||
|
.arg("CHECKSUM")
|
||||||
|
.fails()
|
||||||
|
.stderr_contains("no properly formatted checksum lines found");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_check_comment_leading_space() {
|
||||||
|
// A comment must have its '#' in first position on the line.
|
||||||
|
// A space before it will raise a warning for improperly formatted line.
|
||||||
|
|
||||||
|
let scene = TestScenario::new(util_name!());
|
||||||
|
let at = &scene.fixtures;
|
||||||
|
|
||||||
|
at.write("foo", "foo-content\n");
|
||||||
|
at.write(
|
||||||
|
"CHECKSUM-sha1",
|
||||||
|
" # This is a comment\n\
|
||||||
|
SHA1 (foo) = 058ab38dd3603703b3a7063cf95dc51a4286b6fe\n",
|
||||||
|
);
|
||||||
|
|
||||||
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.arg("--check")
|
||||||
|
.arg("CHECKSUM-sha1")
|
||||||
|
.succeeds()
|
||||||
|
.stdout_contains("foo: OK")
|
||||||
|
.stderr_contains("WARNING: 1 line is improperly formatted");
|
||||||
|
}
|
||||||
|
|
|
@ -939,3 +939,71 @@ fn test_check_b2sum_strict_check() {
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_only(&output);
|
.stdout_only(&output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_check_md5_comment_line() {
|
||||||
|
// A comment in a checksum file shall be discarded unnoticed.
|
||||||
|
|
||||||
|
let scene = TestScenario::new(util_name!());
|
||||||
|
let at = &scene.fixtures;
|
||||||
|
|
||||||
|
at.write("foo", "foo-content\n");
|
||||||
|
at.write(
|
||||||
|
"MD5SUM",
|
||||||
|
"\
|
||||||
|
# This is a comment\n\
|
||||||
|
8411029f3f5b781026a93db636aca721 foo\n\
|
||||||
|
# next comment is empty\n#",
|
||||||
|
);
|
||||||
|
|
||||||
|
scene
|
||||||
|
.ccmd("md5sum")
|
||||||
|
.arg("--check")
|
||||||
|
.arg("MD5SUM")
|
||||||
|
.succeeds()
|
||||||
|
.stdout_contains("foo: OK")
|
||||||
|
.no_stderr();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_check_md5_comment_only() {
|
||||||
|
// A file only filled with comments is equivalent to an empty file,
|
||||||
|
// and therefore produces an error.
|
||||||
|
|
||||||
|
let scene = TestScenario::new(util_name!());
|
||||||
|
let at = &scene.fixtures;
|
||||||
|
|
||||||
|
at.write("foo", "foo-content\n");
|
||||||
|
at.write("MD5SUM", "# This is a comment\n");
|
||||||
|
|
||||||
|
scene
|
||||||
|
.ccmd("md5sum")
|
||||||
|
.arg("--check")
|
||||||
|
.arg("MD5SUM")
|
||||||
|
.fails()
|
||||||
|
.stderr_contains("no properly formatted checksum lines found");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_check_md5_comment_leading_space() {
|
||||||
|
// A file only filled with comments is equivalent to an empty file,
|
||||||
|
// and therefore produces an error.
|
||||||
|
|
||||||
|
let scene = TestScenario::new(util_name!());
|
||||||
|
let at = &scene.fixtures;
|
||||||
|
|
||||||
|
at.write("foo", "foo-content\n");
|
||||||
|
at.write(
|
||||||
|
"MD5SUM",
|
||||||
|
" # This is a comment\n\
|
||||||
|
8411029f3f5b781026a93db636aca721 foo\n",
|
||||||
|
);
|
||||||
|
|
||||||
|
scene
|
||||||
|
.ccmd("md5sum")
|
||||||
|
.arg("--check")
|
||||||
|
.arg("MD5SUM")
|
||||||
|
.succeeds()
|
||||||
|
.stdout_contains("foo: OK")
|
||||||
|
.stderr_contains("WARNING: 1 line is improperly formatted");
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue