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

storj: implement server side Move

Nick Craig-Woodbf9c68c88a98
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 |