[check-log] change loadState to distinguish an error between a "file does not exist" error and other errors
@@ -420,15 +420,15 @@ type state struct {
func loadState(fname string) (*state, error) {
state := &state{}
- _, err := os.Stat(fname)
- if err == nil { // state file exists
b, err := ioutil.ReadFile(fname)
- if err == nil {
- err = json.Unmarshal(b, state)
+ if err != nil {
+ if os.IsNotExist(err) {
+ return nil, nil
}
return state, err
}
- return nil, nil
+ err = json.Unmarshal(b, state)
+ return state, err
}
var stateRe = regexp.MustCompile(`^([a-zA-Z]):[/\\]`)
