From 97be9015a48f63bc055aaa80235f84894426b016 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 12 May 2023 11:44:01 +0100 Subject: [PATCH] union: implement missing methods Implement these missing methods: - CleanUp And declare these ones unimplementable: - UnWrap - WrapFs - SetWrapper - UserInfo - Disconnect - PublicLink - PutUnchecked - MergeDirs - OpenWriterAt --- backend/union/union.go | 19 +++++++++++++++++++ backend/union/union_test.go | 33 +++++++++++++++++++-------------- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/backend/union/union.go b/backend/union/union.go index 78a713896..268860621 100644 --- a/backend/union/union.go +++ b/backend/union/union.go @@ -801,6 +801,24 @@ func (f *Fs) Shutdown(ctx context.Context) error { return errs.Err() } +// CleanUp the trash in the Fs +// +// Implement this if you have a way of emptying the trash or +// otherwise cleaning up old versions of files. +func (f *Fs) CleanUp(ctx context.Context) error { + errs := Errors(make([]error, len(f.upstreams))) + multithread(len(f.upstreams), func(i int) { + u := f.upstreams[i] + if do := u.Features().CleanUp; do != nil { + err := do(ctx) + if err != nil { + errs[i] = fmt.Errorf("%s: %w", u.Name(), err) + } + } + }) + return errs.Err() +} + // NewFs constructs an Fs from the path. // // The returned Fs is the actual Fs, referenced by remote in the config @@ -963,4 +981,5 @@ var ( _ fs.Abouter = (*Fs)(nil) _ fs.ListRer = (*Fs)(nil) _ fs.Shutdowner = (*Fs)(nil) + _ fs.CleanUpper = (*Fs)(nil) ) diff --git a/backend/union/union_test.go b/backend/union/union_test.go index f5a9948f6..c9482c56c 100644 --- a/backend/union/union_test.go +++ b/backend/union/union_test.go @@ -11,6 +11,11 @@ import ( "github.com/rclone/rclone/fstest/fstests" ) +var ( + unimplementableFsMethods = []string{"UnWrap", "WrapFs", "SetWrapper", "UserInfo", "Disconnect", "PublicLink", "PutUnchecked", "MergeDirs", "OpenWriterAt"} + unimplementableObjectMethods = []string{} +) + // TestIntegration runs integration tests against the remote func TestIntegration(t *testing.T) { if *fstest.RemoteName == "" { @@ -18,8 +23,8 @@ func TestIntegration(t *testing.T) { } fstests.Run(t, &fstests.Opt{ RemoteName: *fstest.RemoteName, - UnimplementableFsMethods: []string{"OpenWriterAt", "DuplicateFiles"}, - UnimplementableObjectMethods: []string{"MimeType"}, + UnimplementableFsMethods: unimplementableFsMethods, + UnimplementableObjectMethods: unimplementableObjectMethods, }) } @@ -39,8 +44,8 @@ func TestStandard(t *testing.T) { {Name: name, Key: "create_policy", Value: "epmfs"}, {Name: name, Key: "search_policy", Value: "ff"}, }, - UnimplementableFsMethods: []string{"OpenWriterAt", "DuplicateFiles"}, - UnimplementableObjectMethods: []string{"MimeType"}, + UnimplementableFsMethods: unimplementableFsMethods, + UnimplementableObjectMethods: unimplementableObjectMethods, QuickTestOK: true, }) } @@ -61,8 +66,8 @@ func TestRO(t *testing.T) { {Name: name, Key: "create_policy", Value: "epmfs"}, {Name: name, Key: "search_policy", Value: "ff"}, }, - UnimplementableFsMethods: []string{"OpenWriterAt", "DuplicateFiles"}, - UnimplementableObjectMethods: []string{"MimeType"}, + UnimplementableFsMethods: unimplementableFsMethods, + UnimplementableObjectMethods: unimplementableObjectMethods, QuickTestOK: true, }) } @@ -83,8 +88,8 @@ func TestNC(t *testing.T) { {Name: name, Key: "create_policy", Value: "epmfs"}, {Name: name, Key: "search_policy", Value: "ff"}, }, - UnimplementableFsMethods: []string{"OpenWriterAt", "DuplicateFiles"}, - UnimplementableObjectMethods: []string{"MimeType"}, + UnimplementableFsMethods: unimplementableFsMethods, + UnimplementableObjectMethods: unimplementableObjectMethods, QuickTestOK: true, }) } @@ -105,8 +110,8 @@ func TestPolicy1(t *testing.T) { {Name: name, Key: "create_policy", Value: "lus"}, {Name: name, Key: "search_policy", Value: "all"}, }, - UnimplementableFsMethods: []string{"OpenWriterAt", "DuplicateFiles"}, - UnimplementableObjectMethods: []string{"MimeType"}, + UnimplementableFsMethods: unimplementableFsMethods, + UnimplementableObjectMethods: unimplementableObjectMethods, QuickTestOK: true, }) } @@ -127,8 +132,8 @@ func TestPolicy2(t *testing.T) { {Name: name, Key: "create_policy", Value: "rand"}, {Name: name, Key: "search_policy", Value: "ff"}, }, - UnimplementableFsMethods: []string{"OpenWriterAt", "DuplicateFiles"}, - UnimplementableObjectMethods: []string{"MimeType"}, + UnimplementableFsMethods: unimplementableFsMethods, + UnimplementableObjectMethods: unimplementableObjectMethods, QuickTestOK: true, }) } @@ -149,8 +154,8 @@ func TestPolicy3(t *testing.T) { {Name: name, Key: "create_policy", Value: "all"}, {Name: name, Key: "search_policy", Value: "all"}, }, - UnimplementableFsMethods: []string{"OpenWriterAt", "DuplicateFiles"}, - UnimplementableObjectMethods: []string{"MimeType"}, + UnimplementableFsMethods: unimplementableFsMethods, + UnimplementableObjectMethods: unimplementableObjectMethods, QuickTestOK: true, }) }