MCPcopy Create free account
hub / github.com/Facets-cloud/flow / ScanFile

Method ScanFile

internal/stats/cache.go:46–66  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

44// ScanFile returns the rollup for a jsonl file, reusing the cached result
45// when the file's mod time and size are unchanged.
46func (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.
69func (c *Cache) Prune(seen map[string]bool) {

Callers 3

BuildStatsFunction · 0.80
TestLoadCacheCorruptFunction · 0.80

Calls 1

ScanJSONLFunction · 0.85

Tested by 2

TestLoadCacheCorruptFunction · 0.64