Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
rust: ['1.85', stable, nightly]
rust: ['1.70', stable, nightly]
steps:
- name: Setup | Checkout
uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# CHANGELOG

## 9.0.0
## 8.0.2

- MSRV bumped to Rust 1.85.0
- Dependency on `home_env` removed, the implementation found in rust 1.85.0 for a home directory has been fixed.
Thanks, [@madsmtm],(https://github.com/madsmtm) for this contribution to which!
- Dependency on `winsafe` removed, code for Windows API is now handwritten.

## 8.0.1

Expand Down
11 changes: 2 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "which"
version = "9.0.0"
version = "8.0.2"
edition = "2021"
rust-version = "1.85"
rust-version = "1.70"
authors = ["Harry Fei <tiziyuanfang@gmail.com>, Jacob Kiesel <jake@bitcrafters.co>"]
repository = "https://github.com/harryfei/which-rs.git"
documentation = "https://docs.rs/which/"
Expand All @@ -16,7 +16,7 @@ keywords = ["which", "which-rs", "unix", "command"]
default = ["real-sys"]
regex = ["dep:regex"]
tracing = ["dep:tracing"]
real-sys = ["dep:rustix", "dep:winsafe"]
real-sys = ["dep:rustix"]

[dependencies]
regex = { version = "1.10.2", optional = true }
Expand All @@ -25,9 +25,6 @@ tracing = { version = "0.1.40", default-features = false, optional = true }
[target.'cfg(any(unix, target_os = "wasi", target_os = "redox"))'.dependencies]
rustix = { version = "1.0.5", default-features = false, features = ["fs", "std"], optional = true }

[target.'cfg(windows)'.dependencies]
winsafe = { version = "0.0.19", features = ["kernel"], optional = true }

[dev-dependencies]
tempfile = "3.9.0"

Expand Down
10 changes: 8 additions & 2 deletions src/finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ impl<TSys: Sys> Finder<TSys> {
}
_ => {
#[cfg(feature = "tracing")]
tracing::trace!("{} has no path seperators, so only paths in PATH environment variable will be searched.", path.display());
tracing::trace!(
"{} has no path seperators, so only paths in PATH environment variable will be searched.",
path.display()
);
// Search binary in PATHs(defined in environment variable).
let paths = paths.ok_or(Error::CannotGetCurrentDirAndPathListEmpty)?;
let paths = self.sys.env_split_paths(paths.as_ref());
Expand Down Expand Up @@ -346,7 +349,10 @@ impl<TSys: Sys, B: Borrow<Regex>, F: NonFatalErrorHandler> Iterator
}
} else {
#[cfg(feature = "tracing")]
tracing::debug!("regex unable to evaluate filename as it's not valid unicode. Lossy filename conversion: {}", path.file_name().to_string_lossy());
tracing::debug!(
"regex unable to evaluate filename as it's not valid unicode. Lossy filename conversion: {}",
path.file_name().to_string_lossy()
);
}
}
Some(Err(e)) => {
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ mod error;
mod finder;
mod helper;
pub mod sys;
#[cfg(all(windows, feature = "real-sys"))]
mod win_ffi;

use std::fmt;
use std::path;
Expand Down
20 changes: 17 additions & 3 deletions src/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,23 @@ impl Sys for RealSys {

#[cfg(windows)]
fn is_valid_executable(&self, path: &Path) -> io::Result<bool> {
winsafe::GetBinaryType(&path.display().to_string())
.map(|_| true)
.map_err(|e| io::Error::from_raw_os_error(e.raw() as i32))
use std::os::windows::ffi::OsStrExt;

use crate::win_ffi;
let w_str: Vec<u16> = path
.as_os_str()
.encode_wide()
.chain(std::iter::once(0))
.collect();
let mut binary_type = 0u32;
unsafe {
let success = win_ffi::GetBinaryTypeW(w_str.as_ptr(), &mut binary_type);
if success != 0 {
Ok(true)
} else {
Err(io::Error::from_raw_os_error(win_ffi::GetLastError() as i32))
}
}
}
}

Expand Down
18 changes: 18 additions & 0 deletions src/win_ffi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#[cfg(all(windows, target_arch = "x86"))]
#[link(
name = "kernel32.dll",
kind = "raw-dylib",
modifiers = "+verbatim",
import_name_type = "undecorated"
)]
extern "system" {
pub fn GetBinaryTypeW(app_name: *const u16, bin_type: *mut u32) -> i32;
pub fn GetLastError() -> u32;
}

#[cfg(all(windows, not(target_arch = "x86")))]
#[link(name = "kernel32.dll", kind = "raw-dylib", modifiers = "+verbatim")]
extern "system" {
pub fn GetBinaryTypeW(app_name: *const u16, bin_type: *mut u32) -> i32;
pub fn GetLastError() -> u32;
}
2 changes: 1 addition & 1 deletion tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ mod in_memory {
Ok(Box::new(entries.into_iter()))
}
// should use ErrorKind::NotADirectory once upgrading rust version
_ => Err(Error::other("Not a directory")),
_ => Err(Error::new(ErrorKind::Other, "Not a directory")),
}
}

Expand Down