Skip to content

Commit

Permalink
record path of statefile when default one is created initially
Browse files Browse the repository at this point in the history
  • Loading branch information
aybabtme committed Jan 14, 2023
1 parent 01f8a03 commit 425cd4b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/humanlog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func newApp() *cli.App {
if !ok {
return nil
}
if res.hasUpdate && promptedToUpdate == nil && promptedToUpdate.LT(res.sem) {
if res.hasUpdate && promptedToUpdate == nil || promptedToUpdate.LT(res.sem) {
alreadyPromptedForSameUpdate := promptedToUpdate != nil && promptedToUpdate.GTE(res.sem)
if !alreadyPromptedForSameUpdate {
promptToUpdate(semverVersion, res.sem)
Expand Down
6 changes: 3 additions & 3 deletions internal/pkg/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ func ReadStateFile(path string, dflt *State) (*State, error) {
if !errors.Is(err, os.ErrNotExist) {
return nil, fmt.Errorf("opening state file %q: %v", path, err)
}
return dflt, WriteStateFile(path, dflt)
cfg := (State{path: path}).populateEmpty(dflt)
return cfg, WriteStateFile(path, cfg)
}
defer stateFile.Close()
var cfg State
Expand All @@ -67,7 +68,6 @@ func WriteStateFile(path string, state *State) error {
if err != nil {
return fmt.Errorf("marshaling state file: %v", err)
}

newf, err := os.CreateTemp(os.TempDir(), "humanlog_statefile")
if err != nil {
return fmt.Errorf("creating temporary file for statefile: %w", err)
Expand All @@ -88,7 +88,7 @@ func WriteStateFile(path string, state *State) error {
return fmt.Errorf("setting permissions on temporary statefile: %w", err)
}
if err := os.Rename(newf.Name(), path); err != nil {
return fmt.Errorf("replacing statefile: %w", err)
return fmt.Errorf("replacing statefile at %q with %q: %w", path, newf.Name(), err)
}
success = true
return nil
Expand Down

0 comments on commit 425cd4b

Please sign in to comment.