Skip to content

Commit

Permalink
refactor(utils/fs): hoist ignore conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
egasimus authored and Bergmann89 committed Mar 7, 2024
1 parent 97065cc commit 3d838ef
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions src/utils/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ pub fn copy_files_except_ext(
.metadata()
.with_context(|| format!("Failed to read {:?}", entry.path()))?;

// Check if it is in the blacklist
if let Some(ignore) = ignore {
let path = entry.path();
if ignore.matched(&path, path.is_dir()).is_ignore() {
continue;
}
}

// If the entry is a dir and the recursive option is enabled, call itself
if metadata.is_dir() && recursive {
if entry.path() == to.to_path_buf() {
Expand All @@ -127,13 +135,6 @@ pub fn copy_files_except_ext(
}
}

if let Some(ignore) = ignore {
let path = entry.path();
if ignore.matched(&path, path.is_dir()).is_ignore() {
continue;
}
}

// check if output dir already exists
if !to.join(entry.file_name()).exists() {
fs::create_dir(&to.join(entry.file_name()))?;
Expand All @@ -147,14 +148,6 @@ pub fn copy_files_except_ext(
ignore,
)?;
} else if metadata.is_file() {
// Check if it is in the blacklist
if let Some(ignore) = ignore {
let path = entry.path();
if ignore.matched(&path, path.is_dir()).is_ignore() {
continue;
}
}

debug!(
"creating path for file: {:?}",
&to.join(
Expand Down

0 comments on commit 3d838ef

Please sign in to comment.