Skip to content

Commit 38cdeb0

Browse files
authored
Merge pull request #1169 from Ptipiak/mention-executable-detection
Using faccess lib to detect executable files
2 parents d89b575 + 5c87ff5 commit 38cdeb0

File tree

5 files changed

+22
-22
lines changed

5 files changed

+22
-22
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
# Upcoming release
22

3+
## Features
4+
5+
6+
## Changes
7+
8+
- Breaking: On Unix-like systems, `--type executable` now additionally checks if
9+
the file is executable by the current user, see #1106 and #1169 (@ptipiak)
10+
11+
12+
## Bugfixes
13+
14+
15+
## Other
16+
17+
18+
319
# v8.5.3
420

521
## 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.5", optional = true}
54+
faccess = "0.2.4"
5455

5556
[dependencies.clap]
5657
version = "4.0.22"
@@ -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
@@ -643,6 +643,7 @@ pub enum FileType {
643643
Directory,
644644
#[value(alias = "l")]
645645
Symlink,
646+
/// A file which is executable by the current effective user
646647
#[value(alias = "x")]
647648
Executable,
648649
#[value(alias = "e")]

src/filesystem.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +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)]
11-
use faccess::PathExt as _;
12-
1310
use normpath::PathExt;
1411

1512
use crate::dir_entry;
@@ -44,16 +41,6 @@ pub fn is_existing_directory(path: &Path) -> bool {
4441
path.is_dir() && (path.file_name().is_some() || path.normalize().is_ok())
4542
}
4643

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 {
54-
path.executable()
55-
}
56-
5744
pub fn is_empty(entry: &dir_entry::DirEntry) -> bool {
5845
if let Some(file_type) = entry.file_type() {
5946
if file_type.is_dir() {

src/filetypes.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::dir_entry;
22
use crate::filesystem;
33

4+
use faccess::PathExt;
5+
46
/// Whether or not to show
57
#[derive(Default)]
68
pub struct FileTypes {
@@ -21,11 +23,7 @@ impl FileTypes {
2123
|| (!self.symlinks && entry_type.is_symlink())
2224
|| (!self.sockets && filesystem::is_socket(*entry_type))
2325
|| (!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))
26+
|| (self.executables_only && !entry.path().executable())
2927
|| (self.empty_only && !filesystem::is_empty(entry))
3028
|| !(entry_type.is_file()
3129
|| entry_type.is_dir()

0 commit comments

Comments
 (0)