From f7db17f7d05280d83d57f7266dbc4e9d3ba2c48a Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 28 Aug 2023 13:24:52 +0200 Subject: [PATCH] Load defaults for AppState before reading from yaml So far this hasn't been necessary because all defaults were zero values. We're about to add the first non-zero value though, and it's important that it is initialized correctly for users who have a state.yml that doesn't have it yet. --- pkg/config/app_config.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index a9872ea1e..ea26dd872 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -283,11 +283,13 @@ func (c *AppConfig) SaveAppState() error { // loadAppState loads recorded AppState from file func loadAppState() (*AppState, error) { + appState := getDefaultAppState() + filepath, err := configFilePath("state.yml") if err != nil { if os.IsPermission(err) { // apparently when people have read-only permissions they prefer us to fail silently - return getDefaultAppState(), nil + return appState, nil } return nil, err } @@ -298,10 +300,9 @@ func loadAppState() (*AppState, error) { } if len(appStateBytes) == 0 { - return getDefaultAppState(), nil + return appState, nil } - appState := &AppState{} err = yaml.Unmarshal(appStateBytes, appState) if err != nil { return nil, err