function pm_drush_pm_download_destination_alter

8.0.x download.pm.inc pm_drush_pm_download_destination_alter(&$request, $release)
6.x download.pm.inc pm_drush_pm_download_destination_alter(&$project, $release)
7.x download.pm.inc pm_drush_pm_download_destination_alter(&$request, $release)
4.x pm.drush.inc pm_drush_pm_download_destination_alter(&$project, $release)
5.x download.pm.inc pm_drush_pm_download_destination_alter(&$project, $release)
master download.pm.inc pm_drush_pm_download_destination_alter(&$request, $release)

Implementation of hook_drush_pm_download_destination_alter().

Built-in download-destination-alter hook. This particular version of the hook will move modules that contain only drush commands to /usr/share/drush/commands if it exists, or $HOME/.drush if the site-wide location does not exist.

File

commands/pm/download.pm.inc, line 254
pm-download command implementation.

Code

function pm_drush_pm_download_destination_alter(&$project, $release) {
  // A module is a pure drush command if it has no .module and contain
  // .drush.inc files.  Skip this test for drush itself, though; we do
  // not want to download drush to the ~/.drush folder.
  if (($project['project_type'] == 'module') && ($project['name'] != 'drush')) {
    $drush_command_files = drush_scan_directory($project['full_project_path'], '/.*\.drush.inc/');
    if (!empty($drush_command_files)) {
      $module_files = drush_scan_directory($project['full_project_path'], '/.*\.module/');
      if (empty($module_files)) {
        $install_dir = drush_get_context('DRUSH_SITE_WIDE_COMMANDFILES');
        if (!is_dir($install_dir) || !is_writable($install_dir)) {
          $install_dir = drush_get_context('DRUSH_PER_USER_CONFIGURATION');
        }
        // Make the .drush dir if it does not already exist.
        if (!is_dir($install_dir)) {
          drush_mkdir($install_dir, FALSE);
        }
        // Change the location if the mkdir worked.
        if (is_dir($install_dir)) {
          $project['project_install_location'] = $install_dir;
        }
      }
      // We need to clear the drush commandfile cache so that
      // our newly-downloaded drush extension commandfiles can be found.
      drush_cache_clear_all();
    }
  }
}