Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions internal/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ func newHash(alg string) (hash.Hash, error) {
switch strings.ToLower(alg) {
case "md5":
hash = md5.New()
case "sha256":
case "sha256", "sha-256":
hash = sha256.New()
case "sha512":
case "sha512", "sha-512":
hash = sha512.New()
default:
return nil, fmt.Errorf("expected one of md5, sha256, sha512, got %s", alg)
return nil, fmt.Errorf("WARNING: expected one of md5, sha256, sha512, got %q", alg)
}
return hash, nil
}
Expand Down
15 changes: 10 additions & 5 deletions internal/fetch_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ func downloader(
defer os.Remove(dest.Name())

w := &writerHasher{Writer: dest}
skipchecksum := false
if req.ChecksumAlg != "" {
w.hash, err = newHash(req.ChecksumAlg)
if err != nil {
return err
fmt.Println(err)
skipchecksum = true
}
}
_, err = fetch(ctx, zult.URL, w)
Expand All @@ -114,13 +116,16 @@ func downloader(
return fmt.Errorf("probable HTML download content, possibly indicating a bad auth redirect")
}

zult.Checksum = w.Checksum()
if !skipchecksum {
zult.Checksum = w.Checksum()
if zult.Checksum != req.Checksum {
return fmt.Errorf("got checksum %s, expected %s", zult.Checksum, req.Checksum)
}
}

zult.Size = w.size
zult.Duration = time.Since(start)

if zult.Checksum != req.Checksum {
return fmt.Errorf("got checksum %s, expected %s", zult.Checksum, req.Checksum)
}
if err := os.Rename(dest.Name(), zult.Path); err != nil {
return fmt.Errorf("failed to rename %s to %s: %w", dest.Name(), zult.Path, err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestSplitChecksum(t *testing.T) {
}

func Test_newHash(t *testing.T) {
goodCases := []string{"md5", "MD5", "sha256", "sha512"}
goodCases := []string{"md5", "MD5", "sha256", "SHA-256", "sha512", "SHA-512"}
for _, test := range goodCases {
t.Run(test, func(t *testing.T) {
hash, err := newHash(test)
Expand Down