"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
fs/hash: install QuickXorHash as a supported rclone hash type #2262
Nick Craig-Woodbcdb7719c699
diff --git a/fs/hash/hash.go b/fs/hash/hash.goindex 83d72cf24..57b206bfd 100644--- a/fs/hash/hash.go+++ b/fs/hash/hash.go@@ -10,6 +10,7 @@ import ("strings""github.com/ncw/rclone/backend/dropbox/dbhash"+ "github.com/ncw/rclone/backend/onedrive/quickxorhash""github.com/pkg/errors")@@ -31,19 +32,24 @@ const (// https://www.dropbox.com/developers/reference/content-hashDropbox+ // QuickXorHash indicates Microsoft onedrive hash+ // https://docs.microsoft.com/en-us/onedrive/developer/code-snippets/quickxorhash+ QuickXorHash+// None indicates no hashes are supportedNone Type = 0)// Supported returns a set of all the supported hashes by// HashStream and MultiHasher.-var Supported = NewHashSet(MD5, SHA1, Dropbox)+var Supported = NewHashSet(MD5, SHA1, Dropbox, QuickXorHash)// Width returns the width in characters for any HashTypevar Width = map[Type]int{- MD5: 32,- SHA1: 40,- Dropbox: 64,+ MD5: 32,+ SHA1: 40,+ Dropbox: 64,+ QuickXorHash: 40,}// Stream will calculate hashes of all supported hash types.@@ -81,6 +87,8 @@ func (h Type) String() string {return "SHA-1"case Dropbox:return "DropboxHash"+ case QuickXorHash:+ return "QuickXorHash"default:err := fmt.Sprintf("internal error: unknown hash type: 0x%x", int(h))panic(err)@@ -98,6 +106,8 @@ func (h *Type) Set(s string) error {*h = SHA1case "DropboxHash":*h = Dropbox+ case "QuickXorHash":+ *h = QuickXorHashdefault:return errors.Errorf("Unknown hash type %q", s)}@@ -126,6 +136,8 @@ func fromTypes(set Set) (map[Type]hash.Hash, error) {hashers[t] = sha1.New()case Dropbox:hashers[t] = dbhash.New()+ case QuickXorHash:+ hashers[t] = quickxorhash.New()default:err := fmt.Sprintf("internal error: Unsupported hash type %v", t)panic(err)diff --git a/fs/hash/hash_test.go b/fs/hash/hash_test.goindex ba41621f3..92ef91ab1 100644--- a/fs/hash/hash_test.go+++ b/fs/hash/hash_test.go@@ -69,18 +69,20 @@ var hashTestSet = []hashTest{{input: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14},output: map[hash.Type]string{- hash.MD5: "bf13fc19e5151ac57d4252e0e0f87abe",- hash.SHA1: "3ab6543c08a75f292a5ecedac87ec41642d12166",- hash.Dropbox: "214d2fcf3566e94c99ad2f59bd993daca46d8521a0c447adf4b324f53fddc0c7",+ hash.MD5: "bf13fc19e5151ac57d4252e0e0f87abe",+ hash.SHA1: "3ab6543c08a75f292a5ecedac87ec41642d12166",+ hash.Dropbox: "214d2fcf3566e94c99ad2f59bd993daca46d8521a0c447adf4b324f53fddc0c7",+ hash.QuickXorHash: "0110c000085000031c0001095ec00218d0000700",},},// Empty data set{input: []byte{},output: map[hash.Type]string{- hash.MD5: "d41d8cd98f00b204e9800998ecf8427e",- hash.SHA1: "da39a3ee5e6b4b0d3255bfef95601890afd80709",- hash.Dropbox: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",+ hash.MD5: "d41d8cd98f00b204e9800998ecf8427e",+ hash.SHA1: "da39a3ee5e6b4b0d3255bfef95601890afd80709",+ hash.Dropbox: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",+ hash.QuickXorHash: "0000000000000000000000000000000000000000",},},}@@ -95,13 +97,13 @@ func TestMultiHasher(t *testing.T) {for k, v := range sums {expect, ok := test.output[k]require.True(t, ok, "test output for hash not found")- assert.Equal(t, v, expect)+ assert.Equal(t, expect, v)}// Test that all are presentfor k, v := range test.output {expect, ok := sums[k]require.True(t, ok, "test output for hash not found")- assert.Equal(t, v, expect)+ assert.Equal(t, expect, v)}}}@@ -151,8 +153,8 @@ func TestHashStreamTypes(t *testing.T) {}func TestHashSetStringer(t *testing.T) {- h := hash.NewHashSet(hash.SHA1, hash.MD5, hash.Dropbox)- assert.Equal(t, h.String(), "[MD5, SHA-1, DropboxHash]")+ h := hash.NewHashSet(hash.SHA1, hash.MD5, hash.Dropbox, hash.QuickXorHash)+ assert.Equal(t, h.String(), "[MD5, SHA-1, DropboxHash, QuickXorHash]")h = hash.NewHashSet(hash.SHA1)assert.Equal(t, h.String(), "[SHA-1]")h = hash.NewHashSet()