Skip to content

Commit 2714a92

Browse files
committed
change hash algorithm computation
1 parent da3ced8 commit 2714a92

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
module git.helsinki.tools/helsinki-systems/wp4nix
22

33
go 1.16
4+
5+
require github.com/nix-community/go-nix v0.0.0-20231219074122-93cb24a86856 // indirect

main.go

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

1820
var 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-
8475
func 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

Comments
 (0)