config: detect duplicate & internal job names at parse time

Before this PR, config parsing would accept duplicate job names.
`zrepl daemon` would later fail to start with a panic.
But tools like `zrepl configcheck` would pass.

This PR adds a check to ensure job names are unique.

Similarly, internal job names were not being rejected by config
parsing
Move that check to parse-time as well.
This commit is contained in:
Christian Schwarz
2026-01-19 08:20:07 +00:00
parent 4d6583ea5f
commit 8153d399f0
9 changed files with 108 additions and 54 deletions
+24
View File
@@ -6,6 +6,7 @@ import (
"os"
pathpkg "path"
"path/filepath"
"strings"
"time"
"github.com/pkg/errors"
@@ -693,9 +694,32 @@ func ParseConfig(path string) (rootConfig *Config, err error) {
return nil, err
}
if err = validateJobNames(rootConfig); err != nil {
return nil, err
}
return rootConfig, err
}
func IsInternalJobName(s string) bool {
return strings.HasPrefix(s, "_")
}
func validateJobNames(config *Config) error {
seen := make(map[string]struct{})
for _, job := range config.Jobs {
name := job.Name()
if IsInternalJobName(name) {
return errors.Errorf("job name %q is reserved for internal use (starts with _)", name)
}
if _, ok := seen[name]; ok {
return errors.Errorf("duplicate job name %q", name)
}
seen[name] = struct{}{}
}
return nil
}
func expandConfigInclude(configPath string, config *Config) (err error) {
var includeConfigPaths []string
for _, path := range config.Include {