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)
|
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.
|
// DeleteFile deletes a single file respecting --dry-run and accumulating stats and errors.
|
||||||
func DeleteFile(dst Object) (err error) {
|
func DeleteFile(dst Object) (err error) {
|
||||||
if Config.DryRun {
|
if Config.DryRun {
|
||||||
|
|
|
@ -44,6 +44,7 @@ type syncCopyMove struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSyncCopyMove(fdst, fsrc Fs, Delete bool, DoMove bool) *syncCopyMove {
|
func newSyncCopyMove(fdst, fsrc Fs, Delete bool, DoMove bool) *syncCopyMove {
|
||||||
|
canServerSideMove := CanServerSideMove(fdst)
|
||||||
s := &syncCopyMove{
|
s := &syncCopyMove{
|
||||||
fdst: fdst,
|
fdst: fdst,
|
||||||
fsrc: fsrc,
|
fsrc: fsrc,
|
||||||
|
@ -67,12 +68,8 @@ func newSyncCopyMove(fdst, fsrc Fs, Delete bool, DoMove bool) *syncCopyMove {
|
||||||
s.noTraverse = false
|
s.noTraverse = false
|
||||||
}
|
}
|
||||||
if s.trackRenames {
|
if s.trackRenames {
|
||||||
// Don't track renames for remotes without server-side rename support.
|
// Don't track renames for remotes without server-side move support.
|
||||||
// Some remotes simulate rename by server-side copy and delete, so include
|
if !canServerSideMove {
|
||||||
// remotes that implements either Mover or Copier.
|
|
||||||
switch fdst.(type) {
|
|
||||||
case Mover, Copier:
|
|
||||||
default:
|
|
||||||
ErrorLog(fdst, "Ignoring --track-renames as the destination does not support server-side move or copy")
|
ErrorLog(fdst, "Ignoring --track-renames as the destination does not support server-side move or copy")
|
||||||
s.trackRenames = false
|
s.trackRenames = false
|
||||||
}
|
}
|
||||||
|
|
|
@ -617,9 +617,7 @@ func TestSyncWithTrackRenames(t *testing.T) {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
haveHash := r.fremote.Hashes().Overlap(r.flocal.Hashes()).GetOne() != fs.HashNone
|
haveHash := r.fremote.Hashes().Overlap(r.flocal.Hashes()).GetOne() != fs.HashNone
|
||||||
_, canMove := r.fremote.(fs.Mover)
|
canTrackRenames := haveHash && fs.CanServerSideMove(r.fremote)
|
||||||
_, canCopy := r.fremote.(fs.Copier)
|
|
||||||
canTrackRenames := haveHash && (canMove || canCopy)
|
|
||||||
t.Logf("Can track renames: %v", canTrackRenames)
|
t.Logf("Can track renames: %v", canTrackRenames)
|
||||||
|
|
||||||
f1 := r.WriteFile("potato", "Potato Content", t1)
|
f1 := r.WriteFile("potato", "Potato Content", t1)
|
||||||
|
|
Loading…
Reference in a new issue