mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
hashsum: Implement the quiet mode
This commit is contained in:
parent
89b7a1a8fb
commit
6acc8e695f
4 changed files with 48 additions and 5 deletions
|
@ -182,6 +182,7 @@ mod options {
|
||||||
pub const STATUS: &str = "status";
|
pub const STATUS: &str = "status";
|
||||||
pub const WARN: &str = "warn";
|
pub const WARN: &str = "warn";
|
||||||
pub const IGNORE_MISSING: &str = "ignore-missing";
|
pub const IGNORE_MISSING: &str = "ignore-missing";
|
||||||
|
pub const QUIET: &str = "quiet";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determines whether to prompt an asterisk (*) in the output.
|
/// Determines whether to prompt an asterisk (*) in the output.
|
||||||
|
@ -282,7 +283,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
let strict = matches.get_flag(options::STRICT);
|
let strict = matches.get_flag(options::STRICT);
|
||||||
let status = matches.get_flag(options::STATUS);
|
let status = matches.get_flag(options::STATUS);
|
||||||
let warn = matches.get_flag(options::WARN);
|
let warn = matches.get_flag(options::WARN);
|
||||||
let ignore_missing = matches.get_flag(options::IGNORE_MISSING);
|
let ignore_missing: bool = matches.get_flag(options::IGNORE_MISSING);
|
||||||
|
let quiet: bool = matches.get_flag(options::QUIET);
|
||||||
|
|
||||||
if (binary_flag || text_flag) && check {
|
if (binary_flag || text_flag) && check {
|
||||||
return Err(ChecksumError::BinaryTextConflict.into());
|
return Err(ChecksumError::BinaryTextConflict.into());
|
||||||
|
@ -307,6 +309,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
warn,
|
warn,
|
||||||
binary_flag,
|
binary_flag,
|
||||||
ignore_missing,
|
ignore_missing,
|
||||||
|
quiet,
|
||||||
algo_option,
|
algo_option,
|
||||||
length,
|
length,
|
||||||
);
|
);
|
||||||
|
@ -447,6 +450,13 @@ pub fn uu_app() -> Command {
|
||||||
.help("don't output anything, status code shows success")
|
.help("don't output anything, status code shows success")
|
||||||
.action(ArgAction::SetTrue),
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new(options::QUIET)
|
||||||
|
.short('q')
|
||||||
|
.long(options::QUIET)
|
||||||
|
.help("don't print OK for each successfully verified file")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::IGNORE_MISSING)
|
Arg::new(options::IGNORE_MISSING)
|
||||||
.long(options::IGNORE_MISSING)
|
.long(options::IGNORE_MISSING)
|
||||||
|
|
|
@ -220,7 +220,7 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
|
||||||
.unwrap_or(None)
|
.unwrap_or(None)
|
||||||
.unwrap_or(&false);
|
.unwrap_or(&false);
|
||||||
let status = matches.get_flag("status");
|
let status = matches.get_flag("status");
|
||||||
//let quiet = matches.get_flag("quiet") || status;
|
let quiet = matches.get_flag("quiet") || status;
|
||||||
//let strict = matches.get_flag("strict");
|
//let strict = matches.get_flag("strict");
|
||||||
let warn = matches.get_flag("warn") && !status;
|
let warn = matches.get_flag("warn") && !status;
|
||||||
let zero: bool = matches.get_flag("zero");
|
let zero: bool = matches.get_flag("zero");
|
||||||
|
@ -277,6 +277,7 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
|
||||||
warn,
|
warn,
|
||||||
binary_flag,
|
binary_flag,
|
||||||
ignore_missing,
|
ignore_missing,
|
||||||
|
quiet,
|
||||||
algo_option,
|
algo_option,
|
||||||
Some(algo.bits),
|
Some(algo.bits),
|
||||||
);
|
);
|
||||||
|
@ -303,6 +304,7 @@ mod options {
|
||||||
pub const BINARY: &str = "binary";
|
pub const BINARY: &str = "binary";
|
||||||
pub const STATUS: &str = "status";
|
pub const STATUS: &str = "status";
|
||||||
pub const WARN: &str = "warn";
|
pub const WARN: &str = "warn";
|
||||||
|
pub const QUIET: &str = "quiet";
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uu_app_common() -> Command {
|
pub fn uu_app_common() -> Command {
|
||||||
|
@ -351,9 +353,9 @@ pub fn uu_app_common() -> Command {
|
||||||
.action(ArgAction::SetTrue),
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("quiet")
|
Arg::new(options::QUIET)
|
||||||
.short('q')
|
.short('q')
|
||||||
.long("quiet")
|
.long(options::QUIET)
|
||||||
.help("don't print OK for each successfully verified file")
|
.help("don't print OK for each successfully verified file")
|
||||||
.action(ArgAction::SetTrue),
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
|
|
|
@ -310,6 +310,7 @@ pub fn perform_checksum_validation<'a, I>(
|
||||||
warn: bool,
|
warn: bool,
|
||||||
binary: bool,
|
binary: bool,
|
||||||
ignore_missing: bool,
|
ignore_missing: bool,
|
||||||
|
quiet: bool,
|
||||||
algo_name_input: Option<&str>,
|
algo_name_input: Option<&str>,
|
||||||
length_input: Option<usize>,
|
length_input: Option<usize>,
|
||||||
) -> UResult<()>
|
) -> UResult<()>
|
||||||
|
@ -471,7 +472,9 @@ where
|
||||||
|
|
||||||
// Do the checksum validation
|
// Do the checksum validation
|
||||||
if expected_checksum == calculated_checksum {
|
if expected_checksum == calculated_checksum {
|
||||||
|
if !quiet {
|
||||||
println!("{prefix}{filename_to_check}: OK");
|
println!("{prefix}{filename_to_check}: OK");
|
||||||
|
}
|
||||||
correct_format += 1;
|
correct_format += 1;
|
||||||
} else {
|
} else {
|
||||||
if !status {
|
if !status {
|
||||||
|
|
|
@ -729,3 +729,31 @@ fn test_check_directory_error() {
|
||||||
.fails()
|
.fails()
|
||||||
.stderr_contains("md5sum: d: Is a directory\n");
|
.stderr_contains("md5sum: d: Is a directory\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_check_quiet() {
|
||||||
|
let scene = TestScenario::new(util_name!());
|
||||||
|
let at = &scene.fixtures;
|
||||||
|
|
||||||
|
at.touch("f");
|
||||||
|
at.write("in.md5", "d41d8cd98f00b204e9800998ecf8427e f\n");
|
||||||
|
scene
|
||||||
|
.ccmd("md5sum")
|
||||||
|
.arg("--quiet")
|
||||||
|
.arg("--check")
|
||||||
|
.arg(at.subdir.join("in.md5"))
|
||||||
|
.succeeds()
|
||||||
|
.stderr_is("")
|
||||||
|
.stdout_is("");
|
||||||
|
|
||||||
|
// incorrect md5
|
||||||
|
at.write("in.md5", "d41d8cd98f00b204e9800998ecf8427f f\n");
|
||||||
|
scene
|
||||||
|
.ccmd("md5sum")
|
||||||
|
.arg("--quiet")
|
||||||
|
.arg("--check")
|
||||||
|
.arg(at.subdir.join("in.md5"))
|
||||||
|
.fails()
|
||||||
|
.stdout_contains("f: FAILED")
|
||||||
|
.stderr_contains("WARNING: 1 computed checksum did NOT match");
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue