MCPcopy
hub / github.com/rclone/rclone / DirMove

Method DirMove

backend/cache/cache.go:1254–1372  ·  view source on GitHub ↗

DirMove moves src, srcRemote to this remote at dstRemote using server-side move operations.

(ctx context.Context, src fs.Fs, srcRemote, dstRemote string)

Source from the content-addressed store, hash-verified

1252// DirMove moves src, srcRemote to this remote at dstRemote
1253// using server-side move operations.
1254func (f *Fs) DirMove(ctx context.Context, src fs.Fs, srcRemote, dstRemote string) error {
1255 fs.Debugf(f, "move dir '%s'/'%s' -> '%s'/'%s'", src.Root(), srcRemote, f.Root(), dstRemote)
1256
1257 do := f.Fs.Features().DirMove
1258 if do == nil {
1259 return fs.ErrorCantDirMove
1260 }
1261 srcFs, ok := src.(*Fs)
1262 if !ok {
1263 fs.Errorf(srcFs, "can't move directory - not same remote type")
1264 return fs.ErrorCantDirMove
1265 }
1266 if srcFs.Fs.Name() != f.Fs.Name() {
1267 fs.Errorf(srcFs, "can't move directory - not wrapping same remotes")
1268 return fs.ErrorCantDirMove
1269 }
1270
1271 if f.opt.TempWritePath != "" {
1272 // pause background uploads
1273 f.backgroundRunner.pause()
1274 defer f.backgroundRunner.play()
1275
1276 _, errInWrap := srcFs.UnWrap().List(ctx, srcRemote)
1277 _, errInTemp := f.tempFs.List(ctx, srcRemote)
1278 // not found in either fs
1279 if errInWrap != nil && errInTemp != nil {
1280 return fs.ErrorDirNotFound
1281 }
1282
1283 // we check if the source exists on the remote and make the same move on it too if it does
1284 // otherwise, we skip this step
1285 if errInWrap == nil {
1286 err := do(ctx, srcFs.UnWrap(), srcRemote, dstRemote)
1287 if err != nil {
1288 return err
1289 }
1290 fs.Debugf(srcRemote, "movedir: dir moved in the source fs")
1291 }
1292 // we need to check if the directory exists in the temp fs
1293 // and skip the move if it doesn't
1294 if errInTemp != nil {
1295 goto cleanup
1296 }
1297
1298 var queuedEntries []*Object
1299 err := walk.ListR(ctx, f.tempFs, srcRemote, true, -1, walk.ListObjects, func(entries fs.DirEntries) error {
1300 for _, o := range entries {
1301 if oo, ok := o.(fs.Object); ok {
1302 co := ObjectFromOriginal(ctx, f, oo)
1303 queuedEntries = append(queuedEntries, co)
1304 if co.tempFileStartedUpload() {
1305 fs.Errorf(co, "can't move - upload has already started. need to finish that")
1306 return fs.ErrorCantDirMove
1307 }
1308 }
1309 }
1310 return nil
1311 })

Callers

nothing calls this directly

Calls 15

RootMethod · 0.95
absMethod · 0.95
RemoteMethod · 0.95
DebugfFunction · 0.92
ErrorfFunction · 0.92
ListRFunction · 0.92
ObjectFromOriginalFunction · 0.85
cleanPathFunction · 0.85
pauseMethod · 0.80
playMethod · 0.80
tempFileStartedUploadMethod · 0.80

Tested by

no test coverage detected