From b5512fb01c880bc0fde794e4664edacc87864cec Mon Sep 17 00:00:00 2001 From: Yasmin Valim Date: Wed, 17 Apr 2024 10:25:21 -0300 Subject: [PATCH] fix: try to fix windows CI --- config/shared/errors/errors.go | 2 +- config/v3_5_experimental/types/config.go | 15 ++++++++-- config/v3_5_experimental/types/config_test.go | 30 ++++++++++++++----- docs/release-notes.md | 1 + 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/config/shared/errors/errors.go b/config/shared/errors/errors.go index 12cf27d10f..da26eaa28b 100644 --- a/config/shared/errors/errors.go +++ b/config/shared/errors/errors.go @@ -86,7 +86,7 @@ var ( ErrInsecureProxy = errors.New("insecure plaintext HTTP proxy specified for HTTPS resources") ErrPathConflictsSystemd = errors.New("path conflicts with systemd unit or dropin") ErrPathAlreadyExists = errors.New("path already exists") - ErrMisslabeledDir = errors.New("parent directory path matches configured file, check path, and ensure parent directory is configured") + ErrMissLabeledDir = errors.New("parent directory path matches configured file, check path, and ensure parent directory is configured") // Systemd section errors ErrInvalidSystemdExt = errors.New("invalid systemd unit extension") diff --git a/config/v3_5_experimental/types/config.go b/config/v3_5_experimental/types/config.go index a64bd46877..3df89e740a 100644 --- a/config/v3_5_experimental/types/config.go +++ b/config/v3_5_experimental/types/config.go @@ -102,7 +102,7 @@ func (cfg Config) validateParents(c path.ContextPath) report.Report { for i, entry := range entries { if i > 0 && isWithin(entry.Path, entries[i-1].Path) { if entries[i-1].Field != "directories" { - r.AddOnError(c.Append("storage", entry.Field, i, "path"), errors.ErrMisslabeledDir) + r.AddOnError(c.Append("storage", entry.Field, i, "path"), errors.ErrMissLabeledDir) return r } } @@ -127,8 +127,17 @@ func addPathAndEntry(path, fieldName string, entries *[]struct{ Path, Field stri func depth(path string) uint { var count uint - for p := filepath.Clean(path); p != "/" && p != "."; count++ { - p = filepath.Dir(p) + cleanedPath := filepath.FromSlash(filepath.Clean(path)) + sep := string(filepath.Separator) + + volume := filepath.VolumeName(cleanedPath) + if volume != "" { + cleanedPath = cleanedPath[len(volume):] + } + + for cleanedPath != sep && cleanedPath != "." { + cleanedPath = filepath.Dir(cleanedPath) + count++ } return count } diff --git a/config/v3_5_experimental/types/config_test.go b/config/v3_5_experimental/types/config_test.go index 362371dbdb..af354ccb8e 100644 --- a/config/v3_5_experimental/types/config_test.go +++ b/config/v3_5_experimental/types/config_test.go @@ -20,7 +20,6 @@ import ( "github.com/coreos/ignition/v2/config/shared/errors" "github.com/coreos/ignition/v2/config/util" - "github.com/coreos/vcontext/path" "github.com/coreos/vcontext/report" ) @@ -189,12 +188,12 @@ func TestConfigValidation(t *testing.T) { in: Config{ Storage: Storage{ Files: []File{ - {Node: Node{Path: "/foo/bar"}}, - {Node: Node{Path: "/foo/bar/baz"}}, + {Node: Node{Path: "C:\\foo\\bar"}}, + {Node: Node{Path: "C:\\foo\\bar\\baz"}}, }, }, }, - out: errors.ErrMisslabeledDir, + out: errors.ErrMissLabeledDir, at: path.New("json", "storage", "files", 1, "path"), }, @@ -210,7 +209,7 @@ func TestConfigValidation(t *testing.T) { }, }, }, - out: errors.ErrMisslabeledDir, + out: errors.ErrMissLabeledDir, at: path.New("json", "storage", "links", 1, "path"), }, @@ -219,14 +218,14 @@ func TestConfigValidation(t *testing.T) { in: Config{ Storage: Storage{ Files: []File{ - {Node: Node{Path: "/foo/bar"}}, + {Node: Node{Path: "C:\\foo\\bar"}}, }, Directories: []Directory{ - {Node: Node{Path: "/foo/bar/baz"}}, + {Node: Node{Path: "C:\\foo\\bar\\baz"}}, }, }, }, - out: errors.ErrMisslabeledDir, + out: errors.ErrMissLabeledDir, at: path.New("json", "storage", "directories", 1, "path"), }, @@ -333,3 +332,18 @@ func TestConfigValidation(t *testing.T) { } } } + +func BenchmarkValidateParents(b *testing.B) { + cfg := Config{ + Storage: Storage{ + Files: []File{ + {Node: Node{Path: "/foo/bar"}}, + {Node: Node{Path: "/foo/bar/baz"}}, + }, + }, + } + + for i := 0; i < b.N; i++ { + _ = cfg.validateParents(path.New("json")) + } +} diff --git a/docs/release-notes.md b/docs/release-notes.md index 981f1a7246..d4a39ae763 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -38,6 +38,7 @@ nav_order: 9 - Fix validation to catch conflicts with the parent directory of another file, link or directories - Retry HTTP requests on Azure on status codes 404, 410, and 429 + ## Ignition 2.17.0 (2023-11-20) Starting with this release, ignition-validate binaries are signed with the