func prepareRepo(cacheKey string) (string, error) { path, err := ioutil.TempDir("", "repo-"+cacheKey) if err != nil { return "", err } res, err := http.Get(blobstoreCacheURL(cacheKey)) if err != nil { return "", err } defer res.Body.Close() if res.StatusCode == 404 { return path, initRepo(path) } if res.StatusCode != 200 { return "", fmt.Errorf("unexpected error %d retrieving cached repo", res.StatusCode) } r := tar.NewReader(res.Body) if err := archiver.Untar(path, r); err != nil { return "", err } if err := writeRepoHook(path); err != nil { return "", err } return path, nil }
func restoreBlobstoreCache(tempDir, path string) error { cachePath := tempDir + "/" + path res, err := http.Get("http://blobstore.discoverd/cache/" + path + ".tar") if err != nil { return err } defer res.Body.Close() if res.StatusCode == 200 { // cache hit r := tar.NewReader(res.Body) archiver.Untar(cachePath, r) } return nil }
func restoreBlobstoreCache(tempDir, path string) error { cachePath := filepath.Join(tempDir, path) res, err := http.Get(blobstoreCacheURL(path)) if err != nil { return err } defer res.Body.Close() if res.StatusCode == 200 { // cache hit r := tar.NewReader(res.Body) return archiver.Untar(cachePath, r) } return nil }