Skip to content

Commit a22c73f

Browse files
refactor: add another check for dotdirs when iterating the config tree (#2279)
<!-- Thanks for sending a pull request! Here are some tips for you: 1. If this is your first time, please read our contributor guidelines: https://github.com/terramate-io/terramate/blob/main/CONTRIBUTING.md 2. If the PR is unfinished, mark it as draft: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-stage-of-a-pull-request 3. Please update the PR title using the Conventional Commits convention: https://www.conventionalcommits.org/en/v1.0.0/ Example: feat: add support for XYZ. --> ## What this PR does / why we need it: Normally, dotdirs are skipped when parsing the config already, but in case of delayed loading via `LoadSubTree`, we can bypass this and still end up loading files from dotdirs. This PR adds an extra check to exclude dotdirs when visiting the config tree. This fixes a bug in Catalyst. ## Does this PR introduce a user-facing change? <!-- If no, just write "no" in the block below. If yes, please explain the change and update documentation and the CHANGELOG.md file accordingly. --> ``` no ``` <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Small, localized traversal refactor that only affects which tree nodes are visited; main risk is unintentionally excluding previously-visible stacks if callers relied on dotdir contents. > > **Overview** > Updates config tree traversal used by `Stacks()`, `StacksByPaths`, `StacksByTagsFilters`, and `StackByID` to skip dot-directories during DFS, even when nodes were introduced via `LoadSubTree`. > > This refactors the internal helper from `stacks()` to `visit()` and applies an explicit `Skip(name)` check while walking `Tree.Children`, preventing hidden directories from contributing stacks to query results. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit db0ac00. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2 parents 59268bf + db0ac00 commit a22c73f

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

config/config.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ func (root *Root) StacksByPaths(base project.Path, relpaths ...string) List[*Tre
281281
logger.Warn().Msgf("path %s not found in configuration", path.String())
282282
continue
283283
}
284-
stacks = append(stacks, node.stacks((*Tree).IsStack)...)
284+
stacks = append(stacks, node.visit((*Tree).IsStack)...)
285285
}
286286

287287
sort.Sort(stacks)
@@ -295,7 +295,7 @@ func (root *Root) StacksByTagsFilters(filters []string) (project.Paths, error) {
295295
if err != nil {
296296
return nil, err
297297
}
298-
return root.tree.stacks(func(tree *Tree) bool {
298+
return root.tree.visit(func(tree *Tree) bool {
299299
if !hasFilter || !tree.IsStack() {
300300
return false
301301
}
@@ -305,7 +305,7 @@ func (root *Root) StacksByTagsFilters(filters []string) (project.Paths, error) {
305305

306306
// StackByID returns the stack with the given ID.
307307
func (root *Root) StackByID(id string) (*Stack, bool, error) {
308-
stacks := root.tree.stacks(func(tree *Tree) bool {
308+
stacks := root.tree.visit(func(tree *Tree) bool {
309309
return tree.IsStack() && tree.Node.Stack.ID == id
310310
})
311311
if len(stacks) == 0 {
@@ -477,7 +477,7 @@ func (tree *Tree) Stack() (*Stack, error) {
477477
// Stacks returns the stack nodes from the tree.
478478
// The search algorithm is a Deep-First-Search (DFS).
479479
func (tree *Tree) Stacks() List[*Tree] {
480-
stacks := tree.stacks((*Tree).IsStack)
480+
stacks := tree.visit((*Tree).IsStack)
481481
sort.Sort(stacks)
482482
return stacks
483483
}
@@ -517,15 +517,17 @@ func (tree *Tree) TerragruntModule() (*tg.Module, error) {
517517
return nil, nil
518518
}
519519

520-
func (tree *Tree) stacks(cond func(*Tree) bool) List[*Tree] {
521-
var stacks List[*Tree]
520+
func (tree *Tree) visit(cond func(*Tree) bool) List[*Tree] {
521+
var r List[*Tree]
522522
if cond(tree) {
523-
stacks = append(stacks, tree)
523+
r = append(r, tree)
524524
}
525-
for _, children := range tree.Children {
526-
stacks = append(stacks, children.stacks(cond)...)
525+
for name, child := range tree.Children {
526+
if !Skip(name) {
527+
r = append(r, child.visit(cond)...)
528+
}
527529
}
528-
return stacks
530+
return r
529531
}
530532

531533
// Lookup a node from the tree using a filesystem query path.

0 commit comments

Comments
 (0)