about summary refs log tree commit diff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/nixery/popcount/popcount.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/tools/nixery/popcount/popcount.go b/tools/nixery/popcount/popcount.go
index bc5f42af8a85..b21cee2e0e7d 100644
--- a/tools/nixery/popcount/popcount.go
+++ b/tools/nixery/popcount/popcount.go
@@ -160,6 +160,11 @@ func narInfoToRefs(narinfo string) []string {
 }
 
 func fetchNarInfo(i *item) (string, error) {
+	file, err := ioutil.ReadFile("popcache/" + i.hash)
+	if err == nil {
+		return string(file), nil
+	}
+
 	resp, err := client.Get(fmt.Sprintf("https://cache.nixos.org/%s.narinfo", i.hash))
 	if err != nil {
 		return "", err
@@ -168,6 +173,10 @@ func fetchNarInfo(i *item) (string, error) {
 	defer resp.Body.Close()
 
 	narinfo, err := ioutil.ReadAll(resp.Body)
+
+	// best-effort write the file to the cache
+	ioutil.WriteFile("popcache/" + i.hash, narinfo, 0644)
+
 	return string(narinfo), err
 }
 
@@ -208,6 +217,11 @@ func main() {
 		log.Fatalf("Nix channel must be specified as first argument")
 	}
 
+	err := os.MkdirAll("popcache", 0755)
+	if err != nil {
+		log.Fatalf("Failed to create 'popcache' directory in current folder: %s\n", err)
+	}
+
 	count := 42 // concurrent downloader count
 	channel := os.Args[1]
 	log.Printf("Fetching metadata for channel '%s'\n", channel)