From 2cf8e7b8a50cd89c47515193ac523af483c067a7 Mon Sep 17 00:00:00 2001 From: sharkdp Date: Sun, 25 Mar 2018 17:49:32 +0200 Subject: [PATCH] Move is_executable to internal module --- src/internal.rs | 13 +++++++++++++ src/output.rs | 16 ++-------------- src/walk.rs | 5 ++--- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/internal.rs b/src/internal.rs index 6b3a473..a5cdc8d 100644 --- a/src/internal.rs +++ b/src/internal.rs @@ -10,6 +10,9 @@ 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; @@ -174,6 +177,16 @@ 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 246cac7..8bc4b3b 100644 --- a/src/output.rs +++ b/src/output.rs @@ -6,17 +6,15 @@ // notice may not be copied, modified, or distributed except // according to those terms. -use internal::{FdOptions, EXITCODE_ERROR, EXITCODE_SIGINT}; +use internal::{is_executable, FdOptions, EXITCODE_ERROR, EXITCODE_SIGINT}; use lscolors::LsColors; -use std::{fs, process}; +use std::process; use std::io::{self, Write}; use std::ops::Deref; use std::path::{self, Component, Path, PathBuf}; use std::sync::Arc; use std::sync::atomic::{AtomicBool, Ordering}; -#[cfg(any(unix, target_os = "redox"))] -use std::os::unix::fs::PermissionsExt; use ansi_term; @@ -133,13 +131,3 @@ fn get_path_style<'a>(path: &Path, ls_colors: &'a LsColors) -> Option<&'a ansi_t None } } - -#[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/walk.rs b/src/walk.rs index 47026b3..9908ba6 100644 --- a/src/walk.rs +++ b/src/walk.rs @@ -10,7 +10,7 @@ extern crate ctrlc; use exec; use fshelper; -use internal::{error, FdOptions, EXITCODE_SIGINT, MAX_BUFFER_LENGTH}; +use internal::{error, is_executable, FdOptions, EXITCODE_SIGINT, MAX_BUFFER_LENGTH}; use output; use std::process; @@ -202,8 +202,7 @@ 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() - && !output::is_executable(&entry.metadata().unwrap()) + || (entry.metadata().is_ok() && !is_executable(&entry.metadata().unwrap()) && file_types.executables_only) { return ignore::WalkState::Continue;