cli: Allow reading every path not of type dir (#414)

This commit is contained in:
Johannes Wolf 2023-03-30 00:36:22 +02:00 committed by GitHub
parent dffaef0832
commit 4d9c6b28d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions

View File

@ -569,10 +569,10 @@ impl PathHash {
/// Read a file.
fn read(path: &Path) -> FileResult<Vec<u8>> {
let f = |e| FileError::from_io(e, path);
if fs::metadata(&path).map_err(f)?.is_file() {
fs::read(&path).map_err(f)
} else {
if fs::metadata(&path).map_err(f)?.is_dir() {
Err(FileError::IsDirectory)
} else {
fs::read(&path).map_err(f)
}
}

View File

@ -324,10 +324,10 @@ fn read(path: &Path) -> FileResult<Vec<u8>> {
.unwrap_or_else(|_| path.into());
let f = |e| FileError::from_io(e, &suffix);
if fs::metadata(&path).map_err(f)?.is_file() {
fs::read(&path).map_err(f)
} else {
if fs::metadata(&path).map_err(f)?.is_dir() {
Err(FileError::IsDirectory)
} else {
fs::read(&path).map_err(f)
}
}