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 Copy

Kaloyan Raevb98d7f6634a5
diff --git a/backend/storj/fs.go b/backend/storj/fs.go
index b39e0b25d..9a0a5ebe2 100644
--- a/backend/storj/fs.go
+++ b/backend/storj/fs.go
@@ -160,6 +160,7 @@ var (
_ fs.ListRer = &Fs{}
_ fs.PutStreamer = &Fs{}
_ fs.Mover = &Fs{}
+ _ fs.Copier = &Fs{}
)
// NewFs creates a filesystem backed by Storj.
@@ -720,3 +721,43 @@ func (f *Fs) Move(ctx context.Context, src fs.Object, remote string) (fs.Object,
// Read the new object
return f.NewObject(ctx, remote)
}
+
+// Copy src to this remote using server-side copy 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.ErrorCantCopy
+func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object, error) {
+ srcObj, ok := src.(*Object)
+ if !ok {
+ fs.Debugf(src, "Can't copy - not same remote type")
+ return nil, fs.ErrorCantCopy
+ }
+
+ // Copy parameters
+ srcBucket, srcKey := bucket.Split(srcObj.absolute)
+ dstBucket, dstKey := f.absolute(remote)
+ options := uplink.CopyObjectOptions{}
+
+ // Do the copy
+ newObject, err := f.project.CopyObject(ctx, srcBucket, srcKey, dstBucket, dstKey, &options)
+ if err != nil {
+ // Make sure destination bucket exists
+ _, err := f.project.EnsureBucket(ctx, dstBucket)
+ if err != nil {
+ return nil, fmt.Errorf("copy object failed to create destination bucket: %w", err)
+ }
+ // And try again
+ newObject, err = f.project.CopyObject(ctx, srcBucket, srcKey, dstBucket, dstKey, &options)
+ if err != nil {
+ return nil, fmt.Errorf("copy object failed: %w", err)
+ }
+ }
+
+ // Return the new object
+ return newObjectFromUplink(f, remote, newObject), nil
+}
diff --git a/docs/content/overview.md b/docs/content/overview.md
index 790dbf7fd..eca35d8d4 100644
--- a/docs/content/overview.md
+++ b/docs/content/overview.md
@@ -504,7 +504,7 @@ upon backend-specific capabilities.
| Sia | No | No | No | No | No | No | Yes | No | No | Yes |
| SMB | No | No | Yes | Yes | No | No | Yes | No | No | Yes |
| SugarSync | Yes | Yes | Yes | Yes | No | No | Yes | Yes | No | Yes |
-| Storj | Yes † | No | Yes | No | No | Yes | Yes | No | No | No |
+| Storj | Yes † | Yes | 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 |