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 crc = 0u32;
|
||||||
let mut size = 0usize;
|
let mut size = 0usize;
|
||||||
|
|
||||||
let file;
|
|
||||||
let mut rd: Box<dyn Read> = match fname {
|
let mut rd: Box<dyn Read> = match fname {
|
||||||
"-" => Box::new(stdin()),
|
"-" => Box::new(stdin()),
|
||||||
_ => {
|
_ => {
|
||||||
file = File::open(Path::new(fname))?;
|
let p = Path::new(fname);
|
||||||
Box::new(BufReader::new(file))
|
|
||||||
|
// 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);
|
at.mkdir(folder_name);
|
||||||
ts.ucmd()
|
ts.ucmd()
|
||||||
.arg(folder_name)
|
.arg(folder_name)
|
||||||
.fails()
|
.succeeds()
|
||||||
.no_stdout()
|
.stdout_only("4294967295 0 asdf\n");
|
||||||
.stderr_contains("cksum: asdf: Is a directory");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure crc is correct for files larger than 32 bytes
|
// Make sure crc is correct for files larger than 32 bytes
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue