Skip to content

Commit eecf07e

Browse files
oech3oech3
authored andcommitted
cksum: Remove Some
1 parent 23f1a1e commit eecf07e

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/uu/cksum/src/cksum.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,18 @@ fn handle_tag_text_binary_flags<S: AsRef<OsStr>>(
111111
}
112112

113113
/// Sanitize the `--length` argument depending on `--algorithm` and `--length`.
114-
fn maybe_sanitize_length(
115-
algo_cli: Option<AlgoKind>,
116-
input_length: Option<&str>,
117-
) -> UResult<Option<usize>> {
114+
fn maybe_sanitize_length(algo_cli: AlgoKind, input_length: Option<&str>) -> UResult<Option<usize>> {
118115
match (algo_cli, input_length) {
119116
// No provided length is not a problem so far.
120117
(_, None) => Ok(None),
121118

122119
// For SHA2 and SHA3, if a length is provided, ensure it is correct.
123-
(Some(algo @ (AlgoKind::Sha2 | AlgoKind::Sha3)), Some(s_len)) => {
120+
(algo @ (AlgoKind::Sha2 | AlgoKind::Sha3), Some(s_len)) => {
124121
sanitize_sha2_sha3_length_str(algo, s_len).map(Some)
125122
}
126123

127124
// For BLAKE2b, if a length is provided, validate it.
128-
(Some(AlgoKind::Blake2b), Some(len)) => calculate_blake2b_length_str(len),
125+
(AlgoKind::Blake2b, Some(len)) => calculate_blake2b_length_str(len),
129126

130127
// For any other provided algorithm, check if length is 0.
131128
// Otherwise, this is an error.
@@ -157,7 +154,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
157154
let algo_cli = matches
158155
.get_one::<String>(options::ALGORITHM)
159156
.map(AlgoKind::from_cksum)
160-
.transpose()?;
157+
.transpose()?
158+
.unwrap_or(AlgoKind::Crc);
161159

162160
let input_length = matches
163161
.get_one::<String>(options::LENGTH)
@@ -174,7 +172,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
174172

175173
if check {
176174
// cksum does not support '--check'ing legacy algorithms
177-
if algo_cli.is_some_and(AlgoKind::is_legacy) {
175+
let algo_specified = matches.contains_id(options::ALGORITHM);
176+
if algo_cli.is_legacy() && algo_specified {
178177
return Err(ChecksumError::AlgorithmNotSupportedWithCheck.into());
179178
}
180179

@@ -195,7 +194,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
195194
verbose,
196195
};
197196

198-
return perform_checksum_validation(files, algo_cli, length, opts);
197+
if algo_specified {
198+
return perform_checksum_validation(files, Some(algo_cli), length, opts);
199+
}
200+
return perform_checksum_validation(files, None, length, opts);
199201
}
200202

201203
// Not --check
@@ -206,11 +208,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
206208
}
207209

208210
// Set the default algorithm to CRC when not '--check'ing.
209-
let algo_kind = algo_cli.unwrap_or(AlgoKind::Crc);
210-
211211
let (tag, binary) = handle_tag_text_binary_flags(std::env::args_os())?;
212212

213-
let algo = SizedAlgoKind::from_unsized(algo_kind, length)?;
213+
let algo = SizedAlgoKind::from_unsized(algo_cli, length)?;
214214
let line_ending = LineEnding::from_zero_flag(matches.get_flag(options::ZERO));
215215

216216
let opts = ChecksumComputeOptions {

0 commit comments

Comments
 (0)