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.
This commit is contained in:
Luke Granger-Brown 2021-03-22 19:25:55 +00:00
parent 11ed74003a
commit 75afddacc4
2 changed files with 4 additions and 3 deletions

View file

@ -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

View file

@ -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 {