function drush_move_dir

8.0.x filesystem.inc drush_move_dir($src, $dest, $overwrite = FALSE)
6.x filesystem.inc drush_move_dir($src, $dest, $overwrite = FALSE)
7.x filesystem.inc drush_move_dir($src, $dest, $overwrite = FALSE)
3.x drush.inc drush_move_dir($src, $dest, $overwrite = FALSE)
4.x drush.inc drush_move_dir($src, $dest, $overwrite = FALSE)
5.x filesystem.inc drush_move_dir($src, $dest, $overwrite = FALSE)
master filesystem.inc drush_move_dir($src, $dest, $overwrite = FALSE)

Move $src to $dest. If the php 'rename' function doesn't work, then we'll try rsync.

Parameters

$src: The directory to move.

$dest: The destination to move the source to, including the new name of the folder. To move folder "a" from "/b" to "/c", then $src = "/b/a" and $dest = "/c/a". To move "a" to "/c" and rename it to "d", then $dest = "/c/d" (just like php rename function).

$overwrite: If TRUE, the destination will be deleted if it exists. Defaults to FALSE.

Return value

TRUE on success, FALSE on failure

1 call to drush_move_dir()
drush_pm_relocate_project in commands/pm/pm.drush.inc
drush_pm_relocate_project moves projects that should be relocated to a different installation directory to the location they belong in. For example, modules that are only collections of drush commands will be installed to $HOME/.drush.

File

includes/drush.inc, line 540
The drush API implementation and helpers.

Code

function drush_move_dir($src, $dest, $overwrite = FALSE) {
  // Preflight based on $overwrite if $dest exists.
  if (is_dir($dest)) {
    if ($overwrite) {
      drush_op('drush_delete_dir', $dest);
    }
    else {
      return drush_set_error('DRUSH_DESTINATION_EXISTS', dt('Destination directory !dest already exists.', array('!dest' => $dest)));
    }
  }

  // If rename works, then we're done.
  if (@drush_op('rename', $src, $dest)) {
    return TRUE;
  }
  // Bail if we can't make a directory at the
  // destination (e.g. permissions)
  if (!is_dir($dest) && (drush_op('mkdir', $dest) === FALSE)) {
    return FALSE;
  }
  // If rename doesn't work, then try rsync.
  $exec = 'rsync -raz --remove-source-files ' . $src . DIRECTORY_SEPARATOR . ' ' . $dest;
  $rsync_result = drush_op('system', $exec);
  if ($rsync_result !== FALSE) {
    // --remove-source-files deletes all of the files, but
    // we still need to get rid of the directories.
    drush_op('drush_delete_dir', $src);
    return TRUE;
  }
  return FALSE;
}