Skip to content

Commit

Permalink
Move old state.yml files to the state dir
Browse files Browse the repository at this point in the history
  • Loading branch information
horriblename committed Dec 21, 2023
1 parent 34c4ed4 commit d79315b
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions pkg/config/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func (c *AppConfig) SaveAppState() error {
return err
}

filepath, err := stateFilePath("state.yml")
filepath, err := stateFilePath(stateFileName)
if err != nil {
return err
}
Expand All @@ -283,11 +283,15 @@ func (c *AppConfig) SaveAppState() error {
return err
}

var stateFileName = "state.yml"

// loadAppState loads recorded AppState from file
func loadAppState() (*AppState, error) {
_ = migrateStateFile("")

appState := getDefaultAppState()

filepath, err := stateFilePath("state.yml")
filepath, err := stateFilePath(stateFileName)
if err != nil {
return nil, err
}
Expand All @@ -309,6 +313,25 @@ func loadAppState() (*AppState, error) {
return appState, nil
}

// Do any backward-compatibility migrations of things that have changed over time
func migrateStateFile(filename string) error {
path, err := configFilePath(filename)
if err != nil {
return nil
}

if _, err := os.Stat(path); os.IsNotExist(err) {
return nil
}

targetPath, err := stateFilePath(filename)
if err != nil {
return err
}

return os.Rename(path, targetPath)
}

// AppState stores data between runs of the app like when the last update check
// was performed and which other repos have been checked out
type AppState struct {
Expand Down

0 comments on commit d79315b

Please sign in to comment.