function drush_copy_dir

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

Copy $src to $dest.

Parameters

$src: The directory to copy.

$dest: The destination to copy the source to, including the new name of the directory. To copy directory "a" from "/b" to "/c", then $src = "/b/a" and $dest = "/c/a". To copy "a" to "/c" and rename it to "d", then $dest = "/c/d".

$overwrite: Action to take if destination already exists.

Return value

TRUE on success, FALSE on failure.

Related topics

13 calls to drush_copy_dir()
DrushMakeProject::applyPatches in commands/make/make.project.inc
Retrieve and apply any patches specified by the makefile to this project.
DrushMakeProject::getTranslations in commands/make/make.project.inc
Retrieve translations for this project.
drush_move_dir in includes/filesystem.inc
Move $src to $dest.
drush_tarball_extract in includes/drush.inc
Extract a tarball.
drush_version_control_backup::pre_update in commands/pm/version_control/backup.inc
Implementation of pre_update().

... See full list

File

includes/filesystem.inc, line 215
Filesystem utilities.

Code

function drush_copy_dir($src, $dest, $overwrite = FILE_EXISTS_ABORT) {
  // Preflight based on $overwrite if $dest exists.
  if (file_exists($dest)) {
    if ($overwrite === FILE_EXISTS_OVERWRITE) {
      drush_op('drush_delete_dir', $dest, TRUE);
    }
    elseif ($overwrite === FILE_EXISTS_ABORT) {
      return drush_set_error('DRUSH_DESTINATION_EXISTS', dt('Destination directory !dest already exists.', array('!dest' => $dest)));
    }
    elseif ($overwrite === FILE_EXISTS_MERGE) {
      // $overwrite flag may indicate we should merge instead.
      drush_log(dt('Merging existing !dest directory', array('!dest' => $dest)));
    }
  }
  // $src readable?
  if (!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 (!is_writable(dirname($dest))) {
    return drush_set_error('DRUSH_DESTINATION_NOT_WRITABLE', dt('Destination directory !dest is not writable.', array('!dest' => dirname($dest))));
  }
  // Try to do a recursive copy.
  if (@drush_op('_drush_recursive_copy', $src, $dest)) {
    return TRUE;
  }

  return drush_set_error('DRUSH_COPY_DIR_FAILURE', dt('Unable to copy !src to !dest.', array('!src' => $src, '!dest' => $dest)));
}