Merge pull request #1169 from Ptipiak/mention-executable-detection
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Using faccess lib to detect executable files
authored by David Peter · committed by GitHub · parents d89b575, 5c87ff5 · Browse files · 5 files·+22 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+22 added−22 removed
- other:+22 added−22 removed
Provenance
- Commit
38cdeb0- Tree
493dee4- Author
David Peter <sharkdp@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent 1
d89b575- Parent 2
5c87ff5
5 files changed+22 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+16 added
1 # Upcoming release2 3+## Features4+5+6+## Changes7+8+- Breaking: On Unix-like systems, `--type executable` now additionally checks if9+ the file is executable by the current user, see #1106 and #1169 (@ptipiak)10+11+12+## Bugfixes13+14+15+## Other16+17+18+19 # v8.5.320 21 ## Bugfixes22 643 unmodified lines