internal/pkg: rename archive checksum helpers
All checks were successful
Test / Create distribution (push) Successful in 1m7s
Test / Sandbox (push) Successful in 2m50s
Test / ShareFS (push) Successful in 3m50s
Test / Hakurei (push) Successful in 3m54s
Test / Sandbox (race detector) (push) Successful in 5m41s
Test / Hakurei (race detector) (push) Successful in 6m39s
Test / Flake checks (push) Successful in 1m41s

These names are more consistent with other helper names, so rename them while the API is still internal.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-06-04 14:13:20 +09:00
parent 4d04f86f4a
commit 729be19af3
6 changed files with 20 additions and 19 deletions

View File

@@ -262,8 +262,8 @@ func Write(fsys fs.FS, root string, w io.Writer) error {
return aw.Close() return aw.Close()
} }
// HashFS returns a checksum produced by hashing the result of [Flatten]. // SumFS saves checksum of the archive of fsys to the value pointed to by buf.
func HashFS(buf *Checksum, fsys fs.FS, root string) error { func SumFS(buf *Checksum, fsys fs.FS, root string) error {
h := sha512.New384() h := sha512.New384()
if err := Write(fsys, root, h); err != nil { if err := Write(fsys, root, h); err != nil {
return err return err
@@ -272,7 +272,8 @@ func HashFS(buf *Checksum, fsys fs.FS, root string) error {
return nil return nil
} }
// HashDir returns a checksum produced by hashing the result of [Flatten]. // SumDir saves checksum of the archive of directory at pathname to the value
func HashDir(buf *Checksum, pathname *check.Absolute) error { // pointed to by buf.
return HashFS(buf, os.DirFS(pathname.String()), ".") func SumDir(buf *Checksum, pathname *check.Absolute) error {
return SumFS(buf, os.DirFS(pathname.String()), ".")
} }

View File

@@ -141,10 +141,10 @@ func TestArchive(t *testing.T) {
t.Parallel() t.Parallel()
var got pkg.Checksum var got pkg.Checksum
if err := pkg.HashFS(&got, tc.fsys, "."); err != nil { if err := pkg.SumFS(&got, tc.fsys, "."); err != nil {
t.Fatalf("HashFS: error = %v", err) t.Fatalf("SumFS: error = %v", err)
} else if got != tc.sum { } else if got != tc.sum {
t.Fatalf("HashFS: %v", &pkg.ChecksumMismatchError{ t.Fatalf("SumFS: %v", &pkg.ChecksumMismatchError{
Got: got, Got: got,
Want: tc.sum, Want: tc.sum,
}) })

View File

@@ -283,8 +283,8 @@ func TestClean(t *testing.T) {
want := tc.want.hash() want := tc.want.hash()
var checksum pkg.Checksum var checksum pkg.Checksum
if err = pkg.HashDir(&checksum, base); err != nil { if err = pkg.SumDir(&checksum, base); err != nil {
t.Fatalf("HashDir: error = %v", err) t.Fatalf("SumDir: error = %v", err)
} else if checksum != want { } else if checksum != want {
t.Error(expectsFrom(base.String())) t.Error(expectsFrom(base.String()))
} }

View File

@@ -1007,7 +1007,7 @@ func (c *Cache) Scrub(checks int) error {
pathname := dir.Append(ent.Name()) pathname := dir.Append(ent.Name())
if ent.IsDir() { if ent.IsDir() {
if err := HashDir(got, pathname); err != nil { if err := SumDir(got, pathname); err != nil {
addErr(pathname, err) addErr(pathname, err)
return true return true
} }
@@ -2132,7 +2132,7 @@ func (c *Cache) cure(a Artifact, curesExempt bool) (
} }
var gotChecksum Checksum var gotChecksum Checksum
if err = HashFS( if err = SumFS(
&gotChecksum, &gotChecksum,
dotOverrideFS{os.DirFS(t.work.String()).(dirFS)}, dotOverrideFS{os.DirFS(t.work.String()).(dirFS)},
".", ".",

View File

@@ -357,7 +357,7 @@ type expectsFS fstest.MapFS
// hash computes the checksum of e. // hash computes the checksum of e.
func (e expectsFS) hash() (checksum pkg.Checksum) { func (e expectsFS) hash() (checksum pkg.Checksum) {
if err := pkg.HashFS(&checksum, fstest.MapFS(e), "."); err != nil { if err := pkg.SumFS(&checksum, fstest.MapFS(e), "."); err != nil {
panic(err) panic(err)
} }
return return
@@ -561,8 +561,8 @@ func checkWithCache(t *testing.T, testCases []cacheTestCase) {
want := tc.want.hash() want := tc.want.hash()
var checksum pkg.Checksum var checksum pkg.Checksum
if err := pkg.HashDir(&checksum, base); err != nil { if err := pkg.SumDir(&checksum, base); err != nil {
t.Fatalf("HashDir: error = %v", err) t.Fatalf("SumDir: error = %v", err)
} else if checksum != want { } else if checksum != want {
t.Fatal(expectsFrom(base.String())) t.Fatal(expectsFrom(base.String()))
} }
@@ -581,8 +581,8 @@ func checkWithCache(t *testing.T, testCases []cacheTestCase) {
} }
// validate again to make sure scrub did not condemn anything // validate again to make sure scrub did not condemn anything
if err := pkg.HashDir(&checksum, base); err != nil { if err := pkg.SumDir(&checksum, base); err != nil {
t.Fatalf("HashDir: error = %v", err) t.Fatalf("SumDir: error = %v", err)
} else if checksum != want { } else if checksum != want {
t.Fatalf("(scrubbed) %s", expectsFrom(base.String())) t.Fatalf("(scrubbed) %s", expectsFrom(base.String()))
} }

View File

@@ -81,8 +81,8 @@ func TestColdboot(t *testing.T) {
} }
var checksum pkg.Checksum var checksum pkg.Checksum
if err = pkg.HashDir(&checksum, check.MustAbs(d)); err != nil { if err = pkg.SumDir(&checksum, check.MustAbs(d)); err != nil {
t.Fatalf("HashDir: error = %v", err) t.Fatalf("SumDir: error = %v", err)
} }
wantChecksum := pkg.MustDecode("mEy_Lf5KotThm7OwMx7yTKZh5HCCyaB41pVAvI9uDMgVQFM91iosBLYsRm8bDsX8") wantChecksum := pkg.MustDecode("mEy_Lf5KotThm7OwMx7yTKZh5HCCyaB41pVAvI9uDMgVQFM91iosBLYsRm8bDsX8")