|
34 | 34 | func (cfg Config) Validate(c path.ContextPath) (r report.Report) { |
35 | 35 | systemdPath := "/etc/systemd/system/" |
36 | 36 | unitPaths := map[string]struct{}{} |
| 37 | + |
37 | 38 | for _, unit := range cfg.Systemd.Units { |
38 | 39 | if !util.NilOrEmpty(unit.Contents) { |
39 | 40 | pathString := systemdPath + unit.Name |
@@ -61,5 +62,43 @@ func (cfg Config) Validate(c path.ContextPath) (r report.Report) { |
61 | 62 | r.AddOnError(c.Append("storage", "links", i, "path"), errors.ErrPathConflictsSystemd) |
62 | 63 | } |
63 | 64 | } |
| 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 | + } |
64 | 94 | return |
65 | 95 | } |
| 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