move: if --check-first and --order-by are set then delete with perfect ordering

If using rclone move and --check-first and --order-by then rclone uses
the transfer routine to delete files to ensure perfect ordering.

This will cause the transfer stats to have a larger than expected
number of items in it so we don't enable this by default.

Fixes #6033
This commit is contained in:
Nick Craig-Wood 2023-03-08 13:03:05 +00:00
parent 4edcd16f5f
commit dd6e229327
4 changed files with 38 additions and 4 deletions

View file

@ -377,6 +377,14 @@ func (s *syncCopyMove) pairChecker(in *pipe, out *pipe, fraction int, wg *sync.W
fs.Logf(src, "Not removing source file as it is the same file as the destination")
} else if s.ci.IgnoreExisting {
fs.Debugf(src, "Not removing source file as destination file exists and --ignore-existing is set")
} else if s.checkFirst && s.ci.OrderBy != "" {
// If we want perfect ordering then use the transfers to delete the file
//
// We send src == dst, to say we want the src deleted
ok = out.Put(s.ctx, fs.ObjectPair{Src: src, Dst: src})
if !ok {
return
}
} else {
s.processError(operations.DeleteFile(s.ctx, src))
}
@ -417,10 +425,16 @@ func (s *syncCopyMove) pairCopyOrMove(ctx context.Context, in *pipe, fdst fs.Fs,
return
}
src := pair.Src
dst := pair.Dst
if s.DoMove {
_, err = operations.Move(ctx, fdst, pair.Dst, src.Remote(), src)
if src != dst {
_, err = operations.Move(ctx, fdst, dst, src.Remote(), src)
} else {
// src == dst signals delete the src
err = operations.DeleteFile(ctx, src)
}
} else {
_, err = operations.Copy(ctx, fdst, pair.Dst, src.Remote(), src)
_, err = operations.Copy(ctx, fdst, dst, src.Remote(), src)
}
s.processError(err)
}