Skip to content

Commit

Permalink
fixing nilpointer dereference issue
Browse files Browse the repository at this point in the history
  • Loading branch information
binaek committed Feb 18, 2021
1 parent e0826c8 commit b893643
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
14 changes: 7 additions & 7 deletions statefile/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,29 @@ type State struct {
InstallationID string `json:"installationId"` // a UUIDv4 string
}

func LoadState() (*State, error) {
func LoadState() (State, error) {
currentState := createState()

stateFilePath := filepath.Join(constants.InternalDir(), updateStateFileName)
// get the state file
_, err := os.Stat(stateFilePath)
if err != nil {
return nil, err
return currentState, err
}

stateFileContent, err := ioutil.ReadFile(stateFilePath)
if err != nil {
fmt.Println("Could not read update state file")
return nil, err
return currentState, err
}

currentState := State{}

err = json.Unmarshal(stateFileContent, &currentState)
if err != nil {
fmt.Println("Could not parse update state file")
return nil, err
return currentState, err
}

return &currentState, nil
return currentState, nil
}

func createState() State {
Expand Down
5 changes: 1 addition & 4 deletions task/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
const minimumMinutesBetweenChecks = 1440 // 1 day

type Runner struct {
currentState *statefile.State
currentState statefile.State
shouldRun bool
}

Expand Down Expand Up @@ -52,9 +52,6 @@ func (r *Runner) runAsyncJob(job func(), wg *sync.WaitGroup) {

func (r *Runner) getShouldRun() bool {
now := time.Now()
if r.currentState == nil {
return true
}
if r.currentState.LastCheck == "" {
return true
}
Expand Down

0 comments on commit b893643

Please sign in to comment.