Use SHA1 streaming hash for Etag

This commit is contained in:
Conrad Hoffmann 2022-03-16 14:47:47 +01:00
parent b3277148d7
commit e069bc0e9b

View File

@ -2,10 +2,11 @@ package storage
import (
"context"
"crypto/md5"
"crypto/sha1"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
@ -75,11 +76,18 @@ func (b *filesystemBackend) safePath(ctx context.Context, path string) (string,
}
func etagForFile(path string) (string, error) {
data, err := ioutil.ReadFile(path)
f, err := os.Open(path)
if err != nil {
return "", err
}
csum := md5.Sum(data)
defer f.Close()
h := sha1.New()
if _, err := io.Copy(h, f); err != nil {
return "", err
}
csum := h.Sum(nil)
return base64.StdEncoding.EncodeToString(csum[:]), nil
}