From 75afddacc48c37a8c8004a856ae03d70c1144923 Mon Sep 17 00:00:00 2001
From: Luke Granger-Brown <hg@lukegb.com>
Date: Mon, 22 Mar 2021 19:25:55 +0000
Subject: [PATCH] fup/hashfs: actually hash the thing

This previous behaviour was to, instead of hashing the file, just return the
first few bytes of it, which is neither intuitive nor the behaviour I was
looking for.
---
 web/fup/hashfs/hashfs.go      | 3 ++-
 web/fup/hashfs/hashfs_test.go | 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/web/fup/hashfs/hashfs.go b/web/fup/hashfs/hashfs.go
index 2eafa5d126..362275b7f2 100644
--- a/web/fup/hashfs/hashfs.go
+++ b/web/fup/hashfs/hashfs.go
@@ -105,7 +105,8 @@ func (s *FS) build() error {
 		if err != nil {
 			return fmt.Errorf("reading %q: %w", fpath, err)
 		}
-		hexDigest := hex.EncodeToString(sha512.New().Sum(bs)[:6])
+		fileHash := sha512.Sum512(bs)
+		hexDigest := hex.EncodeToString(fileHash[:6])
 
 		// and fix it up in the filename.
 		oldName := fpath
diff --git a/web/fup/hashfs/hashfs_test.go b/web/fup/hashfs/hashfs_test.go
index 7374824627..8ae5d084ce 100644
--- a/web/fup/hashfs/hashfs_test.go
+++ b/web/fup/hashfs/hashfs_test.go
@@ -26,8 +26,8 @@ func TestHashingFS(t *testing.T) {
 		newName     string
 		wantContent string
 	}{
-		{"foo", "foo.68656c6c6f2c", "hello, world"},
-		{"bar/bar.txt", "bar/bar.666f6f206261.txt", "foo bar baz"},
+		{"foo", "foo.8710339dcb68", "hello, world"},
+		{"bar/bar.txt", "bar/bar.bce50343a56f.txt", "foo bar baz"},
 	}
 
 	for _, tc := range tcs {