Factor server side move detection
This commit is contained in:
parent
aa62e93094
commit
4aae7bcca6
3 changed files with 15 additions and 9 deletions
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue