function _pm_download_destination_lookup

8.0.x download.pm.inc _pm_download_destination_lookup($type, $drupal_root, $sitepath, $create = FALSE)
6.x download.pm.inc _pm_download_destination_lookup($type, $drupal_root, $sitepath, $create = FALSE)
7.x download.pm.inc _pm_download_destination_lookup($type, $drupal_root, $sitepath, $create = FALSE)
5.x download.pm.inc _pm_download_destination_lookup($type, $drupal_root, $sitepath, $create = FALSE)
master download.pm.inc _pm_download_destination_lookup($type, $drupal_root, $sitepath, $create = FALSE)

Determines a candidate destination directory for a particular site path.

Optionally attempts to create the directory.

Return value

String the candidate destination if it exists.

1 call to _pm_download_destination_lookup()
_pm_download_destination in commands/pm/download.pm.inc
Returns the best destination for a particular download type we can find.

File

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

Code

function _pm_download_destination_lookup($type, $drupal_root, $sitepath, $create = FALSE) {
  if ($type == 'theme engine') {
    $destination = 'themes/engines';
  }
  // Profiles in Drupal < 8
  elseif (($type == 'profile') && (drush_drupal_major_version() < 8)) {
    $destination = 'profiles';
  }
  // Type: module, theme or profile.
  else {
    $destination = $type . 's';
    // Prefer /contrib if it exists.
    if ($sitepath) {
      $destination = $sitepath . '/' . $destination;
    }
    $contrib = $destination . '/contrib';
    if (is_dir($contrib)) {
      $destination = $contrib;
    }
  }
  if ($create) {
    drush_log(dt('Attempting to create destination directory at !dir', array('!dir' => $destination)));
    drush_mkdir($destination, TRUE);
  }
  if (is_dir($destination)) {
    drush_log(dt('Using destination directory !dir', array('!dir' => $destination)));
    return $destination;
  }
  drush_log(dt('Could not find destination directory at !dir', array('!dir' => $destination)));
  return FALSE;
}