Report configuration persistence failures
This commit is contained in:
committed by
Brandon McGinty
parent
655a109ce8
commit
ef8a92149d
@@ -58,6 +58,9 @@ func (c *Config) SaveConfig() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) saveConfigLocked() error {
|
func (c *Config) saveConfigLocked() error {
|
||||||
|
if err := os.MkdirAll(filepath.Dir(c.fn), 0700); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
data, err := toml.Marshal(c.config)
|
data, err := toml.Marshal(c.config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -286,13 +289,13 @@ func (c *Config) findUser(address string, username string) *eUser {
|
|||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) ToggleMute(u *gumble.User) {
|
func (c *Config) ToggleMute(u *gumble.User) error {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
j := c.findUser(u.GetClient().Config.Address, u.Name)
|
j := c.findUser(u.GetClient().Config.Address, u.Name)
|
||||||
j.LocallyMuted = !j.LocallyMuted
|
j.LocallyMuted = !j.LocallyMuted
|
||||||
u.SetLocallyMuted(j.LocallyMuted)
|
u.SetLocallyMuted(j.LocallyMuted)
|
||||||
_ = c.saveConfigLocked()
|
return c.saveConfigLocked()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) SetMicVolume(v float32) {
|
func (c *Config) SetMicVolume(v float32) {
|
||||||
@@ -355,11 +358,11 @@ func (c *Config) GetNoiseSuppressionEnabled() bool {
|
|||||||
return *c.config.NoiseSuppressionEnabled
|
return *c.config.NoiseSuppressionEnabled
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) SetNoiseSuppressionEnabled(enabled bool) {
|
func (c *Config) SetNoiseSuppressionEnabled(enabled bool) error {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
c.config.NoiseSuppressionEnabled = &enabled
|
c.config.NoiseSuppressionEnabled = &enabled
|
||||||
_ = c.saveConfigLocked()
|
return c.saveConfigLocked()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) GetRecordingFormat() string {
|
func (c *Config) GetRecordingFormat() string {
|
||||||
|
|||||||
@@ -7,13 +7,19 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Regression: a configuration write failure panicked the client instead of
|
func TestSaveConfigCreatesMissingParentDirectory(t *testing.T) {
|
||||||
// returning an error to the caller.
|
parent := filepath.Join(t.TempDir(), "missing")
|
||||||
func TestSaveConfigReturnsWriteError(t *testing.T) {
|
path := filepath.Join(parent, "barnard.toml")
|
||||||
path := filepath.Join(t.TempDir(), "missing", "barnard.toml")
|
|
||||||
cfg := NewConfig(&path)
|
cfg := NewConfig(&path)
|
||||||
if err := cfg.SaveConfig(); err == nil {
|
if err := cfg.SaveConfig(); err != nil {
|
||||||
t.Fatal("expected configuration write error")
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
info, err := os.Stat(parent)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if info.Mode().Perm()&0077 != 0 {
|
||||||
|
t.Fatalf("parent directory permissions = %o, want no group or other access", info.Mode().Perm())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -253,13 +253,19 @@ func main() {
|
|||||||
b.Config.DisableUDP = *tcpOnly
|
b.Config.DisableUDP = *tcpOnly
|
||||||
|
|
||||||
b.Hotkeys = b.UserConfig.GetHotkeys()
|
b.Hotkeys = b.UserConfig.GetHotkeys()
|
||||||
b.UserConfig.SaveConfig()
|
if err := b.UserConfig.SaveConfig(); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "could not save configuration: %s\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
// Configure noise suppression
|
// Configure noise suppression
|
||||||
enabled := b.UserConfig.GetNoiseSuppressionEnabled()
|
enabled := b.UserConfig.GetNoiseSuppressionEnabled()
|
||||||
if *noiseSuppressionEnabled {
|
if *noiseSuppressionEnabled {
|
||||||
enabled = true
|
enabled = true
|
||||||
b.UserConfig.SetNoiseSuppressionEnabled(true)
|
if err := b.UserConfig.SetNoiseSuppressionEnabled(true); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "could not save configuration: %s\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
b.NoiseSuppressor.SetEnabled(enabled)
|
b.NoiseSuppressor.SetEnabled(enabled)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user