Skip to content

Commit 9a43077

Browse files
committed
Using faccess lib to detect executable files
* The detection of executable files was not exactly the same as the original find
1 parent 9e88f91 commit 9a43077

File tree

5 files changed

+14
-17
lines changed

5 files changed

+14
-17
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# unreleased
2+
3+
## Changes
4+
5+
- On Unix-like system change the detection of executable,
6+
`--type executable` now checks if file is executable by the current user,
7+
see #1106 (@ptipiak)
8+
19
# v8.5.2
210

311
## Bugfixes

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ chrono = "0.4"
5151
once_cell = "1.15.0"
5252
crossbeam-channel = "0.5.6"
5353
clap_complete = {version = "4.0", optional = true}
54+
faccess = "0.2.4"
5455

5556
[dependencies.clap]
5657
version = "4.0.12"
@@ -63,9 +64,6 @@ nix = { version = "0.24.2", default-features = false, features = ["signal"] }
6364
[target.'cfg(all(unix, not(target_os = "redox")))'.dependencies]
6465
libc = "0.2"
6566

66-
[target.'cfg(windows)'.dependencies]
67-
faccess = "0.2.4"
68-
6967
# FIXME: Re-enable jemalloc on macOS
7068
# jemalloc is currently disabled on macOS due to a bug in jemalloc in combination with macOS
7169
# Catalina. See https://github.com/sharkdp/fd/issues/498 for details.

src/cli.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,7 @@ pub enum FileType {
707707
Directory,
708708
#[value(alias = "l")]
709709
Symlink,
710+
/// Filter file which are executable by the current effective user
710711
#[value(alias = "x")]
711712
Executable,
712713
#[value(alias = "e")]

src/filesystem.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ use std::ffi::OsStr;
44
use std::fs;
55
use std::io;
66
#[cfg(any(unix, target_os = "redox"))]
7-
use std::os::unix::fs::{FileTypeExt, PermissionsExt};
7+
use std::os::unix::fs::FileTypeExt;
88
use std::path::{Path, PathBuf};
99

10-
#[cfg(windows)]
1110
use faccess::PathExt as _;
1211

1312
use normpath::PathExt;
@@ -44,13 +43,8 @@ pub fn is_existing_directory(path: &Path) -> bool {
4443
path.is_dir() && (path.file_name().is_some() || path.normalize().is_ok())
4544
}
4645

47-
#[cfg(any(unix, target_os = "redox"))]
48-
pub fn is_executable(_: &Path, md: &fs::Metadata) -> bool {
49-
md.permissions().mode() & 0o111 != 0
50-
}
51-
52-
#[cfg(windows)]
53-
pub fn is_executable(path: &Path, _: &fs::Metadata) -> bool {
46+
/// Return true if the path point to a file executable by the current effective user
47+
pub fn is_executable(path: &Path) -> bool {
5448
path.executable()
5549
}
5650

src/filetypes.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ impl FileTypes {
2121
|| (!self.symlinks && entry_type.is_symlink())
2222
|| (!self.sockets && filesystem::is_socket(*entry_type))
2323
|| (!self.pipes && filesystem::is_pipe(*entry_type))
24-
|| (self.executables_only
25-
&& !entry
26-
.metadata()
27-
.map(|md| filesystem::is_executable(entry.path(), md))
28-
.unwrap_or(false))
24+
|| (self.executables_only && !filesystem::is_executable(entry.path()))
2925
|| (self.empty_only && !filesystem::is_empty(entry))
3026
|| !(entry_type.is_file()
3127
|| entry_type.is_dir()

0 commit comments

Comments
 (0)