walk.rs
This file
Path
src/walk.rs
459 lines · 16.5 KiB · Rust
Last changed by
Add new `--type socket` and `--type pipe` filterssharkdpbefore adoptioncb56add
History of this fileTake it
The walk stopped after 200 commits: lines older than afcdaf2 point at it.
Use regex::bytes::* instead of regex::*sharkdpbefore adoption641594c
lines 1–2why, one step back1use std::borrow::Cow;2use std::ffi::OsStr;New implementation of broken-symlink handlingsharkdpbefore adoptionbbf0f1c
line 3why, one step back3use std::fs::{FileType, Metadata};Lock stdout only oncesharkdpbefore adoption8cfdcf4
line 4why, one step back4use std::io;New implementation of broken-symlink handlingsharkdpbefore adoptionbbf0f1c
line 5why, one step back5use std::path::{Path, PathBuf};Move snapcraft filesharkdpbefore adoptionafcdaf2
lines 6–7why, one step back6use std::process;7use std::sync::atomic::{AtomicBool, Ordering};split spawn_receiver(..) and spawn_senders(..) from scan(..).Alexandru Macoveibefore adoption5ade72a
line 8why, one step back8use std::sync::mpsc::{channel, Receiver, Sender};Move snapcraft filesharkdpbefore adoptionafcdaf2
lines 9–12why, one step back9use std::sync::{Arc, Mutex};10use std::thread;11use std::time;12Proper error handling within walk.rssharkdpbefore adoption4590ae8
line 13why, one step back13use anyhow::{anyhow, Result};Move snapcraft filesharkdpbefore adoptionafcdaf2
lines 14–15why, one step back14use ignore::overrides::OverrideBuilder;15use ignore::{self, WalkBuilder};Use regex::bytes::* instead of regex::*sharkdpbefore adoption641594c
line 16why, one step back16use regex::bytes::Regex;Move snapcraft filesharkdpbefore adoptionafcdaf2
line 17why, one step back17Proper error handling within walk.rssharkdpbefore adoption4590ae8
lines 18–24why, one step back18use crate::error::print_error;19use crate::exec;20use crate::exit_codes::{merge_exitcodes, ExitCode};21use crate::filesystem;22use crate::options::Options;23use crate::output;24Move snapcraft filesharkdpbefore adoptionafcdaf2
lines 25–39why, one step back25/// The receiver thread can either be buffering results or directly streaming to the console.26enum ReceiverMode {27 /// Receiver is still buffering in order to sort the results, if the search finishes fast28 /// enough.29 Buffering,3031 /// Receiver is directly printing results to the output.32 Streaming,33}3435/// The Worker threads can result in a valid entry having PathBuf or an error.36pub enum WorkerResult {37 Entry(PathBuf),38 Error(ignore::Error),39}Move MAX_BUFFER_LENGTHsharkdpbefore adoptionc79d163
lines 40–42why, one step back4041/// Maximum size of the output buffer before flushing results to the console42pub const MAX_BUFFER_LENGTH: usize = 1000;Move snapcraft filesharkdpbefore adoptionafcdaf2
lines 43–48why, one step back4344/// Recursively scan the given search path for files / pathnames matching the pattern.45///46/// If the `--exec` argument was supplied, this will create a thread pool for executing47/// jobs in parallel from a given command line and the discovered paths. Otherwise, each48/// path will simply be written to standard output.Proper error handling within walk.rssharkdpbefore adoption4590ae8
line 49why, one step back49pub fn scan(path_vec: &[PathBuf], pattern: Arc<Regex>, config: Arc<Options>) -> Result<ExitCode> {Move snapcraft filesharkdpbefore adoptionafcdaf2
lines 50–58why, one step back50 let mut path_iter = path_vec.iter();51 let first_path_buf = path_iter52 .next()53 .expect("Error: Path vector can not be empty");54 let (tx, rx) = channel();5556 let mut override_builder = OverrideBuilder::new(first_path_buf.as_path());5758 for pattern in &config.exclude_patterns {Proper error handling within walk.rssharkdpbefore adoption4590ae8
lines 59–61why, one step back59 override_builder60 .add(pattern)61 .map_err(|e| anyhow!("Malformed exclude pattern: {}", e))?;Move snapcraft filesharkdpbefore adoptionafcdaf2
line 62why, one step back62 }Proper error handling within walk.rssharkdpbefore adoption4590ae8
lines 63–65why, one step back63 let overrides = override_builder64 .build()65 .map_err(|_| anyhow!("Mismatch in exclude patterns"))?;Move snapcraft filesharkdpbefore adoptionafcdaf2
lines 66–76why, one step back6667 let mut walker = WalkBuilder::new(first_path_buf.as_path());68 walker69 .hidden(config.ignore_hidden)70 .ignore(config.read_fdignore)71 .parents(config.read_fdignore || config.read_vcsignore)72 .git_ignore(config.read_vcsignore)73 .git_global(config.read_vcsignore)74 .git_exclude(config.read_vcsignore)75 .overrides(overrides)76 .follow_links(config.follow_links)Restrict `--one-file-system` to supported systemsSimon Engmannbefore adoptiondea1fbe
lines 77–78why, one step back77 // No need to check for supported platforms, option is unavailable on unsupported ones78 .same_file_system(config.one_file_system)Move snapcraft filesharkdpbefore adoptionafcdaf2
lines 79–86why, one step back79 .max_depth(config.max_depth);8081 if config.read_fdignore {82 walker.add_custom_ignore_filename(".fdignore");83 }8485 for ignore_file in &config.ignore_files {86 let result = walker.add_ignore(ignore_file);save one indent level in error handling for add_ignoreAlexandru Macoveibefore adoption6aa87f3
lines 87–89why, one step back87 match result {88 Some(ignore::Error::Partial(_)) => (),89 Some(err) => {Proper error handling within walk.rssharkdpbefore adoption4590ae8
lines 90–93why, one step back90 print_error(format!(91 "Malformed pattern in custom ignore file. {}.",92 err.to_string()93 ));Move snapcraft filesharkdpbefore adoptionafcdaf2
line 94why, one step back94 }save one indent level in error handling for add_ignoreAlexandru Macoveibefore adoption6aa87f3
line 95why, one step back95 None => (),Move snapcraft filesharkdpbefore adoptionafcdaf2
lines 96–102why, one step back96 }97 }9899 for path_entry in path_iter {100 walker.add(path_entry.as_path());101 }102inline value used only onceAlexandru Macoveibefore adoption74e593c
line 103why, one step back103 let parallel_walker = walker.threads(config.threads).build_parallel();Move snapcraft filesharkdpbefore adoptionafcdaf2
lines 104–106why, one step back104105 let wants_to_quit = Arc::new(AtomicBool::new(false));106 if config.ls_colors.is_some() && config.command.is_none() {Uniform names for config and wants_to_quit. Pass Arc's by ref.Alexandru Macoveibefore adoptiondf4227c
line 107why, one step back107 let wq = Arc::clone(&wants_to_quit);Move snapcraft filesharkdpbefore adoptionafcdaf2
line 108why, one step back108 ctrlc::set_handler(move || {Exit immediately when Ctrl-C has been pressed twicesharkdpbefore adoption2545aaa
lines 109–114why, one step back109 if wq.load(Ordering::Relaxed) {110 // Ctrl-C has been pressed twice, exit NOW111 process::exit(ExitCode::KilledBySigint.into());112 } else {113 wq.store(true, Ordering::Relaxed);114 }Move snapcraft filesharkdpbefore adoptionafcdaf2
lines 115–119why, one step back115 })116 .unwrap();117 }118119 // Spawn the thread that receives all results through the channel.Uniform names for config and wants_to_quit. Pass Arc's by ref.Alexandru Macoveibefore adoptiondf4227c
line 120why, one step back120 let receiver_thread = spawn_receiver(&config, &wants_to_quit, rx);split spawn_receiver(..) and spawn_senders(..) from scan(..).Alexandru Macoveibefore adoption5ade72a
lines 121–122why, one step back121122 // Spawn the sender threads.Uniform names for config and wants_to_quit. Pass Arc's by ref.Alexandru Macoveibefore adoptiondf4227c
line 123why, one step back123 spawn_senders(&config, &wants_to_quit, pattern, parallel_walker, tx);split spawn_receiver(..) and spawn_senders(..) from scan(..).Alexandru Macoveibefore adoption5ade72a
lines 124–125why, one step back124125 // Wait for the receiver thread to print out all results.Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
line 126why, one step back126 let exit_code = receiver_thread.join().unwrap();split spawn_receiver(..) and spawn_senders(..) from scan(..).Alexandru Macoveibefore adoption5ade72a
lines 127–128why, one step back127128 if wants_to_quit.load(Ordering::Relaxed) {Remove process::exit instancesharkdpbefore adoption4815ee4
lines 129–131why, one step back129 Ok(ExitCode::KilledBySigint)130 } else {131 Ok(exit_code)split spawn_receiver(..) and spawn_senders(..) from scan(..).Alexandru Macoveibefore adoption5ade72a
lines 132–135why, one step back132 }133}134135fn spawn_receiver(Move FdOptions to Optionssharkdpbefore adoption65096a6
line 136why, one step back136 config: &Arc<Options>,Uniform names for config and wants_to_quit. Pass Arc's by ref.Alexandru Macoveibefore adoptiondf4227c
line 137why, one step back137 wants_to_quit: &Arc<AtomicBool>,split spawn_receiver(..) and spawn_senders(..) from scan(..).Alexandru Macoveibefore adoption5ade72a
line 138why, one step back138 rx: Receiver<WorkerResult>,Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
line 139why, one step back139) -> thread::JoinHandle<ExitCode> {Uniform names for config and wants_to_quit. Pass Arc's by ref.Alexandru Macoveibefore adoptiondf4227c
lines 140–141why, one step back140 let config = Arc::clone(config);141 let wants_to_quit = Arc::clone(wants_to_quit);split spawn_receiver(..) and spawn_senders(..) from scan(..).Alexandru Macoveibefore adoption5ade72a
line 142why, one step back142Uniform names for config and wants_to_quit. Pass Arc's by ref.Alexandru Macoveibefore adoptiondf4227c
lines 143–145why, one step back143 let show_filesystem_errors = config.show_filesystem_errors;144 let threads = config.threads;145split spawn_receiver(..) and spawn_senders(..) from scan(..).Alexandru Macoveibefore adoption5ade72a
line 146why, one step back146 thread::spawn(move || {Move snapcraft filesharkdpbefore adoptionafcdaf2
line 147why, one step back147 // This will be set to `Some` if the `--exec` argument was supplied.Uniform names for config and wants_to_quit. Pass Arc's by ref.Alexandru Macoveibefore adoptiondf4227c
line 148why, one step back148 if let Some(ref cmd) = config.command {Move snapcraft filesharkdpbefore adoptionafcdaf2
line 149why, one step back149 if cmd.in_batch_mode() {Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
line 150why, one step back150 exec::batch(rx, cmd, show_filesystem_errors)Move snapcraft filesharkdpbefore adoptionafcdaf2
lines 151–159why, one step back151 } else {152 let shared_rx = Arc::new(Mutex::new(rx));153154 let out_perm = Arc::new(Mutex::new(()));155156 // Each spawned job will store it's thread handle in here.157 let mut handles = Vec::with_capacity(threads);158 for _ in 0..threads {159 let rx = Arc::clone(&shared_rx);avoid cloning command, in the wake of 9d26b74Alexandru Macoveibefore adoptionc2b46f2
line 160why, one step back160 let cmd = Arc::clone(cmd);Move snapcraft filesharkdpbefore adoptionafcdaf2
lines 161–171why, one step back161 let out_perm = Arc::clone(&out_perm);162163 // Spawn a job thread that will listen for and execute inputs.164 let handle =165 thread::spawn(move || exec::job(rx, cmd, out_perm, show_filesystem_errors));166167 // Push the handle of the spawned thread into the vector for later joining.168 handles.push(handle);169 }170171 // Wait for all threads to exit before exiting the program.Add collection of job & thread exit codes + default to ExitCode::Error if any ExitCode::Errorfusillicodebefore adoption7213f5a
line 172why, one step back172 let mut results: Vec<ExitCode> = Vec::new();Move snapcraft filesharkdpbefore adoptionafcdaf2
line 173why, one step back173 for h in handles {Add collection of job & thread exit codes + default to ExitCode::Error if any ExitCode::Errorfusillicodebefore adoption7213f5a
line 174why, one step back174 results.push(h.join().unwrap());Move snapcraft filesharkdpbefore adoptionafcdaf2
line 175why, one step back175 }Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
line 176why, one step back176Clean up exit code handlingsharkdpbefore adoptione42ddda
line 177why, one step back177 merge_exitcodes(&results)Move snapcraft filesharkdpbefore adoptionafcdaf2
lines 178–187why, one step back178 }179 } else {180 let start = time::Instant::now();181182 let mut buffer = vec![];183184 // Start in buffering mode185 let mut mode = ReceiverMode::Buffering;186187 // Maximum time to wait before we start streaming to the console.Uniform names for config and wants_to_quit. Pass Arc's by ref.Alexandru Macoveibefore adoptiondf4227c
line 188why, one step back188 let max_buffer_time = configMove snapcraft filesharkdpbefore adoptionafcdaf2
lines 189–191why, one step back189 .max_buffer_time190 .unwrap_or_else(|| time::Duration::from_millis(100));191Lock stdout only oncesharkdpbefore adoption8cfdcf4
lines 192–194why, one step back192 let stdout = io::stdout();193 let mut stdout = stdout.lock();194Add --max-results=<count> optionsharkdpbefore adoptiond43827f
lines 195–196why, one step back195 let mut num_results = 0;196Move snapcraft filesharkdpbefore adoptionafcdaf2
line 197why, one step back197 for worker_result in rx {Revert back to master statesharkdpbefore adoptionbfc8c42
lines 198–199why, one step back198 match worker_result {199 WorkerResult::Entry(value) => {Move snapcraft filesharkdpbefore adoptionafcdaf2
lines 200–209why, one step back200 match mode {201 ReceiverMode::Buffering => {202 buffer.push(value);203204 // Have we reached the maximum buffer size or maximum buffering time?205 if buffer.len() > MAX_BUFFER_LENGTH206 || time::Instant::now() - start > max_buffer_time207 {208 // Flush the buffer209 for v in &buffer {Lock stdout only oncesharkdpbefore adoption8cfdcf4
lines 210–212why, one step back210 output::print_entry(211 &mut stdout,212 v,Uniform names for config and wants_to_quit. Pass Arc's by ref.Alexandru Macoveibefore adoptiondf4227c
lines 213–214why, one step back213 &config,214 &wants_to_quit,Lock stdout only oncesharkdpbefore adoption8cfdcf4
line 215why, one step back215 );Move snapcraft filesharkdpbefore adoptionafcdaf2
lines 216–223why, one step back216 }217 buffer.clear();218219 // Start streaming220 mode = ReceiverMode::Streaming;221 }222 }223 ReceiverMode::Streaming => {Uniform names for config and wants_to_quit. Pass Arc's by ref.Alexandru Macoveibefore adoptiondf4227c
line 224why, one step back224 output::print_entry(&mut stdout, &value, &config, &wants_to_quit);Move snapcraft filesharkdpbefore adoptionafcdaf2
lines 225–226why, one step back225 }226 }Add --max-results=<count> optionsharkdpbefore adoptiond43827f
lines 227–228why, one step back227228 num_results += 1;Move snapcraft filesharkdpbefore adoptionafcdaf2
line 229why, one step back229 }Revert back to master statesharkdpbefore adoptionbfc8c42
line 230why, one step back230 WorkerResult::Error(err) => {Move snapcraft filesharkdpbefore adoptionafcdaf2
line 231why, one step back231 if show_filesystem_errors {Proper error handling within walk.rssharkdpbefore adoption4590ae8
line 232why, one step back232 print_error(err.to_string());Move snapcraft filesharkdpbefore adoptionafcdaf2
line 233why, one step back233 }Add --max-results=<count> optionsharkdpbefore adoptiond43827f
lines 234–239why, one step back234 }235 }236237 if let Some(max_results) = config.max_results {238 if num_results >= max_results {239 break;Move snapcraft filesharkdpbefore adoptionafcdaf2
lines 240–248why, one step back240 }241 }242 }243244 // If we have finished fast enough (faster than max_buffer_time), we haven't streamed245 // anything to the console, yet. In this case, sort the results and print them:246 if !buffer.is_empty() {247 buffer.sort();248 for value in buffer {Uniform names for config and wants_to_quit. Pass Arc's by ref.Alexandru Macoveibefore adoptiondf4227c
line 249why, one step back249 output::print_entry(&mut stdout, &value, &config, &wants_to_quit);Move snapcraft filesharkdpbefore adoptionafcdaf2
lines 250–251why, one step back250 }251 }Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
lines 252–253why, one step back252253 ExitCode::SuccessMove snapcraft filesharkdpbefore adoptionafcdaf2
line 254why, one step back254 }split spawn_receiver(..) and spawn_senders(..) from scan(..).Alexandru Macoveibefore adoption5ade72a
lines 255–256why, one step back255 })256}Move snapcraft filesharkdpbefore adoptionafcdaf2
line 257why, one step back257New implementation of broken-symlink handlingsharkdpbefore adoptionbbf0f1c
lines 258–285why, one step back258pub enum DirEntry {259 Normal(ignore::DirEntry),260 BrokenSymlink(PathBuf),261}262263impl DirEntry {264 pub fn path(&self) -> &Path {265 match self {266 DirEntry::Normal(e) => e.path(),267 DirEntry::BrokenSymlink(pathbuf) => pathbuf.as_path(),268 }269 }270271 pub fn file_type(&self) -> Option<FileType> {272 match self {273 DirEntry::Normal(e) => e.file_type(),274 DirEntry::BrokenSymlink(pathbuf) => {275 pathbuf.symlink_metadata().map(|m| m.file_type()).ok()276 }277 }278 }279280 pub fn metadata(&self) -> Option<Metadata> {281 match self {282 DirEntry::Normal(e) => e.metadata().ok(),283 DirEntry::BrokenSymlink(_) => None,284 }285 }Add --min-depth and --exact-depthsharkdpbefore adoptiond63c63b
lines 286–292why, one step back286287 pub fn depth(&self) -> Option<usize> {288 match self {289 DirEntry::Normal(e) => Some(e.depth()),290 DirEntry::BrokenSymlink(_) => None,291 }292 }New implementation of broken-symlink handlingsharkdpbefore adoptionbbf0f1c
lines 293–294why, one step back293}294split spawn_receiver(..) and spawn_senders(..) from scan(..).Alexandru Macoveibefore adoption5ade72a
line 295why, one step back295fn spawn_senders(Move FdOptions to Optionssharkdpbefore adoption65096a6
line 296why, one step back296 config: &Arc<Options>,Uniform names for config and wants_to_quit. Pass Arc's by ref.Alexandru Macoveibefore adoptiondf4227c
line 297why, one step back297 wants_to_quit: &Arc<AtomicBool>,split spawn_receiver(..) and spawn_senders(..) from scan(..).Alexandru Macoveibefore adoption5ade72a
lines 298–301why, one step back298 pattern: Arc<Regex>,299 parallel_walker: ignore::WalkParallel,300 tx: Sender<WorkerResult>,301) {Move snapcraft filesharkdpbefore adoptionafcdaf2
line 302why, one step back302 parallel_walker.run(|| {Uniform names for config and wants_to_quit. Pass Arc's by ref.Alexandru Macoveibefore adoptiondf4227c
line 303why, one step back303 let config = Arc::clone(config);Move snapcraft filesharkdpbefore adoptionafcdaf2
lines 304–305why, one step back304 let pattern = Arc::clone(&pattern);305 let tx_thread = tx.clone();Uniform names for config and wants_to_quit. Pass Arc's by ref.Alexandru Macoveibefore adoptiondf4227c
line 306why, one step back306 let wants_to_quit = Arc::clone(wants_to_quit);Move snapcraft filesharkdpbefore adoptionafcdaf2
lines 307–313why, one step back307308 Box::new(move |entry_o| {309 if wants_to_quit.load(Ordering::Relaxed) {310 return ignore::WalkState::Quit;311 }312313 let entry = match entry_o {Fix for older versions of Rustsharkdpbefore adoptiond05e717
line 314why, one step back314 Ok(ref e) if e.depth() == 0 => {New implementation of broken-symlink handlingsharkdpbefore adoptionbbf0f1c
lines 315–322why, one step back315 // Skip the root directory entry.316 return ignore::WalkState::Continue;317 }318 Ok(e) => DirEntry::Normal(e),319 Err(ignore::Error::WithPath {320 path,321 err: inner_err,322 }) => match inner_err.as_ref() {Add additional check for symlinksharkdpbefore adoption81dee25
lines 323–326why, one step back323 ignore::Error::Io(io_error)324 if io_error.kind() == io::ErrorKind::NotFound325 && path326 .symlink_metadata()Fix for older versions of Rustsharkdpbefore adoptiond05e717
line 327why, one step back327 .ok()Add additional check for symlinksharkdpbefore adoption81dee25
lines 328–329why, one step back328 .map_or(false, |m| m.file_type().is_symlink()) =>329 {Solve clippy issuessharkdpbefore adoptionb9d0e72
line 330why, one step back330 DirEntry::BrokenSymlink(path)New implementation of broken-symlink handlingsharkdpbefore adoptionbbf0f1c
lines 331–341why, one step back331 }332 _ => {333 tx_thread334 .send(WorkerResult::Error(ignore::Error::WithPath {335 path,336 err: inner_err,337 }))338 .unwrap();339 return ignore::WalkState::Continue;340 }341 },Move snapcraft filesharkdpbefore adoptionafcdaf2
lines 342–346why, one step back342 Err(err) => {343 tx_thread.send(WorkerResult::Error(err)).unwrap();344 return ignore::WalkState::Continue;345 }346 };Add --min-depth and --exact-depthsharkdpbefore adoptiond63c63b
lines 347–352why, one step back347348 if let Some(min_depth) = config.min_depth {349 if entry.depth().map_or(true, |d| d < min_depth) {350 return ignore::WalkState::Continue;351 }352 }Move snapcraft filesharkdpbefore adoptionafcdaf2
line 353why, one step back353Check the pattern before anything else, since it doesn't require metadataTavian Barnesbefore adoption5cbd840
lines 354–356why, one step back354 // Check the name first, since it doesn't require metadata355 let entry_path = entry.path();356Use regex::bytes::* instead of regex::*sharkdpbefore adoption641594c
line 357why, one step back357 let search_str: Cow<OsStr> = if config.search_full_path {Proper error handling within walk.rssharkdpbefore adoption4590ae8
lines 358–360why, one step back358 let path_abs_buf = filesystem::path_absolute_form(entry_path)359 .expect("Retrieving absolute path succeeds");360 Cow::Owned(path_abs_buf.as_os_str().to_os_string())Check the pattern before anything else, since it doesn't require metadataTavian Barnesbefore adoption5cbd840
line 361why, one step back361 } else {Use regex::bytes::* instead of regex::*sharkdpbefore adoption641594c
lines 362–369why, one step back362 match entry_path.file_name() {363 Some(filename) => Cow::Borrowed(filename),364 None => unreachable!(365 "Encountered file system entry without a file name. This should only \366 happen for paths like 'foo/bar/..' or '/' which are not supposed to \367 appear in a file system traversal."368 ),369 }Check the pattern before anything else, since it doesn't require metadataTavian Barnesbefore adoption5cbd840
lines 370–371why, one step back370 };371Rename fshelper to filesystemsharkdpbefore adoptionb415d72
line 372why, one step back372 if !pattern.is_match(&filesystem::osstr_to_bytes(search_str.as_ref())) {Use regex::bytes::* instead of regex::*sharkdpbefore adoption641594c
line 373why, one step back373 return ignore::WalkState::Continue;Check the pattern before anything else, since it doesn't require metadataTavian Barnesbefore adoption5cbd840
lines 374–377why, one step back374 }375376 // Filter out unwanted extensions.377 if let Some(ref exts_regex) = config.extensions {Use regex::bytes::* instead of regex::*sharkdpbefore adoption641594c
line 378why, one step back378 if let Some(path_str) = entry_path.file_name() {Rename fshelper to filesystemsharkdpbefore adoptionb415d72
line 379why, one step back379 if !exts_regex.is_match(&filesystem::osstr_to_bytes(path_str)) {Check the pattern before anything else, since it doesn't require metadataTavian Barnesbefore adoption5cbd840
lines 380–386why, one step back380 return ignore::WalkState::Continue;381 }382 } else {383 return ignore::WalkState::Continue;384 }385 }386Move snapcraft filesharkdpbefore adoptionafcdaf2
lines 387–392why, one step back387 // Filter out unwanted file types.388 if let Some(ref file_types) = config.file_types {389 if let Some(ref entry_type) = entry.file_type() {390 if (!file_types.files && entry_type.is_file())391 || (!file_types.directories && entry_type.is_dir())392 || (!file_types.symlinks && entry_type.is_symlink())Add new `--type socket` and `--type pipe` filterssharkdpbefore adoptioncb56add
lines 393–394why, one step back393 || (!file_types.sockets && filesystem::is_socket(entry_type))394 || (!file_types.pipes && filesystem::is_pipe(entry_type))Move snapcraft filesharkdpbefore adoptionafcdaf2
lines 395–397why, one step back395 || (file_types.executables_only396 && !entry397 .metadata()Rename fshelper to filesystemsharkdpbefore adoptionb415d72
line 398why, one step back398 .map(|m| filesystem::is_executable(&m))Move snapcraft filesharkdpbefore adoptionafcdaf2
line 399why, one step back399 .unwrap_or(false))Rename fshelper to filesystemsharkdpbefore adoptionb415d72
line 400why, one step back400 || (file_types.empty_only && !filesystem::is_empty(&entry))Add new `--type socket` and `--type pipe` filterssharkdpbefore adoptioncb56add
lines 401–405why, one step back401 || !(entry_type.is_file()402 || entry_type.is_dir()403 || entry_type.is_symlink()404 || filesystem::is_socket(entry_type)405 || filesystem::is_pipe(entry_type))Move snapcraft filesharkdpbefore adoptionafcdaf2
lines 406–414why, one step back406 {407 return ignore::WalkState::Continue;408 }409 } else {410 return ignore::WalkState::Continue;411 }412 }413414 // Filter out unwanted sizes if it is a file and we have been given size constraints.fix most clippy lintsAlexandru Macoveibefore adoptionfe53af0
line 415why, one step back415 if !config.size_constraints.is_empty() {Move snapcraft filesharkdpbefore adoptionafcdaf2
lines 416–436why, one step back416 if entry_path.is_file() {417 if let Ok(metadata) = entry_path.metadata() {418 let file_size = metadata.len();419 if config420 .size_constraints421 .iter()422 .any(|sc| !sc.is_within(file_size))423 {424 return ignore::WalkState::Continue;425 }426 } else {427 return ignore::WalkState::Continue;428 }429 } else {430 return ignore::WalkState::Continue;431 }432 }433434 // Filter out unwanted modification times435 if !config.time_constraints.is_empty() {436 let mut matched = false;Make --changed-within/before work for directoriessharkdpbefore adoption08fcd7c
lines 437–442why, one step back437 if let Ok(metadata) = entry_path.metadata() {438 if let Ok(modified) = metadata.modified() {439 matched = config440 .time_constraints441 .iter()442 .all(|tf| tf.applies_to(&modified));Move snapcraft filesharkdpbefore adoptionafcdaf2
lines 443–449why, one step back443 }444 }445 if !matched {446 return ignore::WalkState::Continue;447 }448 }449Formattingsharkdpbefore adoptionf7d1938
line 450why, one step back450 let send_result = tx_thread.send(WorkerResult::Entry(entry_path.to_owned()));Quit immediately if the channel::send call failedsharkdpbefore adoption0f27485
line 451why, one step back451Solve clippy issuessharkdpbefore adoptionb9d0e72
line 452why, one step back452 if send_result.is_err() {Quit immediately if the channel::send call failedsharkdpbefore adoption0f27485
lines 453–454why, one step back453 return ignore::WalkState::Quit;454 }Move snapcraft filesharkdpbefore adoptionafcdaf2
lines 455–459why, one step back455456 ignore::WalkState::Continue457 })458 });459}