diff --git a/fs/sync/sync.go b/fs/sync/sync.go index 6ec0c074f..b3eca0a86 100644 --- a/fs/sync/sync.go +++ b/fs/sync/sync.go @@ -380,6 +380,20 @@ func (s *syncCopyMove) pairChecker(in *pipe, out *pipe, fraction int, wg *sync.W tr := accounting.Stats(s.ctx).NewCheckingTransfer(src, "checking") // Check to see if can store this if src.Storable() { + // Fix case for case insensitive filesystems before checking + // whether a transfer is needed, since NeedTransfer may delete + // the destination (when content matches but modtime can't be + // set without re-upload), which would cause the rename below + // to fail with a "not found" error. + if s.ci.FixCase && !s.ci.Immutable && src.Remote() != pair.Dst.Remote() { + if newDst, err := operations.Move(s.ctx, s.fdst, nil, src.Remote(), pair.Dst); err != nil { + fs.Errorf(pair.Dst, "Error while attempting to rename to %s: %v", src.Remote(), err) + s.processError(err) + } else { + fs.Infof(pair.Dst, "Fixed case by renaming to: %s", src.Remote()) + pair.Dst = newDst + } + } 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) @@ -391,16 +405,6 @@ func (s *syncCopyMove) pairChecker(in *pipe, out *pipe, fraction int, wg *sync.W needTransfer = false } } - // Fix case for case insensitive filesystems - if s.ci.FixCase && !s.ci.Immutable && src.Remote() != pair.Dst.Remote() { - if newDst, err := operations.Move(s.ctx, s.fdst, nil, src.Remote(), pair.Dst); err != nil { - fs.Errorf(pair.Dst, "Error while attempting to rename to %s: %v", src.Remote(), err) - s.processError(err) - } else { - fs.Infof(pair.Dst, "Fixed case by renaming to: %s", src.Remote()) - pair.Dst = newDst - } - } if needTransfer { // If files are treated as immutable, fail if destination exists and does not match if s.ci.Immutable && pair.Dst != nil {