Using faccess lib to detect executable files
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* The detection of executable files was not exactly the same as the original find
authored by Ptipiak · committed by Ptipiak · parent d89b575 · Browse files · 5 files·+12 added−22 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+12 added−22 removed
- other:+12 added−22 removed
Provenance
- Commit
88bebb8- Tree
75752bc- Author
Ptipiak <Ptipiak.off@gmail.com>- Committer
Ptipiak <Ptipiak.off@gmail.com>- Parent
d89b575
5 files changed+12 added−22 removed
modified:src/cli.rs+1 added
641 unmodified lines642 #[value(alias = "d")]643 Directory,644 #[value(alias = "l")]645 Symlink,646+ /// A file which is executable by the current effective user647 #[value(alias = "x")]648 Executable,649 #[value(alias = "e")]650 Empty,135 unmodified linesmodified:src/filesystem.rs+1 added-14 removed
2 unmodified lines3 use std::ffi::OsStr;4 use std::fs;5 use std::io;6 #[cfg(any(unix, target_os = "redox"))]7-use std::os::unix::fs::{FileTypeExt, PermissionsExt};7+use std::os::unix::fs::FileTypeExt;8 use std::path::{Path, PathBuf};9 10-#[cfg(windows)]11-use faccess::PathExt as _;12-10 use normpath::PathExt;11 12 use crate::dir_entry;13 26 unmodified lines40 // the CWD has been deleted.41 path.is_dir() && (path.file_name().is_some() || path.normalize().is_ok())42 }43 47-#[cfg(any(unix, target_os = "redox"))]48-pub fn is_executable(_: &Path, md: &fs::Metadata) -> bool {49- md.permissions().mode() & 0o111 != 050-}51-52-#[cfg(windows)]53-pub fn is_executable(path: &Path, _: &fs::Metadata) -> bool {54- path.executable()55-}56-44 pub fn is_empty(entry: &dir_entry::DirEntry) -> bool {45 if let Some(file_type) = entry.file_type() {46 if file_type.is_dir() {47 if let Ok(mut entries) = fs::read_dir(entry.path()) {91 unmodified linesmodified:src/filetypes.rs+3 added-5 removed
1 use crate::dir_entry;2 use crate::filesystem;3 4+use faccess::PathExt;5+6 /// Whether or not to show7 #[derive(Default)]8 pub struct FileTypes {9 pub files: bool,12 unmodified lines22 || (!self.directories && entry_type.is_dir())23 || (!self.symlinks && entry_type.is_symlink())24 || (!self.sockets && filesystem::is_socket(*entry_type))25 || (!self.pipes && filesystem::is_pipe(*entry_type))24- || (self.executables_only25- && !entry26- .metadata()27- .map(|md| filesystem::is_executable(entry.path(), md))28- .unwrap_or(false))26+ || (self.executables_only && !entry.path().executable())27 || (self.empty_only && !filesystem::is_empty(entry))28 || !(entry_type.is_file()29 || entry_type.is_dir()30 || entry_type.is_symlink()7 unmodified linesmodified:Cargo.toml+1 added-3 removed
49 unmodified lines5051525354555657584 unmodified lines636465666667686768697017 unmodified lines49 unmodified lineschrono = "0.4"once_cell = "1.15.0"crossbeam-channel = "0.5.6"clap_complete = {version = "4.0.5", optional = true}faccess = "0.2.4"
[dependencies.clap]version = "4.0.22"features = ["suggestions", "color", "wrap_help", "cargo", "unstable-grouped", "derive"]4 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(all(target_env = "musl", target_pointer_width = "32")), not(target_arch = "riscv64")))'.dependencies]17 unmodified linesmodified:CHANGELOG.md+6 added
5 unmodified lines6 7 - Fix completion generation to not include full path of fd command8 - Fix build error if completions feature is disabled9 10+## Changes11+12+- On Unix-like system change the detection of executable,13+ `--type executable` now checks if file is executable by the current user,14+ see #1106 (@ptipiak)15+16 # v8.5.217 18 ## Bugfixes19 636 unmodified lines