mcookie: generate cookie even if specified file doesn't exist (#285)

* mcookie: don't quit if specified file doesn't exist

* mcookie: add test

* minor fixes

* minor fix

* formatted

---------

Co-authored-by: Alexandra <aspasparagus@gmail.com>
This commit is contained in:
chalice19
2025-04-08 15:05:17 +02:00
committed by GitHub
parent f24471694c
commit 7254ab6238
2 changed files with 44 additions and 1 deletions

View File

@@ -70,7 +70,13 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}
} else {
input_name = file_path;
let mut f = File::open(file_path)?;
let open_result = File::open(file_path);
if let Err(err) = open_result {
eprintln!("mcookie: cannot open {file_path}: {err}");
continue;
}
let mut f = open_result.unwrap();
if let Some(max_bytes) = &max_size {
let mut limited_reader = f.take(*max_bytes);
limited_reader.read_to_end(&mut buffer)?;