@@ -9,10 +9,12 @@ import (
99 "log"
1010 "net/http"
1111 "os"
12- "os/exec"
1312 "regexp"
1413 "strconv"
1514 "strings"
15+ "crypto/sha256"
16+ "github.com/nix-community/go-nix/pkg/nar"
17+ "github.com/nix-community/go-nix/pkg/nixbase32"
1618)
1719
1820var DEBUG bool
@@ -70,30 +72,21 @@ func writeFile(t string, c map[string]interface{}) {
7072 os .Rename (t + "-new.json" , t + ".json" )
7173}
7274
73- func execCmd (name , dir , file string , args ... string ) (string , error ) {
74- log .Printf ("%s %s %s" , name , file , args )
75- cmd := exec .Command (file , args ... )
76- cmd .Dir = dir
77- out , err := cmd .CombinedOutput ()
78- if err != nil {
79- log .Printf ("Failed: %s %s %s %s" , err , name , file , args )
80- }
81- return strings .TrimSpace (string (out )), err
82- }
83-
8475func svnPrefetch (repo * Repository , path string , rev string , rawName string ) (string , error ) {
76+ h := sha256 .New ()
8577 // people push some weird shit
8678 reg , _ := regexp .Compile ("[^a-zA-Z0-9+\\ -._?=]+" )
8779 fixedName := reg .ReplaceAllString (rawName , "" )
8880 dir , _ := ioutil .TempDir ("" , "wp4nix-prefetch-" )
8981 defer os .RemoveAll (dir )
9082 var err error
91- var resp string
83+ var hashString string
9284 err = repo .Export (path , rev , dir + "/" + fixedName , nil , nil )
9385 if err == nil {
94- resp , err = execCmd ("Hash" , dir , "nix-hash" , "--type" , "sha256" , "--base32" , fixedName )
86+ nar .DumpPath (h , path .join (dir , fixedName ))
87+ hashString = nixbase32 .EncodeToString (h .Sum (nil ))
9588 }
96- return resp , err
89+ return hashString , err
9790}
9891
9992// copy every element from every map into the resulting map
0 commit comments