7
7
"context"
8
8
"errors"
9
9
"fmt"
10
- "maps"
11
10
"os"
12
11
"path/filepath"
13
12
"slices"
@@ -24,7 +23,9 @@ import (
24
23
"github.com/zarf-dev/zarf/src/pkg/zoci"
25
24
)
26
25
27
- func resolveImports (ctx context.Context , pkg v1alpha1.ZarfPackage , packagePath , arch , flavor string , seenImports map [string ]interface {}) (v1alpha1.ZarfPackage , error ) {
26
+ func resolveImports (ctx context.Context , pkg v1alpha1.ZarfPackage , packagePath , arch , flavor string , importStack []string ) (v1alpha1.ZarfPackage , error ) {
27
+ importStack = append (importStack , packagePath )
28
+
28
29
variables := pkg .Variables
29
30
constants := pkg .Constants
30
31
components := []v1alpha1.ZarfComponent {}
@@ -47,12 +48,11 @@ func resolveImports(ctx context.Context, pkg v1alpha1.ZarfPackage, packagePath,
47
48
var importedPkg v1alpha1.ZarfPackage
48
49
if component .Import .Path != "" {
49
50
importPath := filepath .Join (packagePath , component .Import .Path )
50
- importKey := fmt .Sprintf ("%s-%s" , component .Name , importPath )
51
- if _ , ok := seenImports [importKey ]; ok {
52
- return v1alpha1.ZarfPackage {}, fmt .Errorf ("package %s imported in cycle by %s in component %s" , filepath .ToSlash (importPath ), filepath .ToSlash (packagePath ), component .Name )
51
+ for _ , sp := range importStack {
52
+ if sp == importPath {
53
+ return v1alpha1.ZarfPackage {}, fmt .Errorf ("package %s imported in cycle by %s in component %s" , filepath .ToSlash (importPath ), filepath .ToSlash (packagePath ), component .Name )
54
+ }
53
55
}
54
- seenImports = maps .Clone (seenImports )
55
- seenImports [importKey ] = nil
56
56
b , err := os .ReadFile (filepath .Join (importPath , layout .ZarfYAML ))
57
57
if err != nil {
58
58
return v1alpha1.ZarfPackage {}, err
@@ -61,7 +61,7 @@ func resolveImports(ctx context.Context, pkg v1alpha1.ZarfPackage, packagePath,
61
61
if err != nil {
62
62
return v1alpha1.ZarfPackage {}, err
63
63
}
64
- importedPkg , err = resolveImports (ctx , importedPkg , importPath , arch , flavor , seenImports )
64
+ importedPkg , err = resolveImports (ctx , importedPkg , importPath , arch , flavor , importStack )
65
65
if err != nil {
66
66
return v1alpha1.ZarfPackage {}, err
67
67
}
@@ -91,7 +91,7 @@ func resolveImports(ctx context.Context, pkg v1alpha1.ZarfPackage, packagePath,
91
91
}
92
92
}
93
93
if len (found ) == 0 {
94
- return v1alpha1.ZarfPackage {}, fmt .Errorf ("component %s not found" , name )
94
+ return v1alpha1.ZarfPackage {}, fmt .Errorf ("no compatible component named %s found" , name )
95
95
} else if len (found ) > 1 {
96
96
return v1alpha1.ZarfPackage {}, fmt .Errorf ("multiple components named %s found" , name )
97
97
}
@@ -122,7 +122,7 @@ func resolveImports(ctx context.Context, pkg v1alpha1.ZarfPackage, packagePath,
122
122
pkg .Constants = slices .CompactFunc (constants , func (l , r v1alpha1.Constant ) bool {
123
123
return l .Name == r .Name
124
124
})
125
-
125
+ importStack = importStack [ 0 : len ( importStack ) - 1 ]
126
126
return pkg , nil
127
127
}
128
128
0 commit comments