Skip to content

Commit

Permalink
Refactor handling of relative paths in ProcessImportSection
Browse files Browse the repository at this point in the history
  • Loading branch information
milldr committed Dec 24, 2024
1 parent f79e16a commit 74ab1d8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/tests/stacks/orgs/cp/tenant1/test2/_defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

import:
- mixins/stage/test2
- ../_defaults # validate relative paths
- ./../_defaults # validate relative paths
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

import:
- mixins/region/global-region
- _defaults # validate relative paths
- ./_defaults # validate relative paths
8 changes: 4 additions & 4 deletions internal/exec/stack_processor_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1786,12 +1786,12 @@ func ProcessImportSection(stackMap map[string]any, filePath string) ([]schema.St
return nil, fmt.Errorf("invalid empty import in the file '%s'", filePath)
}

// Handle relative paths
if !filepath.IsAbs(s) && !strings.Contains(s, "://") {
// Handle relative paths - only if they explicitly start with "./"
if strings.HasPrefix(s, "./") {
// Get the directory of the current file
baseDir := filepath.Dir(filePath)
// Join the base directory with the relative path
s = filepath.Join(baseDir, s)
// Join the base directory with the relative path (removing the "./" prefix)
s = filepath.Join(baseDir, s[2:])
}

result = append(result, schema.StackImport{Path: s})
Expand Down

0 comments on commit 74ab1d8

Please sign in to comment.