mirror of
https://github.com/uutils/coreutils
synced 2024-11-15 09:27:21 +00:00
fix(cksum): check metadata of the path (#1951)
* fix: check metadata of the path * chore: use existing path
This commit is contained in:
parent
d88de3c6a6
commit
25df51a525
1 changed files with 14 additions and 1 deletions
|
@ -140,7 +140,20 @@ fn cksum(fname: &str) -> io::Result<(u32, usize)> {
|
||||||
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 path = &Path::new(fname);
|
||||||
|
if path.is_dir() {
|
||||||
|
return Err(std::io::Error::new(
|
||||||
|
io::ErrorKind::InvalidInput,
|
||||||
|
"Is a directory",
|
||||||
|
));
|
||||||
|
};
|
||||||
|
if !path.metadata().is_ok() {
|
||||||
|
return Err(std::io::Error::new(
|
||||||
|
io::ErrorKind::NotFound,
|
||||||
|
"No such file or directory",
|
||||||
|
));
|
||||||
|
};
|
||||||
|
file = File::open(&path)?;
|
||||||
Box::new(BufReader::new(file))
|
Box::new(BufReader::new(file))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue