From 3d838ef8e62f5e950fcc83d7459665cd981141b9 Mon Sep 17 00:00:00 2001 From: Adam Avramov Date: Sun, 3 Sep 2023 09:07:37 +0300 Subject: [PATCH] refactor(utils/fs): hoist ignore conditional --- src/utils/fs.rs | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/utils/fs.rs b/src/utils/fs.rs index 93299e8c..4f46f590 100644 --- a/src/utils/fs.rs +++ b/src/utils/fs.rs @@ -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() { @@ -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()))?; @@ -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(