function make_download_file_unpack

8.0.x make.download.inc make_download_file_unpack($filename, $download_location, $name, $subtree = NULL)
6.x make.download.inc make_download_file_unpack($filename, $download_location, $name, $subtree = NULL)
7.x make.download.inc make_download_file_unpack($filename, $download_location, $name, $subtree = NULL)
5.x make.download.inc make_download_file_unpack($filename, $download_location, $name, $subtree = NULL)
master make.download.inc make_download_file_unpack($filename, $download_location, $name, $subtree = NULL)

Unpacks a file to the specified download location.

Return value

mixed The download location on success, FALSE on failure.

1 call to make_download_file_unpack()
make_download_file in commands/make/make.download.inc
Downloads a file to the specified location.

File

commands/make/make.download.inc, line 112
Download-specific functions for Drush Make.

Code

function make_download_file_unpack($filename, $download_location, $name, $subtree = NULL) {
  $success = FALSE;

  if (drush_file_is_tarball($filename)) {
    $tmp_location = drush_tempdir();

    if (!drush_tarball_extract($filename, $tmp_location)) {
      return FALSE;
    }

    if ($subtree) {
      $tmp_location .= '/' . $subtree;
      if (!file_exists($tmp_location)) {
        return drush_set_error('DRUSH_MAKE_SUBTREE_NOT_FOUND', dt('Directory !subtree not found within !file', array('!subtree' => $subtree, '!file' => $filename)));
      }
    }
    else {
      $files = scandir($tmp_location);
      unset($files[0]); // . directory
      unset($files[1]); // .. directory
      if ((count($files) == 1) && is_dir($tmp_location . '/' . current($files))) {
        $tmp_location .= '/' . current($files);
      }
    }

    $success = drush_move_dir($tmp_location, $download_location, TRUE);

    // Remove the tarball.
    if (file_exists($filename)) {
      drush_delete_dir($filename, TRUE);
    }
  }
  else {
    // If this is an individual file, and no filename has been specified,
    // assume the original name.
    if (is_file($filename) && !$name) {
      $name = basename($filename);
    }

    // The destination directory has already been created by
    // findDownloadLocation().
    $destination = $download_location . ($name ? '/' . $name : '');
    $success = drush_move_dir($filename, $destination, TRUE);
  }
  return $success ? $download_location : FALSE;
}