From 4aae7bcca63e8e76821851ec925672285b88d41b Mon Sep 17 00:00:00 2001 From: ncw Date: Tue, 10 Jan 2017 20:03:55 +0000 Subject: [PATCH] Factor server side move detection --- fs/operations.go | 11 +++++++++++ fs/sync.go | 9 +++------ fs/sync_test.go | 4 +--- 3 files changed, 15 insertions(+), 9 deletions(-) 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)