MCPcopy Index your code
hub / github.com/docker/docker-agent / highestSiblingVersion

Function highestSiblingVersion

lint/configpath.go:43–57  ·  view source on GitHub ↗

highestSiblingVersion returns the largest N such that pkg/config/vN/ exists as a sibling of filename's directory. Result is cached per parent directory so callers can invoke it once per file cheaply.

(filename string)

Source from the content-addressed store, hash-verified

41// exists as a sibling of filename's directory. Result is cached per
42// parent directory so callers can invoke it once per file cheaply.
43func highestSiblingVersion(filename string) (int, bool) {
44 abs, err := filepath.Abs(filename)
45 if err != nil {
46 return 0, false
47 }
48 parent := filepath.Dir(filepath.Dir(abs))
49
50 if v, ok := highestCache.Load(parent); ok {
51 n := v.(int)
52 return n, n >= 0
53 }
54 n := scanHighestVN(parent)
55 highestCache.Store(parent, n)
56 return n, n >= 0
57}
58
59// highestCache memoises highestSiblingVersion. Value is -1 when no vN/
60// directory exists under the key.

Callers 1

Calls 4

scanHighestVNFunction · 0.85
DirMethod · 0.80
LoadMethod · 0.80
StoreMethod · 0.45

Tested by

no test coverage detected