aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-12-03 04:23:53 +0000
committerFuwn <[email protected]>2024-12-03 04:23:53 +0000
commit4be6e521f639617fefda4c3f32dda41aa36199f6 (patch)
treeeeb481a9fb2ad8756812b827f0f10294afa65226 /internal
parentfix(init): initialise base empty environment on init command (diff)
downloadyae-4be6e521f639617fefda4c3f32dda41aa36199f6.tar.xz
yae-4be6e521f639617fefda4c3f32dda41aa36199f6.zip
feat(yae): track sri hash field for sources
Diffstat (limited to 'internal')
-rw-r--r--internal/yae/source.go10
-rw-r--r--internal/yae/utilities.go10
2 files changed, 19 insertions, 1 deletions
diff --git a/internal/yae/source.go b/internal/yae/source.go
index 735e4d4..20d16dc 100644
--- a/internal/yae/source.go
+++ b/internal/yae/source.go
@@ -11,6 +11,7 @@ import (
type Source struct {
URL string `json:"url"`
SHA256 string `json:"sha256"`
+ Hash string `json:"hash"`
Unpack bool `json:"unpack"`
Type string `json:"type"`
Version string `json:"version,omitempty"`
@@ -78,10 +79,17 @@ func (source *Source) Update(sources *Environment, name string, force bool, forc
return updated, err
}
- if sha256 != source.SHA256 {
+ sriHash, err := FetchSRIHash(sha256)
+
+ if err != nil {
+ return updated, err
+ }
+
+ if sha256 != source.SHA256 || sriHash != source.Hash || force || source.Force {
log.Infof("rehashed %s: %s -> %s", name, source.SHA256, sha256)
source.SHA256 = sha256
+ source.Hash = sriHash
updated = true
}
diff --git a/internal/yae/utilities.go b/internal/yae/utilities.go
index ef9d334..73042fd 100644
--- a/internal/yae/utilities.go
+++ b/internal/yae/utilities.go
@@ -25,6 +25,16 @@ func FetchSHA256(url string, unpack bool) (string, error) {
return strings.Trim(lines[len(lines)-2], "\n"), nil
}
+func FetchSRIHash(sha256 string) (string, error) {
+ output, err := command("nix", false, "hash", "convert", "--hash-algo", "sha256", "--from", "nix32", sha256)
+
+ if err != nil {
+ return "", err
+ }
+
+ return strings.Trim(output, "\n"), nil
+}
+
func command(name string, show bool, args ...string) (string, error) {
executable, err := exec.LookPath(name)
out := []byte{}