Reject missing explicit configuration files
This commit is contained in:
committed by
Brandon McGinty
parent
1ea71b1862
commit
6da5b249f9
@@ -356,6 +356,20 @@ func (c *Config) UpdateConfig(u *gumble.User) {
|
||||
j.LocallyMuted = u.LocallyMuted() // Save LocallyMuted state to config
|
||||
}
|
||||
|
||||
// RequireConfigFile verifies that an explicitly requested configuration file
|
||||
// exists and is a regular file. The default configuration remains optional.
|
||||
func RequireConfigFile(fn string) error {
|
||||
path := resolvePath(fn)
|
||||
info, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("config file %q: %w", path, err)
|
||||
}
|
||||
if info.IsDir() {
|
||||
return fmt.Errorf("config file %q is a directory", path)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewConfig(fn *string) *Config {
|
||||
var c *Config
|
||||
c = &Config{}
|
||||
|
||||
@@ -8,6 +8,15 @@ import (
|
||||
"git.stormux.org/storm/barnard/uiterm"
|
||||
)
|
||||
|
||||
// Regression: an explicit -config path silently fell back to in-memory
|
||||
// defaults, then overwrote the intended file on exit.
|
||||
func TestRequireConfigFileRejectsMissingExplicitPath(t *testing.T) {
|
||||
missing := filepath.Join(t.TempDir(), "missing.toml")
|
||||
if err := RequireConfigFile(missing); err == nil {
|
||||
t.Fatal("missing explicit config was accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigBackfillsRecordingDefaults(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
configPath := filepath.Join(dir, "barnard.toml")
|
||||
|
||||
Reference in New Issue
Block a user