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

Conversation

onny
Copy link

@onny onny commented Mar 8, 2024

instead of using os.exec to execute nix-hash, this method uses a native go module for hash computation

main.go Outdated Show resolved Hide resolved
@@ -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? 😊

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants