Move src to this remote using server-side move operations.
(ctx context.Context, src fs.Object, remote string)
| 1610 | |
| 1611 | // Move src to this remote using server-side move operations. |
| 1612 | func (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) |
nothing calls this directly
no test coverage detected