This repository has been archived by the owner on May 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
cache.go
50 lines (41 loc) · 1.49 KB
/
cache.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2018 IBM Corporation
// Licensed under the Apache License, Version 2.0. See LICENSE file.
package scanner
import (
"github.com/IBM/binprint/record"
"github.com/IBM/binprint/store"
)
var cache = store.NewInMemoryStore()
// PersistRememberedObjects persists the in-memory store to disk for
// resuscitation in future runs.
func PersistRememberedObjects() {
cache.PersistRememberedObjects()
}
// GetStore returns the current backing store being used
func GetStore() record.Store {
return cache
}
// RestoreRememberedObjects loads a previously persisted dump of the in-memory
// store in to memory so that previous work does not need to be repeated.
func RestoreRememberedObjects() {
if populated := store.RestoreRememberedObjects(); populated != nil {
cache = populated
}
}
// FindMatchingFingerprint searches the in-memory database for the first fingerprint that matches the provided FingerprintMatcher
func FindMatchingFingerprint(matcher FingerprintMatcher) *record.Fingerprint {
// If we are looking for a full gitsha then we can just do a direct lookup without scanning
if matcher.T == "git" || matcher.T == "gitsha" {
if len(matcher.B) == 20 {
exact := [20]byte{}
copy(exact[:], matcher.B)
// // var exact [20]byte =
// exact := [...]byte{...matcher.B} // hash.NewGitShaDigestFromBytes(matcher.B)
return cache.GetFingerprintByGitSHA(exact)
}
}
matchFn := func(fp *record.Fingerprint) bool {
return matcher.Match(fp)
}
return cache.FindMatchingFingerprint(matchFn)
}