MCPcopy
hub / github.com/containerd/containerd / selectRepositoryMountCandidate

Function selectRepositoryMountCandidate

core/remotes/docker/handler.go:111–137  ·  view source on GitHub ↗

selectRepositoryMountCandidate will select the repo which has longest common prefix components as the candidate.

(refspec reference.Spec, sources map[string]string)

Source from the content-addressed store, hash-verified

109// selectRepositoryMountCandidate will select the repo which has longest
110// common prefix components as the candidate.
111func selectRepositoryMountCandidate(refspec reference.Spec, sources map[string]string) string {
112 u, err := url.Parse("dummy://" + refspec.Locator)
113 if err != nil {
114 // NOTE: basically, it won't be error here
115 return ""
116 }
117
118 source, target := u.Hostname(), strings.TrimPrefix(u.Path, "/")
119 repoLabel, ok := sources[distributionSourceLabelKey(source)]
120 if !ok || repoLabel == "" {
121 return ""
122 }
123
124 n, match := 0, ""
125 components := strings.Split(target, "/")
126 for repo := range strings.SplitSeq(repoLabel, ",") {
127 // the target repo is not a candidate
128 if repo == target {
129 continue
130 }
131
132 if l := commonPrefixComponents(components, repo); l >= n {
133 n, match = l, repo
134 }
135 }
136 return match
137}
138
139func commonPrefixComponents(components []string, target string) int {
140 targetComponents := strings.Split(target, "/")

Callers 2

pushMethod · 0.85

Calls 3

commonPrefixComponentsFunction · 0.85
HostnameMethod · 0.65

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…