Skip to content

Commit

Permalink
use NotADirectory io error kind where appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
dvtkrlbs committed Jan 18, 2025
1 parent c2d1a5d commit b7ccbf6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion gix-fs/tests/dir/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ mod empty_upwards_until_boundary {
let dir = tempfile::tempdir()?;
let target = dir.path().join("actually-a-file");
std::fs::write(&target, [42])?;
assert!(remove::empty_upward_until_boundary(&target, dir.path()).is_err()); // TODO: check for IsNotADirectory when it becomes stable

let res = remove::empty_upward_until_boundary(&target, dir.path());
assert!(res.is_err());
assert!(res.err().unwrap().kind() == io::ErrorKind::NotADirectory);
assert!(target.is_file(), "it didn't touch the file");
assert!(dir.path().is_dir(), "it won't touch the boundary");
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion gix-glob/src/search/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn io_err_is_dir(err: &std::io::Error) -> bool {
let raw = err.raw_os_error();
raw == Some(if cfg!(windows) { 5 } else { 21 }) /* Not a directory */
/* Also that, but under different circumstances */
|| raw == Some(20)
|| raw == Some(20) || err.kind() == std::io::ErrorKind::NotADirectory
}

/// Instantiation
Expand Down
2 changes: 1 addition & 1 deletion gix-odb/src/store_impls/dynamic/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl Store {
)?;
if !objects_dir.is_dir() {
return Err(std::io::Error::new(
std::io::ErrorKind::Other, // TODO: use NotADirectory when stabilized
std::io::ErrorKind::NotADirectory,
format!("'{}' wasn't a directory", objects_dir.display()),
));
}
Expand Down

0 comments on commit b7ccbf6

Please sign in to comment.