88package component
99
1010import (
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- }
0 commit comments