-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
cksum family: Backport new errors for --binary, --text and --tag #10618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,7 +74,10 @@ pub fn standalone_with_length_main( | |
| .transpose()? | ||
| .flatten(); | ||
|
|
||
| let format = OutputFormat::from_standalone(std::env::args_os()); | ||
| //todo: deduplicate matches.get_flag | ||
| let text = !matches.get_flag(options::BINARY); | ||
| let tag = matches.get_flag(options::TAG); | ||
| let format = OutputFormat::from_standalone(text, tag); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm trying to brainstorm to clean this code up and I'm wondering if its better to just pass the matches in the OutputFormat? Then you can also move the error handling validation into there and it will make the code reduce by a bunch |
||
|
|
||
| checksum_main(algo, length, matches, format?) | ||
| } | ||
|
|
@@ -83,8 +86,10 @@ pub fn standalone_with_length_main( | |
| pub fn standalone_main(algo: AlgoKind, cmd: Command, args: impl uucore::Args) -> UResult<()> { | ||
| let matches = uucore::clap_localization::handle_clap_result(cmd, args)?; | ||
| let algo = Some(algo); | ||
|
|
||
| let format = OutputFormat::from_standalone(std::env::args_os()); | ||
| //todo: deduplicate matches.get_flag | ||
| let text = !matches.get_flag(options::BINARY); | ||
| let tag = matches.get_flag(options::TAG); | ||
| let format = OutputFormat::from_standalone(text, tag); | ||
|
|
||
| checksum_main(algo, None, matches, format?) | ||
| } | ||
|
|
@@ -155,24 +160,30 @@ pub fn checksum_main( | |
| let quiet = check_flag("quiet")?; | ||
| let strict = check_flag("strict")?; | ||
| let status = check_flag("status")?; | ||
| let text_flag = matches.get_flag(options::TEXT); | ||
| let binary_flag = matches.get_flag(options::BINARY); | ||
| let tag = matches.get_flag(options::TAG); | ||
|
|
||
| // clap provides the default value -. So we unwrap() safety. | ||
| let files = matches | ||
| .get_many::<OsString>(options::FILE) | ||
| .unwrap() | ||
| .map(Borrow::borrow); | ||
|
|
||
| if text_flag && tag { | ||
| return Err(ChecksumError::TextAfterTag.into()); | ||
| } | ||
|
|
||
| if check { | ||
| // cksum does not support '--check'ing legacy algorithms | ||
| if algo.is_some_and(AlgoKind::is_legacy) { | ||
| return Err(ChecksumError::AlgorithmNotSupportedWithCheck.into()); | ||
| } | ||
|
|
||
| let text_flag = matches.get_flag(options::TEXT); | ||
| let binary_flag = matches.get_flag(options::BINARY); | ||
| let tag = matches.get_flag(options::TAG); | ||
|
|
||
| if tag || binary_flag || text_flag { | ||
| // Maybe, we should just use clap | ||
| if tag { | ||
| return Err(ChecksumError::TagCheck.into()); | ||
| } | ||
| if binary_flag || text_flag { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this check is invalid to have in the checksum_common library since it only applies to cksum and not the other ones like md5sum and sha256sum. When running on the 9.10 version I'm finding that this is valid: |
||
| return Err(ChecksumError::BinaryTextConflict.into()); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -403,6 +403,8 @@ pub enum ChecksumError { | |
| BinaryTextConflict, | ||
| #[error("--text mode is only supported with --untagged")] | ||
| TextWithoutUntagged, | ||
| #[error("the --tag option is meaningless when verifying checksums")] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can be done a different pr but it will need translate!() at some point |
||
| TagCheck, | ||
| #[error("--tag does not support --text mode")] | ||
| TextAfterTag, | ||
| #[error("--check is not supported with --algorithm={{bsd,sysv,crc,crc32b}}")] | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.