check / check (push) Waiting to run
An exclude pattern that did not compile was skipped with a warning during the backup, which then stored what the user meant to leave out. Config.Validate now refuses it, naming the setting and quoting the pattern, for example exclude[2]: "build[" is not a valid exclude pattern: ... The compile step moves to a new package, internal/exclude, as exclude.Compile; Validate and the scanner both call it. The scanner's skip-and-warn path is gone; a pattern that does not compile there now fails the scanner. Model: opus-5-5
40 lines
909 B
Go
40 lines
909 B
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"sneak.berlin/go/vaultik/internal/exclude"
|
|
)
|
|
|
|
// validateExcludes refuses an exclude pattern, global or in a snapshot,
|
|
// that does not compile, naming the setting and quoting the pattern.
|
|
func (c *Config) validateExcludes() error {
|
|
err := validateExcludeList("exclude", c.Exclude)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, name := range c.SnapshotNames() {
|
|
err = validateExcludeList("snapshots."+name+".exclude",
|
|
c.Snapshots[name].Exclude)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// validateExcludeList refuses the first pattern in patterns that does not
|
|
// compile. setting is the name of the list, as in "exclude".
|
|
func validateExcludeList(setting string, patterns []string) error {
|
|
for i, pattern := range patterns {
|
|
_, _, err := exclude.Compile(pattern)
|
|
if err != nil {
|
|
return fmt.Errorf("%s[%d]: %w", setting, i, err)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|