Skip to content

Commit 0241ffb

Browse files
authored
chore: Backporting #5477 (#5567)
* chore: Backporting #5477 * fix: Addressing lint findings * fix: Adjusting assertion for test case
1 parent 0a6a0ec commit 0241ffb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+11072
-7451
lines changed

internal/component/component.go

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
package component
99

1010
import (
11-
"path/filepath"
1211
"slices"
1312
"sort"
1413
"sync"
1514

1615
"github.com/gruntwork-io/terragrunt/internal/errors"
16+
"github.com/gruntwork-io/terragrunt/internal/util"
1717
)
1818

1919
// Kind is the type of Terragrunt component.
@@ -255,7 +255,7 @@ func NewThreadSafeComponents(components Components) *ThreadSafeComponents {
255255

256256
// Pre-populate resolved paths cache for initial components
257257
for _, c := range components {
258-
tsc.resolvedPaths[c.Path()] = resolvePath(c.Path())
258+
tsc.resolvedPaths[c.Path()] = util.ResolvePath(c.Path())
259259
}
260260

261261
return tsc
@@ -269,7 +269,7 @@ func (tsc *ThreadSafeComponents) resolvedPathFor(path string) string {
269269
return resolved
270270
}
271271

272-
return resolvePath(path)
272+
return util.ResolvePath(path)
273273
}
274274

275275
// EnsureComponent adds a component to the components list if it's not already present.
@@ -293,7 +293,7 @@ func (tsc *ThreadSafeComponents) findComponent(c Component) (Component, bool) {
293293
tsc.mu.RLock()
294294
defer tsc.mu.RUnlock()
295295

296-
searchResolved := resolvePath(c.Path())
296+
searchResolved := util.ResolvePath(c.Path())
297297

298298
idx := slices.IndexFunc(tsc.components, func(cc Component) bool {
299299
return tsc.resolvedPathFor(cc.Path()) == searchResolved
@@ -313,7 +313,7 @@ func (tsc *ThreadSafeComponents) addComponent(c Component) (Component, bool) {
313313
tsc.mu.Lock()
314314
defer tsc.mu.Unlock()
315315

316-
searchResolved := resolvePath(c.Path())
316+
searchResolved := util.ResolvePath(c.Path())
317317

318318
// Do one last check to see if the component is already in the components list
319319
// to avoid a TOCTOU race condition. Uses resolved paths for comparison.
@@ -339,7 +339,7 @@ func (tsc *ThreadSafeComponents) FindByPath(path string) Component {
339339
tsc.mu.RLock()
340340
defer tsc.mu.RUnlock()
341341

342-
resolvedSearchPath := resolvePath(path)
342+
resolvedSearchPath := util.ResolvePath(path)
343343

344344
for _, c := range tsc.components {
345345
if tsc.resolvedPathFor(c.Path()) == resolvedSearchPath {
@@ -369,14 +369,3 @@ func (tsc *ThreadSafeComponents) Len() int {
369369

370370
return len(tsc.components)
371371
}
372-
373-
// resolvePath resolves symlinks in a path for consistent comparison across platforms.
374-
// On macOS, /var is a symlink to /private/var, so paths must be resolved.
375-
func resolvePath(path string) string {
376-
resolved, err := filepath.EvalSymlinks(path)
377-
if err != nil {
378-
return path
379-
}
380-
381-
return resolved
382-
}

internal/discovery/constructor.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func NewForDiscoveryCommand(opts *DiscoveryCommandOptions) (*Discovery, error) {
6666
}
6767

6868
if opts.Include {
69-
d = d.WithParseInclude()
69+
d = d.WithParseIncludes()
7070
}
7171

7272
if opts.Reading {
@@ -142,21 +142,17 @@ func NewForStackGenerate(opts StackGenerateOptions) (*Discovery, error) {
142142
return d, nil
143143
}
144144

145-
// NewDiscovery creates a new Discovery.
146-
func NewDiscovery(dir string, opts ...DiscoveryOption) *Discovery {
145+
// NewDiscovery creates a new Discovery with sensible defaults.
146+
func NewDiscovery(dir string) *Discovery {
147147
numWorkers := max(min(runtime.NumCPU(), maxDiscoveryWorkers), defaultDiscoveryWorkers)
148148

149-
discovery := &Discovery{
149+
return &Discovery{
150150
numWorkers: numWorkers,
151151
maxDependencyDepth: defaultMaxDependencyDepth,
152+
workingDir: dir,
153+
configFilenames: DefaultConfigFilenames,
152154
discoveryContext: &component.DiscoveryContext{
153155
WorkingDir: dir,
154156
},
155157
}
156-
157-
for _, opt := range opts {
158-
opt(discovery)
159-
}
160-
161-
return discovery
162158
}

0 commit comments

Comments
 (0)