MoveDir moves fsrc into fdst
(ctx context.Context, fdst, fsrc fs.Fs, deleteEmptySrcDirs bool, copyEmptySrcDirs bool)
| 1388 | |
| 1389 | // MoveDir moves fsrc into fdst |
| 1390 | func MoveDir(ctx context.Context, fdst, fsrc fs.Fs, deleteEmptySrcDirs bool, copyEmptySrcDirs bool) error { |
| 1391 | fi := filter.GetConfig(ctx) |
| 1392 | if operations.Same(fdst, fsrc) { |
| 1393 | fs.Errorf(fdst, "Nothing to do as source and destination are the same") |
| 1394 | return nil |
| 1395 | } |
| 1396 | |
| 1397 | // First attempt to use DirMover if exists, same Fs and no filters are active |
| 1398 | if fdstDirMove := fdst.Features().DirMove; fdstDirMove != nil && operations.SameConfig(fsrc, fdst) && fi.InActive() { |
| 1399 | if operations.SkipDestructive(ctx, fdst, "server-side directory move") { |
| 1400 | return nil |
| 1401 | } |
| 1402 | fs.Debugf(fdst, "Using server-side directory move") |
| 1403 | err := fdstDirMove(ctx, fsrc, "", "") |
| 1404 | switch err { |
| 1405 | case fs.ErrorCantDirMove, fs.ErrorDirExists: |
| 1406 | fs.Infof(fdst, "Server side directory move failed - fallback to file moves: %v", err) |
| 1407 | case nil: |
| 1408 | fs.Infof(fdst, "Server side directory move succeeded") |
| 1409 | return nil |
| 1410 | default: |
| 1411 | err = fs.CountError(ctx, err) |
| 1412 | fs.Errorf(fdst, "Server side directory move failed: %v", err) |
| 1413 | return err |
| 1414 | } |
| 1415 | } |
| 1416 | |
| 1417 | // Otherwise move the files one by one |
| 1418 | return moveDir(ctx, fdst, fsrc, deleteEmptySrcDirs, copyEmptySrcDirs) |
| 1419 | } |
searching dependent graphs…