function drush_move_dir
| 6.x filesystem.inc | drush_move_dir($src, $dest, $overwrite = FALSE) |
| 5.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) |
Move $src to $dest.
If the php 'rename' function doesn't work, then we'll do copy & delete.
Parameters
$src: The directory to move.
$dest: The destination to move the source to, including the new name of the directory. To move directory "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.
Return value
TRUE on success, FALSE on failure.
Related topics
12 calls to drush_move_dir()
- drush_archive_dump in commands/
core/ archive.drush.inc - Command callback. Generate site archive file.
- drush_archive_restore in commands/
core/ archive.drush.inc - Command callback. Restore web site(s) from a site archive file.
- drush_version_control_backup::pre_update in commands/
pm/ version_control/ backup.inc - Implementation of pre_update().
- drush_version_control_backup::rollback in commands/
pm/ version_control/ backup.inc - Implementation of rollback().
- make_download_file_unpack in commands/
make/ make.download.inc - Unpacks a file to the specified download location.
File
- includes/
filesystem.inc, line 270
Code
function drush_move_dir($src, $dest, $overwrite = FALSE) {
// Preflight based on $overwrite if $dest exists.
if (file_exists($dest)) {
if ($overwrite) {
drush_op('drush_delete_dir', $dest, TRUE);
}
else {
return drush_set_error('DRUSH_DESTINATION_EXISTS', dt('Destination directory !dest already exists.', array('!dest' => $dest)));
}
}
// $src readable?
if (!drush_op('is_readable', $src)) {
return drush_set_error('DRUSH_SOURCE_NOT_EXISTS', dt('Source directory !src is not readable or does not exist.', array('!src' => $src)));
}
// $dest writable?
if (!drush_op('is_writable', dirname($dest))) {
return drush_set_error('DRUSH_DESTINATION_NOT_WRITABLE', dt('Destination directory !dest is not writable.', array('!dest' => dirname($dest))));
}
// Try rename. It will fail if $src and $dest are not in the same partition.
if (@drush_op('rename', $src, $dest)) {
return TRUE;
}
// Eventually it will create an empty file in $dest. See
// http://www.php.net/manual/es/function.rename.php#90025
elseif (is_file($dest)) {
drush_op('unlink', $dest);
}
// If 'rename' fails, then we will use copy followed
// by a delete of the source.
if (drush_copy_dir($src, $dest)) {
drush_op('drush_delete_dir', $src, TRUE);
return TRUE;
}
return drush_set_error('DRUSH_MOVE_DIR_FAILURE', dt('Unable to move !src to !dest.', array('!src' => $src, '!dest' => $dest)));
}