Move is_executable to fshelper module

This commit is contained in:
sharkdp 2018-03-25 19:48:09 +02:00
parent 9d840dd485
commit f9a32583a5
4 changed files with 18 additions and 16 deletions

View File

@ -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<PathBuf> {
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
}

View File

@ -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)

View File

@ -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;

View File

@ -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<Regex>, config: Arc<FdOptions>) {
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;