Move is_executable to internal module

This commit is contained in:
sharkdp 2018-03-25 17:49:32 +02:00 committed by David Peter
parent 67f6fdf6a7
commit 2cf8e7b8a5
3 changed files with 17 additions and 17 deletions

View File

@ -10,6 +10,9 @@ use std::ffi::OsString;
use std::process; use std::process;
use std::time; use std::time;
use std::io::Write; use std::io::Write;
use std::fs;
#[cfg(any(unix, target_os = "redox"))]
use std::os::unix::fs::PermissionsExt;
use exec::CommandTemplate; use exec::CommandTemplate;
use lscolors::LsColors; 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)] #[cfg(test)]
fn oss(v: &str) -> OsString { fn oss(v: &str) -> OsString {
OsString::from(v) OsString::from(v)

View File

@ -6,17 +6,15 @@
// notice may not be copied, modified, or distributed except // notice may not be copied, modified, or distributed except
// according to those terms. // according to those terms.
use internal::{FdOptions, EXITCODE_ERROR, EXITCODE_SIGINT}; use internal::{is_executable, FdOptions, EXITCODE_ERROR, EXITCODE_SIGINT};
use lscolors::LsColors; use lscolors::LsColors;
use std::{fs, process}; use std::process;
use std::io::{self, Write}; use std::io::{self, Write};
use std::ops::Deref; use std::ops::Deref;
use std::path::{self, Component, Path, PathBuf}; use std::path::{self, Component, Path, PathBuf};
use std::sync::Arc; use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
#[cfg(any(unix, target_os = "redox"))]
use std::os::unix::fs::PermissionsExt;
use ansi_term; use ansi_term;
@ -133,13 +131,3 @@ fn get_path_style<'a>(path: &Path, ls_colors: &'a LsColors) -> Option<&'a ansi_t
None 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
}

View File

@ -10,7 +10,7 @@ extern crate ctrlc;
use exec; use exec;
use fshelper; 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 output;
use std::process; use std::process;
@ -202,8 +202,7 @@ pub fn scan(path_vec: &[PathBuf], pattern: Arc<Regex>, config: Arc<FdOptions>) {
if (entry_type.is_file() && !file_types.files) if (entry_type.is_file() && !file_types.files)
|| (entry_type.is_dir() && !file_types.directories) || (entry_type.is_dir() && !file_types.directories)
|| (entry_type.is_symlink() && !file_types.symlinks) || (entry_type.is_symlink() && !file_types.symlinks)
|| (entry.metadata().is_ok() || (entry.metadata().is_ok() && !is_executable(&entry.metadata().unwrap())
&& !output::is_executable(&entry.metadata().unwrap())
&& file_types.executables_only) && file_types.executables_only)
{ {
return ignore::WalkState::Continue; return ignore::WalkState::Continue;