mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
cksum: accept directories as empty files
This commit is contained in:
parent
8885263ad5
commit
7ae9e0a7eb
2 changed files with 11 additions and 6 deletions
|
@ -80,12 +80,18 @@ fn cksum(fname: &str) -> io::Result<(u32, usize)> {
|
|||
let mut crc = 0u32;
|
||||
let mut size = 0usize;
|
||||
|
||||
let file;
|
||||
let mut rd: Box<dyn Read> = match fname {
|
||||
"-" => Box::new(stdin()),
|
||||
_ => {
|
||||
file = File::open(Path::new(fname))?;
|
||||
Box::new(BufReader::new(file))
|
||||
let p = Path::new(fname);
|
||||
|
||||
// Directories should not give an error, but should be interpreted
|
||||
// as empty files to match GNU semantics.
|
||||
if p.is_dir() {
|
||||
Box::new(BufReader::new(io::empty())) as Box<dyn Read>
|
||||
} else {
|
||||
Box::new(BufReader::new(File::open(p)?)) as Box<dyn Read>
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -74,9 +74,8 @@ fn test_invalid_file() {
|
|||
at.mkdir(folder_name);
|
||||
ts.ucmd()
|
||||
.arg(folder_name)
|
||||
.fails()
|
||||
.no_stdout()
|
||||
.stderr_contains("cksum: asdf: Is a directory");
|
||||
.succeeds()
|
||||
.stdout_only("4294967295 0 asdf\n");
|
||||
}
|
||||
|
||||
// Make sure crc is correct for files larger than 32 bytes
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue