From f9a32583a5a870a66eea417cf588b186bfa7c895 Mon Sep 17 00:00:00 2001 From: sharkdp Date: Sun, 25 Mar 2018 19:48:09 +0200 Subject: [PATCH] Move is_executable to fshelper module --- src/fshelper/mod.rs | 13 +++++++++++++ src/internal.rs | 13 ------------- src/output.rs | 3 ++- src/walk.rs | 5 +++-- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/fshelper/mod.rs b/src/fshelper/mod.rs index b473a76..5beff0c 100644 --- a/src/fshelper/mod.rs +++ b/src/fshelper/mod.rs @@ -9,6 +9,9 @@ use std::env::current_dir; use std::path::{Path, PathBuf}; use std::io; +use std::fs; +#[cfg(any(unix, target_os = "redox"))] +use std::os::unix::fs::PermissionsExt; pub fn path_absolute_form(path: &Path) -> io::Result { if path.is_absolute() { @@ -42,3 +45,13 @@ pub fn is_dir(path: &Path) -> bool { path.is_dir() && path.canonicalize().is_ok() } } + +#[cfg(any(unix, target_os = "redox"))] +pub fn is_executable(md: &fs::Metadata) -> bool { + md.permissions().mode() & 0o111 != 0 +} + +#[cfg(windows)] +pub fn is_executable(_: &fs::Metadata) -> bool { + false +} diff --git a/src/internal.rs b/src/internal.rs index a5cdc8d..6b3a473 100644 --- a/src/internal.rs +++ b/src/internal.rs @@ -10,9 +10,6 @@ use std::ffi::OsString; use std::process; use std::time; use std::io::Write; -use std::fs; -#[cfg(any(unix, target_os = "redox"))] -use std::os::unix::fs::PermissionsExt; use exec::CommandTemplate; use lscolors::LsColors; @@ -177,16 +174,6 @@ where }) } -#[cfg(any(unix, target_os = "redox"))] -pub fn is_executable(md: &fs::Metadata) -> bool { - md.permissions().mode() & 0o111 != 0 -} - -#[cfg(windows)] -pub fn is_executable(_: &fs::Metadata) -> bool { - false -} - #[cfg(test)] fn oss(v: &str) -> OsString { OsString::from(v) diff --git a/src/output.rs b/src/output.rs index 8bc4b3b..0c2c0b6 100644 --- a/src/output.rs +++ b/src/output.rs @@ -6,7 +6,8 @@ // notice may not be copied, modified, or distributed except // according to those terms. -use internal::{is_executable, FdOptions, EXITCODE_ERROR, EXITCODE_SIGINT}; +use internal::{FdOptions, EXITCODE_ERROR, EXITCODE_SIGINT}; +use fshelper::is_executable; use lscolors::LsColors; use std::process; diff --git a/src/walk.rs b/src/walk.rs index 9908ba6..f151ea6 100644 --- a/src/walk.rs +++ b/src/walk.rs @@ -10,7 +10,7 @@ extern crate ctrlc; use exec; use fshelper; -use internal::{error, is_executable, FdOptions, EXITCODE_SIGINT, MAX_BUFFER_LENGTH}; +use internal::{error, FdOptions, EXITCODE_SIGINT, MAX_BUFFER_LENGTH}; use output; use std::process; @@ -202,7 +202,8 @@ pub fn scan(path_vec: &[PathBuf], pattern: Arc, config: Arc) { if (entry_type.is_file() && !file_types.files) || (entry_type.is_dir() && !file_types.directories) || (entry_type.is_symlink() && !file_types.symlinks) - || (entry.metadata().is_ok() && !is_executable(&entry.metadata().unwrap()) + || (entry.metadata().is_ok() + && !fshelper::is_executable(&entry.metadata().unwrap()) && file_types.executables_only) { return ignore::WalkState::Continue;