Skip to content

Commit 8bc316a

Browse files
committed
fix(git_discovery): collect all nested modules subtrees, not just the last
Closes #211. `find_git_module_info_dirs::walk` tracked the nested \`modules\` dir in a single \`Option<PathBuf>\`, so a directory listing that yielded more than one entry whose \`file_name()\` matched \`modules\` would keep only the last one walked. The case is unusual on case-sensitive filesystems but reachable on case-insensitive ones (macOS / NTFS) where \`modules\` and \`Modules\` can collide as dir entries from different writers, and a future relax of the equality match (icase, alt names) would silently start dropping subtrees. Replace the \`Option<PathBuf>\` with a \`Vec<PathBuf>\` and walk each collected nested-modules dir in turn. The \`return\` on the inner \`fs::read_dir\` error becomes a \`continue\` so a single unreadable nested dir no longer aborts the walk for sibling subtrees in the same parent. `cargo test --lib policy::git_discovery` is green (3/3, including \`test_find_git_module_info_dirs_finds_nested_submodules\`).
1 parent 34228f9 commit 8bc316a

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

sdk/src/policy/git_discovery.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@ pub fn find_git_module_info_dirs(dot_git_dir: &Path) -> Vec<PathBuf> {
2121
};
2222

2323
let mut has_info = false;
24-
let mut nested_modules = None;
24+
// Pre-#211 this was a single `Option<PathBuf>`, so a directory
25+
// listing that yielded more than one entry whose `file_name()`
26+
// matched `modules` would only keep the last one walked. The case
27+
// is unusual on case-sensitive filesystems but reachable on
28+
// case-insensitive ones (macOS / NTFS) where `modules` and
29+
// `Modules` can collide as dir entries from different writers,
30+
// and a future relax of the equality match (icase, alt names)
31+
// would silently start dropping subtrees. Collect them all.
32+
let mut nested_modules_dirs: Vec<PathBuf> = Vec::new();
2533

2634
for entry in entries.flatten() {
2735
let name = entry.file_name();
@@ -35,18 +43,18 @@ pub fn find_git_module_info_dirs(dot_git_dir: &Path) -> Vec<PathBuf> {
3543
&& let Ok(ft) = entry.file_type()
3644
&& ft.is_dir()
3745
{
38-
nested_modules = Some(entry.path());
46+
nested_modules_dirs.push(entry.path());
3947
}
4048
}
4149

4250
if has_info {
4351
results.push(dir.join("info"));
4452
}
4553

46-
if let Some(nested) = nested_modules {
54+
for nested in nested_modules_dirs {
4755
let sub_entries = match fs::read_dir(&nested) {
4856
Ok(e) => e,
49-
Err(_) => return,
57+
Err(_) => continue,
5058
};
5159
for entry in sub_entries.flatten() {
5260
if let Ok(ft) = entry.file_type()

0 commit comments

Comments
 (0)