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)
| 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. |
| 43 | func 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. |
no test coverage detected