+11
-4
src/cmd/glob.rs
+11
-4
src/cmd/glob.rs
···
160
160
161
161
// Recursively walk into subdirectories
162
162
if metadata.file_type == VfsFileType::Directory {
163
-
// Continue if: recursive pattern, or we haven't reached max depth, or pattern has more components
163
+
// Only recurse if:
164
+
// 1. Pattern contains ** (recursive wildcard), OR
165
+
// 2. Pattern has path separators and we haven't matched all components yet
166
+
let has_path_separator = normalized_pattern.contains('/');
167
+
let pattern_component_count = if has_path_separator {
168
+
normalized_pattern.split('/').count()
169
+
} else {
170
+
1
171
+
};
172
+
164
173
let should_recurse = is_recursive
165
-
|| current_depth < max_depth
166
-
|| (normalized_pattern.contains('/')
167
-
&& current_depth < normalized_pattern.split('/').count());
174
+
|| (has_path_separator && current_depth + 1 < pattern_component_count);
168
175
169
176
if should_recurse {
170
177
walk_directory(