MCPcopy Index your code
hub / github.com/kopia/kopia / readBlobsFromCache

Method readBlobsFromCache

internal/listcache/listcache.go:54–83  ·  view source on GitHub ↗
(ctx context.Context, prefix blob.ID)

Source from the content-addressed store, hash-verified

52}
53
54func (s *listCacheStorage) readBlobsFromCache(ctx context.Context, prefix blob.ID) *cachedList {
55 cl := &cachedList{}
56
57 var data gather.WriteBuffer
58 defer data.Close()
59
60 if err := s.cacheStorage.GetBlob(ctx, prefix, 0, -1, &data); err != nil {
61 return nil
62 }
63
64 var verified gather.WriteBuffer
65 defer verified.Close()
66
67 if err := hmac.VerifyAndStrip(data.Bytes(), s.hmacSecret, &verified); err != nil {
68 log(ctx).Warnf("invalid list cache HMAC for %v, ignoring", prefix)
69 return nil
70 }
71
72 if err := json.NewDecoder(verified.Bytes().Reader()).Decode(&cl); err != nil {
73 log(ctx).Warnf("can't unmarshal cached list results for %v, ignoring", prefix)
74 return nil
75 }
76
77 if s.cacheTimeFunc().Before(cl.ExpireAfter) {
78 return cl
79 }
80
81 // list cache expired
82 return nil
83}
84
85// ListBlobs implements blob.Storage and caches previous list results for a given prefix.
86func (s *listCacheStorage) ListBlobs(ctx context.Context, prefix blob.ID, cb func(blob.Metadata) error) error {

Callers 1

ListBlobsMethod · 0.95

Calls 6

CloseMethod · 0.95
BytesMethod · 0.95
VerifyAndStripFunction · 0.92
GetBlobMethod · 0.65
ReaderMethod · 0.65
BeforeMethod · 0.45

Tested by

no test coverage detected