Skip to content
Myr

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

5 files+22 added−22 removed

modified:src/cli.rs+1 added
641 unmodified lines
642 #[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 lines
modified:src/filesystem.rs+1 added-14 removed
2 unmodified lines
3use std::ffi::OsStr;4use std::fs;5use std::io;6#[cfg(any(unix, target_os = "redox"))]7use std::os::unix::fs::{FileTypeExt, PermissionsExt};7use std::os::unix::fs::FileTypeExt;8use std::path::{Path, PathBuf};910#[cfg(windows)]11use faccess::PathExt as _;1210use normpath::PathExt;1112use crate::dir_entry;13
26 unmodified lines
40 // the CWD has been deleted.41 path.is_dir() && (path.file_name().is_some() || path.normalize().is_ok())42}4347#[cfg(any(unix, target_os = "redox"))]48pub fn is_executable(_: &Path, md: &fs::Metadata) -> bool {49 md.permissions().mode() & 0o111 != 050}5152#[cfg(windows)]53pub fn is_executable(path: &Path, _: &fs::Metadata) -> bool {54 path.executable()55}5644pub 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 lines
modified:src/filetypes.rs+3 added-5 removed
1use crate::dir_entry;2use crate::filesystem;34use faccess::PathExt;56/// Whether or not to show7#[derive(Default)]8pub struct FileTypes {9 pub files: bool,
12 unmodified lines
22 || (!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 lines
modified:Cargo.toml+1 added-3 removed
modified:CHANGELOG.md+16 added
1# Upcoming release23## Features456## Changes78- Breaking: On Unix-like systems, `--type executable` now additionally checks if9 the file is executable by the current user, see #1106 and #1169 (@ptipiak)101112## Bugfixes131415## Other16171819# v8.5.32021## Bugfixes22
643 unmodified lines