Reduce unnecessary stat calls for max_filesize

This commit is contained in:
Marc Tiehuis 2017-03-01 18:01:46 +13:00 committed by Andrew Gallant
parent 714ae82241
commit 71585f6d47

View File

@ -682,9 +682,16 @@ impl Walk {
return false; return false;
} }
let ft = ent.file_type().is_dir(); let is_dir = ent.file_type().is_dir();
skip_path(&self.ig, ent.path(), ft) || let max_size = self.max_filesize;
skip_filesize(self.max_filesize, ent.path(), &ent.metadata().ok(), ft) let should_skip_path = skip_path(&self.ig, ent.path(), is_dir);
let should_skip_filesize = if !is_dir && max_size.is_some() {
skip_filesize(max_size.unwrap(), ent.path(), &ent.metadata().ok())
} else {
false
};
should_skip_path || should_skip_filesize
} }
} }
@ -1128,10 +1135,15 @@ impl Worker {
} }
} }
let is_dir = dent.file_type().map_or(false, |ft| ft.is_dir()); let is_dir = dent.file_type().map_or(false, |ft| ft.is_dir());
if !skip_path(ig, dent.path(), is_dir) && let max_size = self.max_filesize;
!skip_filesize(self.max_filesize, dent.path(), let should_skip_path = skip_path(ig, dent.path(), is_dir);
&dent.metadata().ok(), is_dir) let should_skip_filesize = if !is_dir && max_size.is_some() {
{ skip_filesize(max_size.unwrap(), dent.path(), &dent.metadata().ok())
} else {
false
};
if !should_skip_path && !should_skip_filesize {
self.queue.push(Message::Work(Work { self.queue.push(Message::Work(Work {
dent: dent, dent: dent,
ignore: ig.clone(), ignore: ig.clone(),
@ -1278,31 +1290,27 @@ fn check_symlink_loop(
Ok(()) Ok(())
} }
// Before calling this function, make sure that you ensure that is really
// necessary as the arguments imply a file stat.
fn skip_filesize( fn skip_filesize(
max_filesize: Option<u64>, max_filesize: u64,
path: &Path, path: &Path,
ent: &Option<Metadata>, ent: &Option<Metadata>
is_dir: bool
) -> bool { ) -> bool {
if is_dir {
return false;
}
let filesize = match *ent { let filesize = match *ent {
Some(ref md) => Some(md.len()), Some(ref md) => Some(md.len()),
None => None None => None
}; };
match (filesize, max_filesize) { if let Some(fs) = filesize {
(Some(fs), Some(m_fs)) => { if fs > max_filesize {
if fs > m_fs { debug!("ignoring {}: {} bytes", path.display(), fs);
debug!("ignoring {}: {} bytes", path.display(), fs); true
true } else {
} else { false
false
}
} }
_ => false } else {
false
} }
} }