mirror of
https://github.com/uutils/coreutils
synced 2024-10-15 12:24:09 +00:00
Merge pull request #6524 from sylvestre/cksum-3
cksum: read the next file when the first is missing or invalid
This commit is contained in:
commit
a18c132994
|
@ -473,16 +473,26 @@ where
|
||||||
// Use stdin if "-" is specified
|
// Use stdin if "-" is specified
|
||||||
Box::new(stdin())
|
Box::new(stdin())
|
||||||
} else {
|
} else {
|
||||||
get_input_file(filename_input)?
|
match get_input_file(filename_input) {
|
||||||
|
Ok(f) => f,
|
||||||
|
Err(e) => {
|
||||||
|
// Could not read the file, show the error and continue to the next file
|
||||||
|
show_error!("{e}");
|
||||||
|
set_exit_code(1);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let reader = BufReader::new(file);
|
let reader = BufReader::new(file);
|
||||||
let lines: Vec<String> = reader.lines().collect::<Result<_, _>>()?;
|
let lines: Vec<String> = reader.lines().collect::<Result<_, _>>()?;
|
||||||
let Some((chosen_regex, is_algo_based_format)) = determine_regex(&lines) else {
|
let Some((chosen_regex, is_algo_based_format)) = determine_regex(&lines) else {
|
||||||
return Err(ChecksumError::NoProperlyFormattedChecksumLinesFound {
|
let e = ChecksumError::NoProperlyFormattedChecksumLinesFound {
|
||||||
filename: get_filename_for_output(filename_input, input_is_stdin),
|
filename: get_filename_for_output(filename_input, input_is_stdin),
|
||||||
}
|
};
|
||||||
.into());
|
show_error!("{e}");
|
||||||
|
set_exit_code(1);
|
||||||
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
for (i, line) in lines.iter().enumerate() {
|
for (i, line) in lines.iter().enumerate() {
|
||||||
|
@ -624,6 +634,7 @@ where
|
||||||
// if any incorrectly formatted line, show it
|
// if any incorrectly formatted line, show it
|
||||||
cksum_output(&res, ignore_missing, status);
|
cksum_output(&res, ignore_missing, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
//
|
//
|
||||||
// For the full copyright and license information, please view the LICENSE
|
// For the full copyright and license information, please view the LICENSE
|
||||||
// file that was distributed with this source code.
|
// file that was distributed with this source code.
|
||||||
// spell-checker:ignore (words) asdf algo algos
|
// spell-checker:ignore (words) asdf algo algos mgmt
|
||||||
|
|
||||||
use crate::common::util::TestScenario;
|
use crate::common::util::TestScenario;
|
||||||
|
|
||||||
|
@ -1221,3 +1221,32 @@ fn test_check_base64_hashes() {
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_is("empty: OK\nempty: OK\nempty: OK\n");
|
.stdout_is("empty: OK\nempty: OK\nempty: OK\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_several_files_error_mgmt() {
|
||||||
|
let scene = TestScenario::new(util_name!());
|
||||||
|
let at = &scene.fixtures;
|
||||||
|
|
||||||
|
// don't exist
|
||||||
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.arg("--check")
|
||||||
|
.arg("empty")
|
||||||
|
.arg("incorrect")
|
||||||
|
.fails()
|
||||||
|
.stderr_contains("empty: No such file ")
|
||||||
|
.stderr_contains("incorrect: No such file ");
|
||||||
|
|
||||||
|
at.touch("empty");
|
||||||
|
at.touch("incorrect");
|
||||||
|
|
||||||
|
// exists but incorrect
|
||||||
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.arg("--check")
|
||||||
|
.arg("empty")
|
||||||
|
.arg("incorrect")
|
||||||
|
.fails()
|
||||||
|
.stderr_contains("empty: no properly ")
|
||||||
|
.stderr_contains("incorrect: no properly ");
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue