Skip to content

Commit 3f6ee52

Browse files
committed
feat: add io_err module with classifiers.
This makes it easier to portably identify IO errors, especially while the MSRV is not Rustc v1.83 which stabilizes the error kind variants.
1 parent ad6b9b6 commit 3f6ee52

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

gix-fs/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ pub fn is_executable(metadata: &std::fs::Metadata) -> bool {
8383
(metadata.mode() & 0o100) != 0
8484
}
8585

86+
/// Classifiers for IO-errors.
87+
pub mod io_err {
88+
use std::io::ErrorKind;
89+
90+
/// Return `true` if `err` indicates that the entry doesn't exist on disk. `raw` is used as well
91+
/// for additional checks while the variants are outside the MSRV.
92+
pub fn is_not_found(err: ErrorKind, raw_err: Option<i32>) -> bool {
93+
// TODO: use variant once MSRV is 1.83
94+
err == ErrorKind::NotFound || raw_err == Some(20)
95+
}
96+
}
97+
8698
#[cfg(not(unix))]
8799
/// Returns whether a a file has the executable permission set.
88100
pub fn is_executable(_metadata: &std::fs::Metadata) -> bool {

0 commit comments

Comments
 (0)