Skip to content

Commit 3d838ef

Browse files
egasimusBergmann89
authored andcommitted
refactor(utils/fs): hoist ignore conditional
1 parent 97065cc commit 3d838ef

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

src/utils/fs.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ pub fn copy_files_except_ext(
115115
.metadata()
116116
.with_context(|| format!("Failed to read {:?}", entry.path()))?;
117117

118+
// Check if it is in the blacklist
119+
if let Some(ignore) = ignore {
120+
let path = entry.path();
121+
if ignore.matched(&path, path.is_dir()).is_ignore() {
122+
continue;
123+
}
124+
}
125+
118126
// If the entry is a dir and the recursive option is enabled, call itself
119127
if metadata.is_dir() && recursive {
120128
if entry.path() == to.to_path_buf() {
@@ -127,13 +135,6 @@ pub fn copy_files_except_ext(
127135
}
128136
}
129137

130-
if let Some(ignore) = ignore {
131-
let path = entry.path();
132-
if ignore.matched(&path, path.is_dir()).is_ignore() {
133-
continue;
134-
}
135-
}
136-
137138
// check if output dir already exists
138139
if !to.join(entry.file_name()).exists() {
139140
fs::create_dir(&to.join(entry.file_name()))?;
@@ -147,14 +148,6 @@ pub fn copy_files_except_ext(
147148
ignore,
148149
)?;
149150
} else if metadata.is_file() {
150-
// Check if it is in the blacklist
151-
if let Some(ignore) = ignore {
152-
let path = entry.path();
153-
if ignore.matched(&path, path.is_dir()).is_ignore() {
154-
continue;
155-
}
156-
}
157-
158151
debug!(
159152
"creating path for file: {:?}",
160153
&to.join(

0 commit comments

Comments
 (0)