MCPcopy
hub / github.com/rclone/rclone / Copy

Method Copy

backend/cache/cache.go:1535–1609  ·  view source on GitHub ↗

Copy src to this remote using server-side copy operations.

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

Source from the content-addressed store, hash-verified

1533
1534// Copy src to this remote using server-side copy operations.
1535func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object, error) {
1536 fs.Debugf(f, "copy obj '%s' -> '%s'", src, remote)
1537
1538 do := f.Fs.Features().Copy
1539 if do == nil {
1540 fs.Errorf(src, "source remote (%v) doesn't support Copy", src.Fs())
1541 return nil, fs.ErrorCantCopy
1542 }
1543 if f.opt.TempWritePath != "" && src.Fs() == f.tempFs {
1544 return nil, fs.ErrorCantCopy
1545 }
1546 // the source must be a cached object or we abort
1547 srcObj, ok := src.(*Object)
1548 if !ok {
1549 fs.Errorf(srcObj, "can't copy - not same remote type")
1550 return nil, fs.ErrorCantCopy
1551 }
1552 // both the source cache fs and this cache fs need to wrap the same remote
1553 if srcObj.CacheFs.Fs.Name() != f.Fs.Name() {
1554 fs.Errorf(srcObj, "can't copy - not wrapping same remotes")
1555 return nil, fs.ErrorCantCopy
1556 }
1557 // refresh from source or abort
1558 if err := srcObj.refreshFromSource(ctx, false); err != nil {
1559 fs.Errorf(f, "can't copy %v - %v", src, err)
1560 return nil, fs.ErrorCantCopy
1561 }
1562
1563 if srcObj.isTempFile() {
1564 // we check if the feature is still active
1565 if f.opt.TempWritePath == "" {
1566 fs.Errorf(srcObj, "can't copy - this is a local cached file but this feature is turned off this run")
1567 return nil, fs.ErrorCantCopy
1568 }
1569
1570 do = srcObj.ParentFs.Features().Copy
1571 if do == nil {
1572 fs.Errorf(src, "parent remote (%v) doesn't support Copy", srcObj.ParentFs)
1573 return nil, fs.ErrorCantCopy
1574 }
1575 }
1576
1577 obj, err := do(ctx, srcObj.Object, remote)
1578 if err != nil {
1579 fs.Errorf(srcObj, "error moving in cache: %v", err)
1580 return nil, err
1581 }
1582 fs.Debugf(obj, "copy: file copied")
1583
1584 // persist new
1585 co := ObjectFromOriginal(ctx, f, obj).persist()
1586 fs.Debugf(co, "copy: added to cache")
1587 // expire the destination path
1588 parentCd := NewDirectory(f, cleanPath(path.Dir(co.Remote())))
1589 err = f.cache.ExpireDir(parentCd)
1590 if err != nil {
1591 fs.Errorf(parentCd, "copy: cache expire error: %v", err)
1592 } else {

Callers

nothing calls this directly

Calls 15

RemoteMethod · 0.95
DebugfFunction · 0.92
ErrorfFunction · 0.92
InfofFunction · 0.92
ObjectFromOriginalFunction · 0.85
cleanPathFunction · 0.85
refreshFromSourceMethod · 0.80
isTempFileMethod · 0.80
persistMethod · 0.80
DirMethod · 0.80
ExpireDirMethod · 0.80

Tested by

no test coverage detected