Skip to content

Commit 5129aba

Browse files
authored
Merge pull request #7192 from RenjiSann/cksum-fix-error-handling
cksum: Update error and flags handling to improver GNU's match
2 parents 6c8ec89 + 84bbd05 commit 5129aba

File tree

4 files changed

+545
-91
lines changed

4 files changed

+545
-91
lines changed

src/uu/cksum/src/cksum.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ use std::iter;
1313
use std::path::Path;
1414
use uucore::checksum::{
1515
calculate_blake2b_length, detect_algo, digest_reader, perform_checksum_validation,
16-
ChecksumError, ChecksumOptions, ALGORITHM_OPTIONS_BLAKE2B, ALGORITHM_OPTIONS_BSD,
17-
ALGORITHM_OPTIONS_CRC, ALGORITHM_OPTIONS_CRC32B, ALGORITHM_OPTIONS_SYSV, SUPPORTED_ALGORITHMS,
16+
ChecksumError, ChecksumOptions, ChecksumVerbose, ALGORITHM_OPTIONS_BLAKE2B,
17+
ALGORITHM_OPTIONS_BSD, ALGORITHM_OPTIONS_CRC, ALGORITHM_OPTIONS_CRC32B, ALGORITHM_OPTIONS_SYSV,
18+
SUPPORTED_ALGORITHMS,
1819
};
1920
use uucore::{
2021
encoding,
@@ -322,13 +323,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
322323
|| iter::once(OsStr::new("-")).collect::<Vec<_>>(),
323324
|files| files.map(OsStr::new).collect::<Vec<_>>(),
324325
);
326+
327+
let verbose = ChecksumVerbose::new(status, quiet, warn);
328+
325329
let opts = ChecksumOptions {
326330
binary: binary_flag,
327331
ignore_missing,
328-
quiet,
329-
status,
330332
strict,
331-
warn,
333+
verbose,
332334
};
333335

334336
return perform_checksum_validation(files.iter().copied(), algo_option, length, opts);
@@ -462,19 +464,22 @@ pub fn uu_app() -> Command {
462464
.short('w')
463465
.long("warn")
464466
.help("warn about improperly formatted checksum lines")
465-
.action(ArgAction::SetTrue),
467+
.action(ArgAction::SetTrue)
468+
.overrides_with_all([options::STATUS, options::QUIET]),
466469
)
467470
.arg(
468471
Arg::new(options::STATUS)
469472
.long("status")
470473
.help("don't output anything, status code shows success")
471-
.action(ArgAction::SetTrue),
474+
.action(ArgAction::SetTrue)
475+
.overrides_with_all([options::WARN, options::QUIET]),
472476
)
473477
.arg(
474478
Arg::new(options::QUIET)
475479
.long(options::QUIET)
476480
.help("don't print OK for each successfully verified file")
477-
.action(ArgAction::SetTrue),
481+
.action(ArgAction::SetTrue)
482+
.overrides_with_all([options::WARN, options::STATUS]),
478483
)
479484
.arg(
480485
Arg::new(options::IGNORE_MISSING)

src/uu/hashsum/src/hashsum.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use uucore::checksum::escape_filename;
2424
use uucore::checksum::perform_checksum_validation;
2525
use uucore::checksum::ChecksumError;
2626
use uucore::checksum::ChecksumOptions;
27+
use uucore::checksum::ChecksumVerbose;
2728
use uucore::checksum::HashAlgorithm;
2829
use uucore::error::{FromIo, UResult};
2930
use uucore::sum::{Digest, Sha3_224, Sha3_256, Sha3_384, Sha3_512, Shake128, Shake256};
@@ -240,13 +241,14 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
240241
|| iter::once(OsStr::new("-")).collect::<Vec<_>>(),
241242
|files| files.map(OsStr::new).collect::<Vec<_>>(),
242243
);
244+
245+
let verbose = ChecksumVerbose::new(status, quiet, warn);
246+
243247
let opts = ChecksumOptions {
244248
binary,
245249
ignore_missing,
246-
quiet,
247-
status,
248250
strict,
249-
warn,
251+
verbose,
250252
};
251253

252254
// Execute the checksum validation
@@ -356,14 +358,16 @@ pub fn uu_app_common() -> Command {
356358
.short('q')
357359
.long(options::QUIET)
358360
.help("don't print OK for each successfully verified file")
359-
.action(ArgAction::SetTrue),
361+
.action(ArgAction::SetTrue)
362+
.overrides_with_all([options::STATUS, options::WARN]),
360363
)
361364
.arg(
362365
Arg::new(options::STATUS)
363366
.short('s')
364367
.long("status")
365368
.help("don't output anything, status code shows success")
366-
.action(ArgAction::SetTrue),
369+
.action(ArgAction::SetTrue)
370+
.overrides_with_all([options::QUIET, options::WARN]),
367371
)
368372
.arg(
369373
Arg::new(options::STRICT)
@@ -382,7 +386,8 @@ pub fn uu_app_common() -> Command {
382386
.short('w')
383387
.long("warn")
384388
.help("warn about improperly formatted checksum lines")
385-
.action(ArgAction::SetTrue),
389+
.action(ArgAction::SetTrue)
390+
.overrides_with_all([options::QUIET, options::STATUS]),
386391
)
387392
.arg(
388393
Arg::new("zero")

0 commit comments

Comments
 (0)