MCPcopy Index your code
hub / github.com/jetify-com/devbox / fetchNarInfoStatusFromHTTP

Function fetchNarInfoStatusFromHTTP

internal/devpkg/narinfo_cache.go:259–283  ·  view source on GitHub ↗
(
	ctx context.Context,
	uri string,
	hash string,
)

Source from the content-addressed store, hash-verified

257var narInfoStatusFnCache = sync.Map{}
258
259func fetchNarInfoStatusFromHTTP(
260 ctx context.Context,
261 uri string,
262 hash string,
263) (bool, error) {
264 key := fmt.Sprintf("%s/%s", uri, hash)
265 fetch, _ := narInfoStatusFnCache.LoadOrStore(key, sync.OnceValues(
266 func() (bool, error) {
267 ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
268 defer cancel()
269 url := fmt.Sprintf("%s/%s.narinfo", uri, hash)
270 req, err := http.NewRequestWithContext(ctx, http.MethodHead, url, nil)
271 if err != nil {
272 return false, err
273 }
274 res, err := http.DefaultClient.Do(req)
275 if err != nil {
276 return false, err
277 }
278 defer res.Body.Close()
279 return res.StatusCode == http.StatusOK, nil
280 },
281 ))
282 return fetch.(func() (bool, error))()
283}
284
285func fetchNarInfoStatusFromS3(
286 ctx context.Context,

Callers 2

AreAllOutputsInCacheMethod · 0.85

Calls 1

DoMethod · 0.45

Tested by

no test coverage detected