Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change hash algorithm computation method #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be an indirect dependency. Can you please run go get -u ; go mod tidy and push the changes? 😊

24 changes: 9 additions & 15 deletions main.go
Expand Up @@ -9,10 +9,13 @@ import (
"log"
"net/http"
"os"
"os/exec"
"regexp"
"strconv"
"strings"
"path/filepath"
"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 +73,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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this down to after line 93 (inside the if err == nil.

// 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop this

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, filepath.Join(dir, fixedName))
hashString = nixbase32.EncodeToString(h.Sum(nil))
Comment on lines +87 to +88
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
nar.DumpPath(h, filepath.Join(dir, fixedName))
hashString = nixbase32.EncodeToString(h.Sum(nil))
if err := nar.DumpPath(h, filepath.Join(dir, fixedName)); err != nil {
return "", fmt.Errorf("failed to dump path: %w", err)
}
return nixbase32.EncodeToString(h.Sum(nil)), nil

}
return resp, err
return hashString, err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return hashString, err
return "", err

}

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