Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions crates/forge_services/src/fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,31 @@ pub(crate) fn has_allowed_extension(path: &Path) -> bool {
}
}

/// Returns `true` if the file at `path` should be excluded based on its name,
/// regardless of extension. This covers lock files and other generated
/// dependency manifest files that are not useful to index.
fn is_ignored_by_name(path: &Path) -> bool {
let Some(name) = path.file_name().and_then(|n| n.to_str()) else {
return false;
};
let name_lower = name.to_lowercase();

// Lock files: *-lock.json, *.lock, *.lockb, *.lock.json, etc.
if name_lower.ends_with(".lock")
|| name_lower.ends_with(".lockb")
|| name_lower.ends_with("-lock.json")
|| name_lower.ends_with("-lock.yaml")
|| name_lower.ends_with("-lock.yml")
|| name_lower.ends_with(".lock.json")
|| name_lower.ends_with(".lockfile")
|| name == "Package.resolved"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent case-sensitivity check. Line 50 uses name (case-sensitive) while all other checks use name_lower (case-insensitive). This will fail to filter out variations like "package.resolved" or "PACKAGE.RESOLVED".

Fix by using the lowercase version:

|| name_lower == "package.resolved"
Suggested change
|| name == "Package.resolved"
|| name_lower == "package.resolved"

Spotted by Graphite

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

{
return true;
}

false
}

/// Returns `true` if `path` is a symlink (does not follow the link).
fn is_symlink(path: &Path) -> bool {
path.symlink_metadata()
Expand All @@ -53,6 +78,7 @@ pub(crate) fn filter_and_resolve(
.into_iter()
.map(|p| dir_path.join(&p))
.filter(|p| !is_symlink(p))
.filter(|p| !is_ignored_by_name(p))
.filter(|p| has_allowed_extension(p))
.collect();

Expand Down
Loading