Skip to content

Commit

Permalink
fix(fs-index): refactor should_index
Browse files Browse the repository at this point in the history
Signed-off-by: Tarek <[email protected]>
  • Loading branch information
tareknaser committed Aug 6, 2024
1 parent 0e3cac8 commit e0f6e75
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions fs-index/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,11 @@ pub(crate) fn discover_paths<P: AsRef<Path>>(
) -> Result<Vec<DirEntry>> {
log::debug!("Discovering paths at root path: {:?}", root_path.as_ref());

let walker = WalkDir::new(&root_path)
.min_depth(1) // Skip the root directory
let paths = WalkDir::new(root_path)
.min_depth(1)
.into_iter()
.filter_entry(should_index); // Skip hidden files and empty files

// Filter out directories
let paths = walker
.filter_map(|entry| {
let entry = entry.ok()?;
if entry.file_type().is_file() {
Some(entry)
} else {
None
}
})
.filter_map(|e| e.ok())
.filter(|e| should_index(e))
.collect();

Ok(paths)
Expand Down Expand Up @@ -144,6 +134,7 @@ fn should_index(entry: &walkdir::DirEntry) -> bool {
.to_string_lossy()
.starts_with('.')
{
log::trace!("Ignoring hidden file: {:?}", entry.path());
return false;
}

Expand All @@ -153,6 +144,19 @@ fn should_index(entry: &walkdir::DirEntry) -> bool {
.map(|m| m.len() == 0)
.unwrap_or(false)
{
log::trace!("Ignoring empty file: {:?}", entry.path());
return false;
}

// Check if the entry isn't a file
if !entry.file_type().is_file() {
log::trace!("Ignoring non-file: {:?}", entry.path());
return false;
}

// Check if it's the index file
if entry.file_name() == INDEX_PATH {
log::trace!("Ignoring index file: {:?}", entry.path());
return false;
}

Expand Down

0 comments on commit e0f6e75

Please sign in to comment.