From b7ccbf6b9c35442914f50f0475b3b3d8cf68aebd Mon Sep 17 00:00:00 2001 From: Tunahan Karlibas Date: Sat, 18 Jan 2025 05:43:15 +0300 Subject: [PATCH] use NotADirectory io error kind where appropriate --- gix-fs/tests/dir/remove.rs | 5 ++++- gix-glob/src/search/pattern.rs | 2 +- gix-odb/src/store_impls/dynamic/init.rs | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/gix-fs/tests/dir/remove.rs b/gix-fs/tests/dir/remove.rs index 079cf68342e..717efa133af 100644 --- a/gix-fs/tests/dir/remove.rs +++ b/gix-fs/tests/dir/remove.rs @@ -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(()) diff --git a/gix-glob/src/search/pattern.rs b/gix-glob/src/search/pattern.rs index 54981651ecb..b45ce4adab1 100644 --- a/gix-glob/src/search/pattern.rs +++ b/gix-glob/src/search/pattern.rs @@ -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 diff --git a/gix-odb/src/store_impls/dynamic/init.rs b/gix-odb/src/store_impls/dynamic/init.rs index 2031e48c837..f66cd8dde35 100644 --- a/gix-odb/src/store_impls/dynamic/init.rs +++ b/gix-odb/src/store_impls/dynamic/init.rs @@ -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()), )); }