diff --git a/readjson.go b/readjson.go index a2a9df1..1a632b2 100644 --- a/readjson.go +++ b/readjson.go @@ -76,14 +76,7 @@ func readData(device string) (gjson.Result, error) { if _, err := os.Stat(device); err == nil { cacheValue, cacheOk := jsonCache[device] - timeToScan := false - if cacheOk { - timeToScan = time.Now().After(cacheValue.LastCollect.Add(options.SMARTctl.CollectPeriodDuration)) - } else { - timeToScan = true - } - - if timeToScan { + if !cacheOk || time.Now().After(cacheValue.LastCollect.Add(options.SMARTctl.CollectPeriodDuration)) { json, ok := readSMARTctl(device) if ok { jsonCache[device] = JSONCache{JSON: json, LastCollect: time.Now()} @@ -91,7 +84,7 @@ func readData(device string) (gjson.Result, error) { } return gjson.Parse("{}"), fmt.Errorf("smartctl returned bad data for device %s", device) } - return gjson.Parse("{}"), fmt.Errorf("Too early collect called for device %s", device) + return cacheValue.JSON, nil } return gjson.Parse("{}"), fmt.Errorf("Device %s unavialable", device) }