aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/pkg/dir.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-01-16 02:09:12 +0900
committerOphestra <cat@gensokyo.uk>2026-01-16 02:47:59 +0900
commit5936e6a4aab541a437fa9464468b51f91d019a2a (patch)
tree1aa362806b3f5a0522ee82c2f0b27c0a655476db /internal/pkg/dir.go
parent3499a82785f8cb82bfe528875391d76d5e03c3de (diff)
internal/pkg: parallelise scrub
This significantly improves scrubbing performance. Since the cache directory structure is friendly to simultaneous access, this is possible without synchronisation. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/pkg/dir.go')
-rw-r--r--internal/pkg/dir.go11
1 files changed, 6 insertions, 5 deletions
diff --git a/internal/pkg/dir.go b/internal/pkg/dir.go
index e446c569..d0c3668d 100644
--- a/internal/pkg/dir.go
+++ b/internal/pkg/dir.go
@@ -196,15 +196,16 @@ func Flatten(fsys fs.FS, root string, w io.Writer) (n int, err error) {
}
// HashFS returns a checksum produced by hashing the result of [Flatten].
-func HashFS(fsys fs.FS, root string) (Checksum, error) {
+func HashFS(buf *Checksum, fsys fs.FS, root string) error {
h := sha512.New384()
if _, err := Flatten(fsys, root, h); err != nil {
- return Checksum{}, err
+ return err
}
- return (Checksum)(h.Sum(nil)), nil
+ h.Sum(buf[:0])
+ return nil
}
// HashDir returns a checksum produced by hashing the result of [Flatten].
-func HashDir(pathname *check.Absolute) (Checksum, error) {
- return HashFS(os.DirFS(pathname.String()), ".")
+func HashDir(buf *Checksum, pathname *check.Absolute) error {
+ return HashFS(buf, os.DirFS(pathname.String()), ".")
}