Skip to content

Commit 3435a45

Browse files
committed
add some missing filepath.Clean() invocations
1 parent 2b53ce8 commit 3435a45

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

pkg/manifests/helm.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func NewHelmGenerator(name string, fsys fs.FS, chartPath string, client client.C
9393
return nil, err
9494
}
9595

96-
crds, err := find(fsys, chartPath+"/crds", "*.yaml", fileTypeRegular, 0)
96+
crds, err := find(fsys, filepath.Clean(chartPath+"/crds"), "*.yaml", fileTypeRegular, 0)
9797
if err != nil {
9898
return nil, err
9999
}
@@ -105,12 +105,12 @@ func NewHelmGenerator(name string, fsys fs.FS, chartPath string, client client.C
105105
g.crds = append(g.crds, raw)
106106
}
107107

108-
includes, err := find(fsys, chartPath+"/templates", "_*", fileTypeRegular, 0)
108+
includes, err := find(fsys, filepath.Clean(chartPath+"/templates"), "_*", fileTypeRegular, 0)
109109
if err != nil {
110110
return nil, err
111111
}
112112

113-
manifests, err := find(fsys, chartPath+"/templates", "[^_]*.yaml", fileTypeRegular, 0)
113+
manifests, err := find(fsys, filepath.Clean(chartPath+"/templates"), "[^_]*.yaml", fileTypeRegular, 0)
114114
if err != nil {
115115
return nil, err
116116
}
@@ -120,7 +120,7 @@ func NewHelmGenerator(name string, fsys fs.FS, chartPath string, client client.C
120120

121121
// TODO: for now, one level of library subcharts is supported
122122
// we should enhance the support of subcharts (nested charts, application charts)
123-
subChartPaths, err := find(fsys, chartPath+"/charts", "*", fileTypeDir, 1)
123+
subChartPaths, err := find(fsys, filepath.Clean(chartPath+"/charts"), "*", fileTypeDir, 1)
124124
if err != nil {
125125
return nil, err
126126
}
@@ -136,7 +136,7 @@ func NewHelmGenerator(name string, fsys fs.FS, chartPath string, client client.C
136136
if subChartData.Type != helm.ChartTypeLibrary {
137137
return nil, fmt.Errorf("only library subcharts are supported (path: %s)", subChartPath)
138138
}
139-
subIncludes, err := find(fsys, subChartPath+"/templates", "_*", fileTypeRegular, 0)
139+
subIncludes, err := find(fsys, filepath.Clean(subChartPath+"/templates"), "_*", fileTypeRegular, 0)
140140
if err != nil {
141141
return nil, err
142142
}

pkg/manifests/util.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,25 @@ func fileTypeFromMode(mode fs.FileMode) uint {
8888
// Resulting paths will be always relative to fsys (cleaned, with no leading dot).
8989
// The parameter dir must not contain any dot or double dot, unless it equals '.' in which case the whole fsys will be searched.
9090
// As an alternative, dir can be empty (which is equivalent to dir == '.').
91+
// Parameters namePattern and fileType may be optionally set to filter the result; namePattern must be a file pattern
92+
// (not containing any slashes) and will be matched using path.Match(); an empty namePattern will match anything.
93+
// The parameter fileType may be a (logically or'ed) combination of the constants defined in this file;
94+
// supplying fileType as zero is the same as passing fileTypeAny.
9195
// The parameter maxDepth can be any integer between 0 and 10000 (where 0 is interpreted as 10000).
96+
// The returned paths will be relative (to the provided fsys), and filepath.Clean() will be run on each entry.
9297
func find(fsys fs.FS, dir string, namePattern string, fileType uint, maxDepth uint) ([]string, error) {
9398
if dir == "" {
9499
dir = "."
95100
}
96-
if strings.Contains(namePattern, "/") {
97-
return nil, fmt.Errorf("invalid name pattern; must not contain slashes")
101+
if namePattern == "" {
102+
namePattern = "*"
103+
} else if strings.Contains(namePattern, "/") {
104+
panic("invalid name pattern; must not contain slashes")
98105
}
99106
if fileType == 0 {
100107
fileType = fileTypeAny
101108
} else if fileType&fileTypeAny != fileType {
102-
return nil, fmt.Errorf("invalid file type")
109+
panic("invalid file type")
103110
}
104111
if maxDepth == 0 {
105112
maxDepth = 10000

0 commit comments

Comments
 (0)