From eeab7a0a434264d318468e52ad4756d61572ba39 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Wed, 20 Mar 2019 12:40:52 +0000 Subject: [PATCH] crypt: Implement Optional methods SetTier, GetTier - fixes #2895 This implements optional methods on Object - ID - SetTier - GetTier And declares that it will not implement MimeType for the FsCheck test. --- backend/crypt/crypt.go | 33 +++++++++++++++++++++++++++++++++ backend/crypt/crypt_test.go | 10 +++++++--- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/backend/crypt/crypt.go b/backend/crypt/crypt.go index 6e76cde9f..234b1b1cf 100644 --- a/backend/crypt/crypt.go +++ b/backend/crypt/crypt.go @@ -169,6 +169,8 @@ func NewFs(name, rpath string, m configmap.Mapper) (fs.Fs, error) { WriteMimeType: false, BucketBased: true, CanHaveEmptyDirectories: true, + SetTier: true, + GetTier: true, }).Fill(f).Mask(wrappedFs).WrapsFs(f, wrappedFs) return f, err @@ -839,6 +841,34 @@ func (o *ObjectInfo) Hash(hash hash.Type) (string, error) { return "", nil } +// ID returns the ID of the Object if known, or "" if not +func (o *Object) ID() string { + do, ok := o.Object.(fs.IDer) + if !ok { + return "" + } + return do.ID() +} + +// SetTier performs changing storage tier of the Object if +// multiple storage classes supported +func (o *Object) SetTier(tier string) error { + do, ok := o.Object.(fs.SetTierer) + if !ok { + return errors.New("crypt: underlying remote does not support SetTier") + } + return do.SetTier(tier) +} + +// GetTier returns storage tier or class of the Object +func (o *Object) GetTier() string { + do, ok := o.Object.(fs.GetTierer) + if !ok { + return "" + } + return do.GetTier() +} + // Check the interfaces are satisfied var ( _ fs.Fs = (*Fs)(nil) @@ -860,4 +890,7 @@ var ( _ fs.ObjectInfo = (*ObjectInfo)(nil) _ fs.Object = (*Object)(nil) _ fs.ObjectUnWrapper = (*Object)(nil) + _ fs.IDer = (*Object)(nil) + _ fs.SetTierer = (*Object)(nil) + _ fs.GetTierer = (*Object)(nil) ) diff --git a/backend/crypt/crypt_test.go b/backend/crypt/crypt_test.go index 4acf61a46..1558915c4 100644 --- a/backend/crypt/crypt_test.go +++ b/backend/crypt/crypt_test.go @@ -21,8 +21,9 @@ func TestIntegration(t *testing.T) { t.Skip("Skipping as -remote not set") } fstests.Run(t, &fstests.Opt{ - RemoteName: *fstest.RemoteName, - NilObject: (*crypt.Object)(nil), + RemoteName: *fstest.RemoteName, + NilObject: (*crypt.Object)(nil), + UnimplementableObjectMethods: []string{"MimeType"}, }) } @@ -42,6 +43,7 @@ func TestStandard(t *testing.T) { {Name: name, Key: "password", Value: obscure.MustObscure("potato")}, {Name: name, Key: "filename_encryption", Value: "standard"}, }, + UnimplementableObjectMethods: []string{"MimeType"}, }) } @@ -61,6 +63,7 @@ func TestOff(t *testing.T) { {Name: name, Key: "password", Value: obscure.MustObscure("potato2")}, {Name: name, Key: "filename_encryption", Value: "off"}, }, + UnimplementableObjectMethods: []string{"MimeType"}, }) } @@ -80,6 +83,7 @@ func TestObfuscate(t *testing.T) { {Name: name, Key: "password", Value: obscure.MustObscure("potato2")}, {Name: name, Key: "filename_encryption", Value: "obfuscate"}, }, - SkipBadWindowsCharacters: true, + SkipBadWindowsCharacters: true, + UnimplementableObjectMethods: []string{"MimeType"}, }) }