diff --git a/Cargo.lock b/Cargo.lock index 516344082..c299d276f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -42,9 +42,9 @@ dependencies = [ [[package]] name = "cfg-if" -version = "1.0.0" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9" [[package]] name = "cfg_aliases" @@ -109,6 +109,7 @@ version = "4.1.0-snapshot" dependencies = [ "bitflags", "cc", + "cfg-if", "errno", "fish-build-helper", "fish-build-man-pages", diff --git a/Cargo.toml b/Cargo.toml index 08f045fe1..0bbe534ec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ repository = "https://github.com/fish-shell/fish-shell" [workspace.dependencies] bitflags = "2.5.0" cc = "1.0.94" +cfg-if = "1.0.3" errno = "0.3.0" fish-build-helper = { path = "crates/build-helper" } fish-build-man-pages = { path = "crates/build-man-pages" } @@ -76,6 +77,7 @@ readme = "README.rst" [dependencies] bitflags.workspace = true +cfg-if.workspace = true errno.workspace = true fish-build-helper.workspace = true fish-build-man-pages = { workspace = true, optional = true } diff --git a/src/wutil/dir_iter.rs b/src/wutil/dir_iter.rs index 24bf40755..d85a6e3bd 100644 --- a/src/wutil/dir_iter.rs +++ b/src/wutil/dir_iter.rs @@ -2,6 +2,7 @@ use crate::common::{str2wcstring, wcs2zstring}; use crate::wchar::{wstr, WString}; use crate::wutil::DevInode; +use cfg_if::cfg_if; use libc::{ DT_BLK, DT_CHR, DT_DIR, DT_FIFO, DT_LNK, DT_REG, DT_SOCK, EACCES, EIO, ELOOP, ENAMETOOLONG, ENODEV, ENOENT, ENOTDIR, S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO, S_IFLNK, S_IFMT, S_IFREG, @@ -285,14 +286,13 @@ pub fn next(&mut self) -> Option> { self.entry.reset(); self.entry.name = str2wcstring(d_name); - #[cfg(any(target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))] - { - self.entry.inode = dent.d_fileno; - } - #[cfg(not(any(target_os = "freebsd", target_os = "netbsd", target_os = "openbsd")))] - { - self.entry.inode = dent.d_ino; - } + cfg_if!( + if #[cfg(any(target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))] { + self.entry.inode = dent.d_fileno; + } else { + self.entry.inode = dent.d_ino; + } + ); let typ = dirent_type_to_entry_type(dent.d_type); // Do not store symlinks as we will need to resolve them. if typ != Some(DirEntryType::lnk) {