Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

backend: skip hash calculation when the hashType is None - fixes #8518

Oleksiy Stashokbadf16cc3453
diff --git a/backend/local/local.go b/backend/local/local.go
index 9df4d454b..3a4f0b2de 100644
--- a/backend/local/local.go
+++ b/backend/local/local.go
@@ -1090,6 +1090,10 @@ func (o *Object) Remote() string {
// Hash returns the requested hash of a file as a lowercase hex string
func (o *Object) Hash(ctx context.Context, r hash.Type) (string, error) {
+ if r == hash.None {
+ return "", nil
+ }
+
// Check that the underlying file hasn't changed
o.fs.objectMetaMu.RLock()
oldtime := o.modTime
diff --git a/backend/local/local_internal_test.go b/backend/local/local_internal_test.go
index 03a30c218..b54cb3fae 100644
--- a/backend/local/local_internal_test.go
+++ b/backend/local/local_internal_test.go
@@ -204,6 +204,23 @@ func TestSymlinkError(t *testing.T) {
assert.Equal(t, errLinksAndCopyLinks, err)
}
+func TestHashWithTypeNone(t *testing.T) {
+ ctx := context.Background()
+ r := fstest.NewRun(t)
+ const filePath = "file.txt"
+ r.WriteFile(filePath, "content", time.Now())
+ f := r.Flocal.(*Fs)
+
+ // Get the object
+ o, err := f.NewObject(ctx, filePath)
+ require.NoError(t, err)
+
+ // Test the hash is as we expect
+ h, err := o.Hash(ctx, hash.None)
+ require.Empty(t, h)
+ require.NoError(t, err)
+}
+
// Test hashes on updating an object
func TestHashOnUpdate(t *testing.T) {
ctx := context.Background()
diff --git a/cmd/serve/s3/utils.go b/cmd/serve/s3/utils.go
index f10d238d3..5020df63a 100644
--- a/cmd/serve/s3/utils.go
+++ b/cmd/serve/s3/utils.go
@@ -45,6 +45,10 @@ func getFileHashByte(node any, hashType hash.Type) []byte {
}
func getFileHash(node any, hashType hash.Type) string {
+ if hashType == hash.None {
+ return ""
+ }
+
var o fs.Object
switch b := node.(type) {