ScanFile returns the rollup for a jsonl file, reusing the cached result when the file's mod time and size are unchanged.
(path, ownSlug string)
| 44 | // ScanFile returns the rollup for a jsonl file, reusing the cached result |
| 45 | // when the file's mod time and size are unchanged. |
| 46 | func (c *Cache) ScanFile(path, ownSlug string) (FileRollup, error) { |
| 47 | fi, err := os.Stat(path) |
| 48 | if err != nil { |
| 49 | return FileRollup{}, err |
| 50 | } |
| 51 | modNS, size := fi.ModTime().UnixNano(), fi.Size() |
| 52 | if e, ok := c.Entries[path]; ok && e.ModNS == modNS && e.Size == size { |
| 53 | return e.Rollup, nil |
| 54 | } |
| 55 | f, err := os.Open(path) |
| 56 | if err != nil { |
| 57 | return FileRollup{}, err |
| 58 | } |
| 59 | defer f.Close() |
| 60 | roll, err := ScanJSONL(f, ownSlug) |
| 61 | if err != nil { |
| 62 | return FileRollup{}, err |
| 63 | } |
| 64 | c.Entries[path] = cacheEntry{ModNS: modNS, Size: size, Rollup: roll} |
| 65 | return roll, nil |
| 66 | } |
| 67 | |
| 68 | // Prune drops cache entries whose path was not seen in the latest run. |
| 69 | func (c *Cache) Prune(seen map[string]bool) { |