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

Factor server side move detection

ncw4aae7bcca63e
diff --git a/fs/operations.go b/fs/operations.go
index bade42513..8e97ea79d 100644
--- a/fs/operations.go
+++ b/fs/operations.go
@@ -385,6 +385,17 @@ func Move(fdst Fs, dst Object, remote string, src Object) (err error) {
return DeleteFile(src)
}
+// CanServerSideMove returns true if fdst support server side moves or
+// server side copies
+//
+// Some remotes simulate rename by server-side copy and delete, so include
+// remotes that implements either Mover or Copier.
+func CanServerSideMove(fdst Fs) bool {
+ _, canMove := fdst.(Mover)
+ _, canCopy := fdst.(Copier)
+ return canMove || canCopy
+}
+
// DeleteFile deletes a single file respecting --dry-run and accumulating stats and errors.
func DeleteFile(dst Object) (err error) {
if Config.DryRun {
diff --git a/fs/sync.go b/fs/sync.go
index fc93d913f..9c6558812 100644
--- a/fs/sync.go
+++ b/fs/sync.go
@@ -44,6 +44,7 @@ type syncCopyMove struct {
}
func newSyncCopyMove(fdst, fsrc Fs, Delete bool, DoMove bool) *syncCopyMove {
+ canServerSideMove := CanServerSideMove(fdst)
s := &syncCopyMove{
fdst: fdst,
fsrc: fsrc,
@@ -67,12 +68,8 @@ func newSyncCopyMove(fdst, fsrc Fs, Delete bool, DoMove bool) *syncCopyMove {
s.noTraverse = false
}
if s.trackRenames {
- // Don't track renames for remotes without server-side rename support.
- // Some remotes simulate rename by server-side copy and delete, so include
- // remotes that implements either Mover or Copier.
- switch fdst.(type) {
- case Mover, Copier:
- default:
+ // Don't track renames for remotes without server-side move support.
+ if !canServerSideMove {
ErrorLog(fdst, "Ignoring --track-renames as the destination does not support server-side move or copy")
s.trackRenames = false
}
diff --git a/fs/sync_test.go b/fs/sync_test.go
index 486984b93..144b41877 100644
--- a/fs/sync_test.go
+++ b/fs/sync_test.go
@@ -617,9 +617,7 @@ func TestSyncWithTrackRenames(t *testing.T) {
}()
haveHash := r.fremote.Hashes().Overlap(r.flocal.Hashes()).GetOne() != fs.HashNone
- _, canMove := r.fremote.(fs.Mover)
- _, canCopy := r.fremote.(fs.Copier)
- canTrackRenames := haveHash && (canMove || canCopy)
+ canTrackRenames := haveHash && fs.CanServerSideMove(r.fremote)
t.Logf("Can track renames: %v", canTrackRenames)
f1 := r.WriteFile("potato", "Potato Content", t1)