Skip to content

Commit e03c6ba

Browse files
committed
v3_5_experimental: add validations
1 parent a36c760 commit e03c6ba

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

config/v3_5_experimental/types/config.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var (
3434
func (cfg Config) Validate(c path.ContextPath) (r report.Report) {
3535
systemdPath := "/etc/systemd/system/"
3636
unitPaths := map[string]struct{}{}
37+
3738
for _, unit := range cfg.Systemd.Units {
3839
if !util.NilOrEmpty(unit.Contents) {
3940
pathString := systemdPath + unit.Name
@@ -61,5 +62,43 @@ func (cfg Config) Validate(c path.ContextPath) (r report.Report) {
6162
r.AddOnError(c.Append("storage", "links", i, "path"), errors.ErrPathConflictsSystemd)
6263
}
6364
}
65+
66+
allPaths := map[string]struct{}{}
67+
68+
for _, f := range cfg.Storage.Files {
69+
allPaths[f.Path] = struct{}{}
70+
71+
filePath := getParentDirectory(f.Path)
72+
if _, exists := allPaths[filePath]; exists {
73+
r.AddOnError(c.Append("storage", "files"), errors.ErrPathConflictsParentDir)
74+
}
75+
}
76+
77+
for _, d := range cfg.Storage.Directories {
78+
allPaths[d.Path] = struct{}{}
79+
80+
dirPath := getParentDirectory(d.Path)
81+
if _, exists := allPaths[dirPath]; exists {
82+
r.AddOnError(c.Append("storage", "directories"), errors.ErrPathConflictsParentDir)
83+
}
84+
}
85+
86+
for _, l := range cfg.Storage.Links {
87+
allPaths[l.Path] = struct{}{}
88+
89+
linkPath := getParentDirectory(l.Path)
90+
if _, exists := allPaths[linkPath]; exists {
91+
r.AddOnError(c.Append("storage", "links"), errors.ErrPathConflictsParentDir)
92+
}
93+
}
6494
return
6595
}
96+
97+
func getParentDirectory(p string) string {
98+
index := len(p) - 1
99+
for index > 0 && p[index-1] != '/' {
100+
index--
101+
}
102+
103+
return p[:index]
104+
}

0 commit comments

Comments
 (0)