Skip to content

Commit

Permalink
Only reset a directory's times if it has files under it
Browse files Browse the repository at this point in the history
This avoids unnessisary work when a directory doesn't directly contain a file
we're going to compress.
  • Loading branch information
Dr-Emann committed Apr 15, 2024
1 parent 264640f commit 61571bd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
7 changes: 5 additions & 2 deletions crates/applesauce/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,12 @@ impl TimeReset for File {
}
}

#[tracing::instrument(level = "debug", skip_all)]
#[tracing::instrument(level = "debug", skip(metadata))]
#[inline]
fn reset_times<F: TimeReset + ?Sized>(f: &F, metadata: &Metadata) -> io::Result<()> {
fn reset_times<F: TimeReset + std::fmt::Debug + ?Sized>(
f: &F,
metadata: &Metadata,
) -> io::Result<()> {
f.reset_times(metadata)
}

Expand Down
13 changes: 9 additions & 4 deletions crates/applesauce/src/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ fn walk_dir_over(
path: &Path,
_state,
entries: &mut Vec<jwalk::Result<jwalk::DirEntry<((), State)>>>| {
let reset_times: State = path
.metadata()
.ok()
.map(|metadata| Arc::new(ResetTimes::new(path, metadata)));
let mut reset_times: Option<State> = None;
// Remove ignored directories from the list of entries.
// Also, add the client state to the entry.
entries.retain_mut(|entry| {
Expand All @@ -51,6 +48,14 @@ fn walk_dir_over(
}
#[allow(clippy::filetype_is_file)]
if entry.file_type().is_file() {
let reset_times = match &mut reset_times {
Some(reset_times) => reset_times,
None => reset_times.insert(
path.metadata()
.ok()
.map(|metadata| Arc::new(ResetTimes::new(path, metadata))),
),
};
entry.client_state.clone_from(&reset_times);
}
}
Expand Down

0 comments on commit 61571bd

Please sign in to comment.