pairChecker reads Objects~s on in send to out if they need transferring. FIXME potentially doing lots of hashes at once
(in *pipe, out *pipe, fraction int, wg *sync.WaitGroup)
| 369 | // |
| 370 | // FIXME potentially doing lots of hashes at once |
| 371 | func (s *syncCopyMove) pairChecker(in *pipe, out *pipe, fraction int, wg *sync.WaitGroup) { |
| 372 | defer wg.Done() |
| 373 | for { |
| 374 | pair, ok := in.GetMax(s.inCtx, fraction) |
| 375 | if !ok { |
| 376 | return |
| 377 | } |
| 378 | src := pair.Src |
| 379 | var err error |
| 380 | tr := accounting.Stats(s.ctx).NewCheckingTransfer(src, "checking") |
| 381 | // Check to see if can store this |
| 382 | if src.Storable() { |
| 383 | needTransfer := operations.NeedTransfer(s.ctx, pair.Dst, pair.Src) |
| 384 | if needTransfer { |
| 385 | NoNeedTransfer, err := operations.CompareOrCopyDest(s.ctx, s.fdst, pair.Dst, pair.Src, s.compareCopyDest, s.backupDir) |
| 386 | if err != nil { |
| 387 | s.processError(err) |
| 388 | s.logger(s.ctx, operations.TransferError, pair.Src, pair.Dst, err) |
| 389 | } |
| 390 | if NoNeedTransfer { |
| 391 | needTransfer = false |
| 392 | } |
| 393 | } |
| 394 | // Fix case for case insensitive filesystems |
| 395 | if s.ci.FixCase && !s.ci.Immutable && src.Remote() != pair.Dst.Remote() { |
| 396 | if newDst, err := operations.Move(s.ctx, s.fdst, nil, src.Remote(), pair.Dst); err != nil { |
| 397 | fs.Errorf(pair.Dst, "Error while attempting to rename to %s: %v", src.Remote(), err) |
| 398 | s.processError(err) |
| 399 | } else { |
| 400 | fs.Infof(pair.Dst, "Fixed case by renaming to: %s", src.Remote()) |
| 401 | pair.Dst = newDst |
| 402 | } |
| 403 | } |
| 404 | if needTransfer { |
| 405 | // If files are treated as immutable, fail if destination exists and does not match |
| 406 | if s.ci.Immutable && pair.Dst != nil { |
| 407 | err := fs.CountError(s.ctx, fserrors.NoRetryError(fs.ErrorImmutableModified)) |
| 408 | fs.Errorf(pair.Dst, "Source and destination exist but do not match: %v", err) |
| 409 | s.processError(err) |
| 410 | } else { |
| 411 | if pair.Dst != nil { |
| 412 | s.markDirModifiedObject(pair.Dst) |
| 413 | } else { |
| 414 | s.markDirModifiedObject(src) |
| 415 | } |
| 416 | // If destination already exists, then we must move it into --backup-dir if required |
| 417 | if pair.Dst != nil && s.backupDir != nil { |
| 418 | err := operations.MoveBackupDir(s.ctx, s.backupDir, pair.Dst) |
| 419 | if err != nil { |
| 420 | s.processError(err) |
| 421 | s.logger(s.ctx, operations.TransferError, pair.Src, pair.Dst, err) |
| 422 | } else { |
| 423 | // If successful zero out the dst as it is no longer there and copy the file |
| 424 | pair.Dst = nil |
| 425 | ok = out.Put(s.inCtx, pair) |
| 426 | if !ok { |
| 427 | return |
| 428 | } |
no test coverage detected