(lastCheckFile string, interval time.Duration, label string, log *logger.Logger)
| 27 | } |
| 28 | |
| 29 | func shouldRunUpdateCheckAtPath(lastCheckFile string, interval time.Duration, label string, log *logger.Logger) bool { |
| 30 | if lastCheckFile == "" { |
| 31 | log.Printf("Could not determine %s file path", label) |
| 32 | return false |
| 33 | } |
| 34 | |
| 35 | data, err := os.ReadFile(lastCheckFile) |
| 36 | if err != nil { |
| 37 | if !os.IsNotExist(err) { |
| 38 | log.Printf("Error reading %s file: %v", label, err) |
| 39 | } |
| 40 | return true |
| 41 | } |
| 42 | |
| 43 | lastCheck, err := time.Parse(time.RFC3339, strings.TrimSpace(string(data))) |
| 44 | if err != nil { |
| 45 | log.Printf("Error parsing %s time: %v", label, err) |
| 46 | return true |
| 47 | } |
| 48 | |
| 49 | elapsed := time.Since(lastCheck) |
| 50 | if elapsed < interval { |
| 51 | log.Printf("Last %s was %v ago, skipping", label, elapsed) |
| 52 | return false |
| 53 | } |
| 54 | |
| 55 | return true |
| 56 | } |
| 57 | |
| 58 | func writeUpdateCheckTime(path string, perm os.FileMode, label string, log *logger.Logger) { |
| 59 | if path == "" { |
no test coverage detected