diff --git a/fs/operations/operations.go b/fs/operations/operations.go index a02aead24..081ceb7a7 100644 --- a/fs/operations/operations.go +++ b/fs/operations/operations.go @@ -1952,11 +1952,17 @@ func moveOrCopyFile(ctx context.Context, fdst fs.Fs, fsrc fs.Fs, dstFileName str return err } } - NoNeedTransfer, err := CompareOrCopyDest(ctx, fdst, dstObj, srcObj, copyDestDir, backupDir) - if err != nil { - return err + needTransfer := NeedTransfer(ctx, dstObj, srcObj) + if needTransfer { + NoNeedTransfer, err := CompareOrCopyDest(ctx, fdst, dstObj, srcObj, copyDestDir, backupDir) + if err != nil { + return err + } + if NoNeedTransfer { + needTransfer = false + } } - if !NoNeedTransfer && NeedTransfer(ctx, dstObj, srcObj) { + if needTransfer { // If destination already exists, then we must move it into --backup-dir if required if dstObj != nil && backupDir != nil { err = MoveBackupDir(ctx, backupDir, dstObj) diff --git a/fs/sync/sync.go b/fs/sync/sync.go index 052b867e8..2c671cf72 100644 --- a/fs/sync/sync.go +++ b/fs/sync/sync.go @@ -331,11 +331,17 @@ func (s *syncCopyMove) pairChecker(in *pipe, out *pipe, fraction int, wg *sync.W tr := accounting.Stats(s.ctx).NewCheckingTransfer(src) // Check to see if can store this if src.Storable() { - NoNeedTransfer, err := operations.CompareOrCopyDest(s.ctx, s.fdst, pair.Dst, pair.Src, s.compareCopyDest, s.backupDir) - if err != nil { - s.processError(err) + needTransfer := operations.NeedTransfer(s.ctx, pair.Dst, pair.Src) + if needTransfer { + NoNeedTransfer, err := operations.CompareOrCopyDest(s.ctx, s.fdst, pair.Dst, pair.Src, s.compareCopyDest, s.backupDir) + if err != nil { + s.processError(err) + } + if NoNeedTransfer { + needTransfer = false + } } - if !NoNeedTransfer && operations.NeedTransfer(s.ctx, pair.Dst, pair.Src) { + if needTransfer { // If files are treated as immutable, fail if destination exists and does not match if s.ci.Immutable && pair.Dst != nil { err := fs.CountError(fserrors.NoRetryError(fs.ErrorImmutableModified))