Fix profile updates and validate configuration before apply

This commit is contained in:
ms2k 2026-10-05 21:45:05 +09:00
commit 2bf14948d7

View file

@ -72,7 +72,10 @@ func keys[V any](m map[string]V) []string {
func loadConfig(path string) (config, error) {
var c config
_, err := toml.DecodeFile(path, &c)
return c, err
if err != nil {
return c, err
}
return c, c.validate()
}
func parseSize(value string, base uint64) (uint64, error) {
@ -112,7 +115,11 @@ func (c config) properties(name string) ([]property, error) {
}
quota := uint64(math.MaxUint64)
if p.CPU != "" {
quota, err = strconv.ParseUint(strings.TrimSuffix(p.CPU, "%"), 10, 64)
percentage, ok := strings.CutSuffix(p.CPU, "%")
if !ok {
return nil, fmt.Errorf("CPUQuota: expected a percentage, got %q", p.CPU)
}
quota, err = strconv.ParseUint(percentage, 10, 64)
if err != nil {
return nil, fmt.Errorf("CPUQuota: %w", err)
}