MCPcopy Index your code
hub / github.com/rclone/rclone / Move

Method Move

backend/cache/cache.go:1612–1708  ·  view source on GitHub ↗

Move src to this remote using server-side move operations.

(ctx context.Context, src fs.Object, remote string)

Source from the content-addressed store, hash-verified

1610
1611// Move src to this remote using server-side move operations.
1612func (f *Fs) Move(ctx context.Context, src fs.Object, remote string) (fs.Object, error) {
1613 fs.Debugf(f, "moving obj '%s' -> %s", src, remote)
1614
1615 // if source fs doesn't support move abort
1616 do := f.Fs.Features().Move
1617 if do == nil {
1618 fs.Errorf(src, "source remote (%v) doesn't support Move", src.Fs())
1619 return nil, fs.ErrorCantMove
1620 }
1621 // the source must be a cached object or we abort
1622 srcObj, ok := src.(*Object)
1623 if !ok {
1624 fs.Errorf(srcObj, "can't move - not same remote type")
1625 return nil, fs.ErrorCantMove
1626 }
1627 // both the source cache fs and this cache fs need to wrap the same remote
1628 if srcObj.CacheFs.Fs.Name() != f.Fs.Name() {
1629 fs.Errorf(srcObj, "can't move - not wrapping same remote types")
1630 return nil, fs.ErrorCantMove
1631 }
1632 // refresh from source or abort
1633 if err := srcObj.refreshFromSource(ctx, false); err != nil {
1634 fs.Errorf(f, "can't move %v - %v", src, err)
1635 return nil, fs.ErrorCantMove
1636 }
1637
1638 // if this is a temp object then we perform the changes locally
1639 if srcObj.isTempFile() {
1640 // we check if the feature is still active
1641 if f.opt.TempWritePath == "" {
1642 fs.Errorf(srcObj, "can't move - this is a local cached file but this feature is turned off this run")
1643 return nil, fs.ErrorCantMove
1644 }
1645 // pause background uploads
1646 f.backgroundRunner.pause()
1647 defer f.backgroundRunner.play()
1648
1649 // started uploads can't be moved until they complete
1650 if srcObj.tempFileStartedUpload() {
1651 fs.Errorf(srcObj, "can't move - upload has already started. need to finish that")
1652 return nil, fs.ErrorCantMove
1653 }
1654 do = f.tempFs.Features().Move
1655
1656 // we must also update the pending queue
1657 err := f.cache.updatePendingUpload(srcObj.abs(), func(item *tempUploadInfo) error {
1658 item.DestPath = path.Join(f.Root(), remote)
1659 item.AddedOn = time.Now()
1660 return nil
1661 })
1662 if err != nil {
1663 fs.Errorf(srcObj, "failed to rename queued file for upload: %v", err)
1664 return nil, fs.ErrorCantMove
1665 }
1666 fs.Debugf(srcObj, "move: queued file moved to %v", remote)
1667 }
1668
1669 obj, err := do(ctx, srcObj.Object, remote)

Callers

nothing calls this directly

Calls 15

RootMethod · 0.95
RemoteMethod · 0.95
DebugfFunction · 0.92
ErrorfFunction · 0.92
InfofFunction · 0.92
cleanPathFunction · 0.85
ObjectFromOriginalFunction · 0.85
refreshFromSourceMethod · 0.80
isTempFileMethod · 0.80
pauseMethod · 0.80
playMethod · 0.80

Tested by

no test coverage detected