I copied and modified package_handler_download_project(), so I may be responsible and I cannot give an easy way to reproduce the problem. That said, let's look at the code:

These lines (take out of context, but the control flow is preserved) remove the 0 key from the return value:

function drush_tarball_extract($path, $destination = FALSE, $listing = FALSE) {
  if (($mimetype == 'application/zip') || ($mimetype == 'application/x-zip')) {
    if ($listing) {
      $output = drush_shell_exec_output();
      array_shift($output);
      $return = array_filter($output, create_function('$str', 'return $str != "";'));
  return $return;

Then these lines from drush/commands/pm/package_handler/wget.inc try to fetch that key:

function package_handler_download_project(&$request, $release) {
  $file_list = drush_tarball_extract($path, $request['base_project_path'], TRUE);
    $project_dir = drush_trim_path($file_list[0]);

It looks to me as though array_shift($file_list) would do a better job than $file_list[0].

Comments

jonhattan’s picture

Status: Active » Postponed (maintainer needs more info)

I don't understand which is the bug report here.

package_handler/wget.inc works with tgz files, not zip files. Are you implementing a .zip variant?

benjifisher’s picture

Status: Postponed (maintainer needs more info) » Needs work

@jonhattan:

Maybe I am confused, but bear with me. I see that there are two versions of package_handler_download_project(), one in package_handler/git_drupalorg.inc and one in package_handler/wget.inc. The one in wget.inc, as far as I can tell, does not deal directly with wget nor with tgz files: it calls drush_download_file() to use cache, wget, curl, or file_get_contents; and it calls drush_tarball_extract() to deal with archives. The archive might be a tar file or a zip file.

Here are the first 33 lines of drush_tarball_extract(), with nothing skipped. I did not write this!

function drush_tarball_extract($path, $destination = FALSE, $listing = FALSE) {
  // Check if tarball is supported.
  if (!($mimetype = drush_file_is_tarball($path))) {
    return drush_set_error('TARBALL_EXTRACT_UNKNOWN_FORMAT', dt('Unable to extract !path. Unknown archive format.', array('!path' => $path)));
  }

  // Check if destination is valid.
  if (!$destination) {
    $destination = dirname($path);
  }
  if (!drush_mkdir($destination)) {
    // drush_mkdir already set an error.
    return FALSE;
  }

  // Perform the extraction of a zip file.
  if (($mimetype == 'application/zip') || ($mimetype == 'application/x-zip')) {
    $return = drush_shell_cd_and_exec(dirname($path), "unzip %s -d %s", $path, $destination);
    if (!$return) {
      return drush_set_error('DRUSH_TARBALL_EXTRACT_ERROR', dt('Unable to unzip !filename.', array('!filename' => $path)));
    }
    if ($listing) {
      // unzip prefixes the file listing output with a header line,
      // and prefixes each line with a verb representing the compression type.
      $output = drush_shell_exec_output();
      // Remove the header line.
      array_shift($output);
      // Remove the prefix verb from each line.
      $output = array_map(create_function('$str', 'return substr($str, strpos($str, ":") + 3 + ' . strlen(dirname($path)) . ');'), $output);
      // Remove any remaining blank lines.
      $return = array_filter($output, create_function('$str', 'return $str != "";'));
    }
  }

The lines I quoted in the issue summary are all there, and I am pretty sure that the ones I skipped do not change the control flow.

Background: I want to download some zip files from GitHub. Since GitHub uses https:// and some systems (like my own) have broken installations of wget, I want to call wget with the --no-check-certificate option. So I copied and pasted _drush_download_file() and edited it. That is why I cannot give an easy example to reproduce the bug. I called drush_tarball_extract(), not a custom version of this function.

greg.1.anderson’s picture

Version: 7.x-5.7 » 8.x-6.x-dev
Status: Needs work » Closed (won't fix)
Issue tags: +Needs migration

This issue was marked closed (won't fix) because Drush has moved to Github.

If desired, you may copy this bug to our Github project and then post a link here to the new issue. Please also change the status of this issue to closed (duplicate).

Please ask support questions on Drupal Answers.