summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Wolf <519002+johannes-wolf@users.noreply.github.com>2023-03-30 00:36:22 +0200
committerGitHub <noreply@github.com>2023-03-30 00:36:22 +0200
commit4d9c6b28d0a811ed7bd090a95774baf3bfa94c55 (patch)
treebf33c2d2e178a5459315df701c97bbd2ca778e66
parentdffaef08326967028e9ca9ff2bdb87e067fcf5f6 (diff)
cli: Allow reading every path not of type dir (#414)
-rw-r--r--cli/src/main.rs6
-rw-r--r--tests/src/tests.rs6
2 files changed, 6 insertions, 6 deletions
diff --git a/cli/src/main.rs b/cli/src/main.rs
index d48917a2..514beaa2 100644
--- a/cli/src/main.rs
+++ b/cli/src/main.rs
@@ -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)
}
}
diff --git a/tests/src/tests.rs b/tests/src/tests.rs
index 66eb532f..fef8c0cf 100644
--- a/tests/src/tests.rs
+++ b/tests/src/tests.rs
@@ -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)
}
}