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)
| 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. |
| 270 | func (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. |
| 296 | type githubRelease struct { |
no test coverage detected