Dedupe identical target paths and case-fold nesting in directory scans - #189
Dedupe identical target paths and case-fold nesting in directory scans#189mazen-salah wants to merge 2 commits into
Conversation
Two identical target paths both survived (the self-comparison was skipped), producing duplicate findings the function is meant to prevent; and the child-of check was case-sensitive, so nesting was missed on case-insensitive filesystems (Windows). Track kept paths to drop exact duplicates and normalize the comparison key (lowercased on Windows). Adds tests.
|
| Filename | Overview |
|---|---|
| cmd/directory.go | Dedup + case-fold logic is correct for Windows; pathKey skips macOS (also case-insensitive by default on APFS) |
| cmd/directory_test.go | New tests cover dedup and Windows case-folding; non-Windows branch is correctly guarded |
Reviews (1): Last reviewed commit: "dedupe identical paths and case-fold nes..." | Re-trigger Greptile
| func pathKey(p string) string { | ||
| if runtime.GOOS == "windows" { | ||
| return strings.ToLower(p) | ||
| } | ||
| return p | ||
| } |
There was a problem hiding this comment.
macOS with APFS (the default since 2017) is case-insensitive, so the nesting check will still miss
"Foo" vs "foo/sub" there. runtime.GOOS == "windows" is correct for Windows, but the same issue exists on macOS for most users. Consider extending the condition, or detecting case-sensitivity at runtime via a stat-based probe.
| func pathKey(p string) string { | |
| if runtime.GOOS == "windows" { | |
| return strings.ToLower(p) | |
| } | |
| return p | |
| } | |
| func pathKey(p string) string { | |
| if runtime.GOOS == "windows" || runtime.GOOS == "darwin" { | |
| return strings.ToLower(p) | |
| } | |
| return p | |
| } |
removeNestedPathsis meant to drop overlapping/duplicate scan targets, but two identical paths both survived (the self-comparison was skipped), producing duplicate findings; and the child-of check was case-sensitive, so nesting was missed on case-insensitive filesystems (Windows).Track kept paths to drop exact duplicates and normalize the comparison key (lowercased on Windows). Adds tests.