Skip to content

Commit b5512fb

Browse files
committed
fix: try to fix windows CI
1 parent 6973cd1 commit b5512fb

File tree

4 files changed

+36
-12
lines changed

4 files changed

+36
-12
lines changed

config/shared/errors/errors.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ var (
8686
ErrInsecureProxy = errors.New("insecure plaintext HTTP proxy specified for HTTPS resources")
8787
ErrPathConflictsSystemd = errors.New("path conflicts with systemd unit or dropin")
8888
ErrPathAlreadyExists = errors.New("path already exists")
89-
ErrMisslabeledDir = errors.New("parent directory path matches configured file, check path, and ensure parent directory is configured")
89+
ErrMissLabeledDir = errors.New("parent directory path matches configured file, check path, and ensure parent directory is configured")
9090

9191
// Systemd section errors
9292
ErrInvalidSystemdExt = errors.New("invalid systemd unit extension")

config/v3_5_experimental/types/config.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (cfg Config) validateParents(c path.ContextPath) report.Report {
102102
for i, entry := range entries {
103103
if i > 0 && isWithin(entry.Path, entries[i-1].Path) {
104104
if entries[i-1].Field != "directories" {
105-
r.AddOnError(c.Append("storage", entry.Field, i, "path"), errors.ErrMisslabeledDir)
105+
r.AddOnError(c.Append("storage", entry.Field, i, "path"), errors.ErrMissLabeledDir)
106106
return r
107107
}
108108
}
@@ -127,8 +127,17 @@ func addPathAndEntry(path, fieldName string, entries *[]struct{ Path, Field stri
127127

128128
func depth(path string) uint {
129129
var count uint
130-
for p := filepath.Clean(path); p != "/" && p != "."; count++ {
131-
p = filepath.Dir(p)
130+
cleanedPath := filepath.FromSlash(filepath.Clean(path))
131+
sep := string(filepath.Separator)
132+
133+
volume := filepath.VolumeName(cleanedPath)
134+
if volume != "" {
135+
cleanedPath = cleanedPath[len(volume):]
136+
}
137+
138+
for cleanedPath != sep && cleanedPath != "." {
139+
cleanedPath = filepath.Dir(cleanedPath)
140+
count++
132141
}
133142
return count
134143
}

config/v3_5_experimental/types/config_test.go

+22-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020

2121
"github.com/coreos/ignition/v2/config/shared/errors"
2222
"github.com/coreos/ignition/v2/config/util"
23-
2423
"github.com/coreos/vcontext/path"
2524
"github.com/coreos/vcontext/report"
2625
)
@@ -189,12 +188,12 @@ func TestConfigValidation(t *testing.T) {
189188
in: Config{
190189
Storage: Storage{
191190
Files: []File{
192-
{Node: Node{Path: "/foo/bar"}},
193-
{Node: Node{Path: "/foo/bar/baz"}},
191+
{Node: Node{Path: "C:\\foo\\bar"}},
192+
{Node: Node{Path: "C:\\foo\\bar\\baz"}},
194193
},
195194
},
196195
},
197-
out: errors.ErrMisslabeledDir,
196+
out: errors.ErrMissLabeledDir,
198197
at: path.New("json", "storage", "files", 1, "path"),
199198
},
200199

@@ -210,7 +209,7 @@ func TestConfigValidation(t *testing.T) {
210209
},
211210
},
212211
},
213-
out: errors.ErrMisslabeledDir,
212+
out: errors.ErrMissLabeledDir,
214213
at: path.New("json", "storage", "links", 1, "path"),
215214
},
216215

@@ -219,14 +218,14 @@ func TestConfigValidation(t *testing.T) {
219218
in: Config{
220219
Storage: Storage{
221220
Files: []File{
222-
{Node: Node{Path: "/foo/bar"}},
221+
{Node: Node{Path: "C:\\foo\\bar"}},
223222
},
224223
Directories: []Directory{
225-
{Node: Node{Path: "/foo/bar/baz"}},
224+
{Node: Node{Path: "C:\\foo\\bar\\baz"}},
226225
},
227226
},
228227
},
229-
out: errors.ErrMisslabeledDir,
228+
out: errors.ErrMissLabeledDir,
230229
at: path.New("json", "storage", "directories", 1, "path"),
231230
},
232231

@@ -333,3 +332,18 @@ func TestConfigValidation(t *testing.T) {
333332
}
334333
}
335334
}
335+
336+
func BenchmarkValidateParents(b *testing.B) {
337+
cfg := Config{
338+
Storage: Storage{
339+
Files: []File{
340+
{Node: Node{Path: "/foo/bar"}},
341+
{Node: Node{Path: "/foo/bar/baz"}},
342+
},
343+
},
344+
}
345+
346+
for i := 0; i < b.N; i++ {
347+
_ = cfg.validateParents(path.New("json"))
348+
}
349+
}

docs/release-notes.md

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ nav_order: 9
3838
- Fix validation to catch conflicts with the parent directory of another file, link or directories
3939
- Retry HTTP requests on Azure on status codes 404, 410, and 429
4040

41+
4142
## Ignition 2.17.0 (2023-11-20)
4243

4344
Starting with this release, ignition-validate binaries are signed with the

0 commit comments

Comments
 (0)