Implement --type executable on Windows
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Fixes #1051.
authored by Tavian Barnes · committed by David Peter · parent 3e68733 · Browse files · 5 files·+23 added−4 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+23 added−4 removed
- other:+23 added−4 removed
Provenance
- Commit
cbc6dde- Tree
f59b2de- Author
Tavian Barnes <tavianator@tavianator.com>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
3e68733
5 files changed+23 added−4 removed
modified:src/filesystem.rs+6 added-3 removed
5 unmodified lines6 #[cfg(any(unix, target_os = "redox"))]7 use std::os::unix::fs::{FileTypeExt, PermissionsExt};8 use std::path::{Path, PathBuf};9 10+#[cfg(windows)]11+use faccess::PathExt as _;12+13 use normpath::PathExt;14 15 use crate::dir_entry;16 27 unmodified lines44 path.is_dir() && (path.file_name().is_some() || path.normalize().is_ok())45 }46 47 #[cfg(any(unix, target_os = "redox"))]45-pub fn is_executable(md: &fs::Metadata) -> bool {48+pub fn is_executable(_: &Path, md: &fs::Metadata) -> bool {49 md.permissions().mode() & 0o111 != 050 }51 52 #[cfg(windows)]50-pub fn is_executable(_: &fs::Metadata) -> bool {51- false53+pub fn is_executable(path: &Path, _: &fs::Metadata) -> bool {54+ path.executable()55 }56 57 pub fn is_empty(entry: &dir_entry::DirEntry) -> bool {58 if let Some(file_type) = entry.file_type() {93 unmodified linesmodified:src/filetypes.rs+1 added-1 removed
22 unmodified lines23 || (!self.pipes && filesystem::is_pipe(*entry_type))24 || (self.executables_only25 && !entry26 .metadata()27- .map(filesystem::is_executable)27+ .map(|md| filesystem::is_executable(entry.path(), md))28 .unwrap_or(false))29 || (self.empty_only && !filesystem::is_empty(entry))30 || !(entry_type.is_file()31 || entry_type.is_dir()8 unmodified linesmodified:Cargo.lock+12 added
175 unmodified lines176 "winapi",177 ]178 179 [[package]]180+name = "faccess"181+version = "0.2.4"182+source = "registry+https://github.com/rust-lang/crates.io-index"183+checksum = "59ae66425802d6a903e268ae1a08b8c38ba143520f227a205edf4e9c7e3e26d5"184+dependencies = [185+ "bitflags",186+ "libc",187+ "winapi",188+]189+190+[[package]]191 name = "fd-find"192 version = "8.4.0"193 dependencies = [194 "ansi_term",5 unmodified lines200 "clap_complete",201 "ctrlc",202 "diff",203 "dirs-next",204+ "faccess",205 "filetime",206 "globset",207 "humantime",208 "ignore",632 unmodified linesmodified:Cargo.toml+3 added
61 unmodified lines626364656667686970717215 unmodified lines61 unmodified lines
[target.'cfg(all(unix, not(target_os = "redox")))'.dependencies]libc = "0.2"
[target.'cfg(windows)'.dependencies]faccess = "0.2.4"
# FIXME: Re-enable jemalloc on macOS# jemalloc is currently disabled on macOS due to a bug in jemalloc in combination with macOS# Catalina. See https://github.com/sharkdp/fd/issues/498 for details.[target.'cfg(all(not(windows), not(target_os = "android"), not(target_os = "macos"), not(target_os = "freebsd"), not(target_env = "musl"), not(target_arch = "riscv64")))'.dependencies]15 unmodified linesmodified:CHANGELOG.md+1 added
1 # Upcoming release2 3 ## Features4 5+- `--type executable`/`-t` now works on Windows, see #1051 and #10616 7 ## Bugfixes8 9 - fd returns an error when current working directory does not exist while a search path is specified, see #1072 (@vijfhoek)600 unmodified lines