MCPcopy Create free account
hub / github.com/docker/docker-agent / fetchIndex

Method fetchIndex

pkg/toolinstall/registry.go:270–293  ·  view source on GitHub ↗

fetchIndex fetches and parses the full registry index. The raw YAML is cached to disk; on fetch failure the cached copy is used. The YAML is re-parsed on every call — there is no in-memory cache.

(ctx context.Context)

Source from the content-addressed store, hash-verified

268// The raw YAML is cached to disk; on fetch failure the cached copy is used.
269// The YAML is re-parsed on every call — there is no in-memory cache.
270func (r *Registry) fetchIndex(ctx context.Context) (*registryIndex, error) {
271 cachePath := filepath.Join(r.cacheDir, registryIndexFile)
272
273 data, err := r.getBody(ctx, r.baseURL+"/"+registryIndexFile)
274 if err != nil {
275 // Fallback to stale disk cache.
276 if cached, readErr := os.ReadFile(cachePath); readErr == nil {
277 data = cached
278 } else {
279 return nil, err
280 }
281 } else {
282 // Best-effort: persist to disk for future fallback.
283 _ = os.MkdirAll(filepath.Dir(cachePath), 0o700)
284 _ = atomicfile.Write(cachePath, bytes.NewReader(data), 0o600)
285 }
286
287 var index registryIndex
288 if err := yaml.Unmarshal(data, &index); err != nil {
289 return nil, fmt.Errorf("parsing registry index: %w", err)
290 }
291
292 return &index, nil
293}
294
295// githubRelease represents the relevant fields from the GitHub releases API.
296type githubRelease struct {

Callers 2

LookupByNameMethod · 0.95
LookupByCommandMethod · 0.95

Calls 4

getBodyMethod · 0.95
WriteFunction · 0.92
ReadFileMethod · 0.80
DirMethod · 0.80

Tested by

no test coverage detected