From bf9c68c88a980d2c98a6b51f2f015f1307e2f91b Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Mon, 14 Mar 2022 15:44:44 +0000 Subject: [PATCH] storj: implement server side Move --- backend/storj/fs.go | 32 ++++++++++++++++++++++++++++++++ docs/content/overview.md | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/backend/storj/fs.go b/backend/storj/fs.go index d708989d7..97c126620 100644 --- a/backend/storj/fs.go +++ b/backend/storj/fs.go @@ -159,6 +159,7 @@ var ( _ fs.Fs = &Fs{} _ fs.ListRer = &Fs{} _ fs.PutStreamer = &Fs{} + _ fs.Mover = &Fs{} ) // NewFs creates a filesystem backed by Storj. @@ -679,3 +680,34 @@ func newPrefix(prefix string) string { return prefix + "/" } + +// Move src to this remote using server-side move operations. +// +// This is stored with the remote path given +// +// It returns the destination Object and a possible error +// +// Will only be called if src.Fs().Name() == f.Name() +// +// If it isn't possible then return fs.ErrorCantMove +func (f *Fs) Move(ctx context.Context, src fs.Object, remote string) (fs.Object, error) { + srcObj, ok := src.(*Object) + if !ok { + fs.Debugf(src, "Can't move - not same remote type") + return nil, fs.ErrorCantMove + } + + // Move parameters + srcBucket, srcKey := bucket.Split(srcObj.absolute) + dstBucket, dstKey := f.absolute(remote) + options := uplink.MoveObjectOptions{} + + // Do the move + err := f.project.MoveObject(ctx, srcBucket, srcKey, dstBucket, dstKey, &options) + if err != nil { + return nil, fmt.Errorf("rename object failed: %w", err) + } + + // Read the new object + return f.NewObject(ctx, remote) +} diff --git a/docs/content/overview.md b/docs/content/overview.md index 023225f5b..995082d85 100644 --- a/docs/content/overview.md +++ b/docs/content/overview.md @@ -441,7 +441,7 @@ upon backend-specific capabilities. | Seafile | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | | SFTP | No | No | Yes | Yes | No | No | Yes | No | Yes | Yes | | SugarSync | Yes | Yes | Yes | Yes | No | No | Yes | Yes | No | Yes | -| Storj | Yes † | No | No | No | No | Yes | Yes | No | No | No | +| Storj | Yes † | No | Yes | No | No | Yes | Yes | No | No | No | | Uptobox | No | Yes | Yes | Yes | No | No | No | No | No | No | | WebDAV | Yes | Yes | Yes | Yes | No | No | Yes ‡ | No | Yes | Yes | | Yandex Disk | Yes | Yes | Yes | Yes | Yes | No | Yes | Yes | Yes | Yes |