Skip to content

Commit

Permalink
change hash algorithm computation
Browse files Browse the repository at this point in the history
  • Loading branch information
onny committed Mar 8, 2024
1 parent da3ced8 commit 2714a92
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
2 changes: 2 additions & 0 deletions go.mod
@@ -1,3 +1,5 @@
module git.helsinki.tools/helsinki-systems/wp4nix

go 1.16

require github.com/nix-community/go-nix v0.0.0-20231219074122-93cb24a86856 // indirect
23 changes: 8 additions & 15 deletions main.go
Expand Up @@ -9,10 +9,12 @@ import (
"log"
"net/http"
"os"
"os/exec"
"regexp"
"strconv"
"strings"
"crypto/sha256"
"github.com/nix-community/go-nix/pkg/nar"
"github.com/nix-community/go-nix/pkg/nixbase32"
)

var DEBUG bool
Expand Down Expand Up @@ -70,30 +72,21 @@ func writeFile(t string, c map[string]interface{}) {
os.Rename(t+"-new.json", t+".json")
}

func execCmd(name, dir, file string, args ...string) (string, error) {
log.Printf("%s %s %s", name, file, args)
cmd := exec.Command(file, args...)
cmd.Dir = dir
out, err := cmd.CombinedOutput()
if err != nil {
log.Printf("Failed: %s %s %s %s", err, name, file, args)
}
return strings.TrimSpace(string(out)), err
}

func svnPrefetch(repo *Repository, path string, rev string, rawName string) (string, error) {
h := sha256.New()
// people push some weird shit
reg, _ := regexp.Compile("[^a-zA-Z0-9+\\-._?=]+")
fixedName := reg.ReplaceAllString(rawName, "")
dir, _ := ioutil.TempDir("", "wp4nix-prefetch-")
defer os.RemoveAll(dir)
var err error
var resp string
var hashString string
err = repo.Export(path, rev, dir+"/"+fixedName, nil, nil)
if err == nil {
resp, err = execCmd("Hash", dir, "nix-hash", "--type", "sha256", "--base32", fixedName)
nar.DumpPath(h, path.join(dir, fixedName))
hashString = nixbase32.EncodeToString(h.Sum(nil))
}
return resp, err
return hashString, err
}

// copy every element from every map into the resulting map
Expand Down

0 comments on commit 2714a92

Please sign in to comment.