Skip to content

Commit

Permalink
core: use native shasum binary on macOS for download verification (#1245
Browse files Browse the repository at this point in the history
)

Signed-off-by: Abiola Ibrahim <[email protected]>
  • Loading branch information
abiosoft authored Jan 9, 2025
1 parent 9b7f399 commit b1d8fcc
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion util/downloader/sha.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"path/filepath"
"strconv"
"strings"

"github.com/abiosoft/colima/util"
)

// SHA is the shasum of a file.
Expand All @@ -18,14 +20,19 @@ type SHA struct {
func (s SHA) ValidateFile(host hostActions, file string) error {
dir, filename := filepath.Split(file)
digest := strings.TrimPrefix(s.Digest, fmt.Sprintf("sha%d:", s.Size))
shasumBinary := "shasum"
if util.MacOS() {
shasumBinary = "/usr/bin/shasum"
}

script := strings.NewReplacer(
"{dir}", dir,
"{digest}", digest,
"{size}", strconv.Itoa(s.Size),
"{filename}", filename,
"{shasum_bin}", shasumBinary,
).Replace(
`cd {dir} && echo "{digest} {filename}" | shasum -a {size} --check --status`,
`cd {dir} && echo "{digest} {filename}" | {shasum_bin} -a {size} --check --status`,
)

return host.Run("sh", "-c", script)
Expand Down

0 comments on commit b1d8fcc

Please sign in to comment.