You are here

function hacked_download_release in Hacked! 5

Same name and namespace in other branches
  1. 6 hacked.module \hacked_download_release()
3 calls to hacked_download_release()
drush_hacked_diff in ./hacked.drush.inc
Drush command callback that shows the list of changes/unchanged files in a project.
hacked_hash_project in ./hacked.module
hacked_reports_hacked_diff in ./hacked.diff.inc

File

./hacked.module, line 348
The Hacked! module, shows which project have been changed since download.

Code

function hacked_download_release($release_url, $type, $short_name, $version) {

  // Compute the path where we'll store this release:
  $dir = hacked_release_form_path_name($type, $short_name, $version);

  // If our directory already exists, we can just return the path to this cached version
  if (file_exists($dir)) {
    return $dir;
  }

  // We've not downloaded this release before:
  // Let's try to download it:
  $request = drupal_http_request($release_url);

  // If we downloaded it, try to unpack it:
  if ($request->code == 200) {

    // Build the destination folder tree if it doesn't already exists.
    if (!file_check_directory($dir, FILE_CREATE_DIRECTORY) && !mkdir($dir, 0775, TRUE)) {
      watchdog('hacked', 'Failed to create temp directory: %dir', array(
        '%dir' => $dir,
      ), WATCHDOG_ERROR);
      return FALSE;
    }

    // Save the tarball someplace:
    $project_path = file_create_path($dir . '/' . basename($release_url));
    file_save_data($request->data, $project_path);
    shell_exec("cd {$dir}; tar -zxf " . basename($project_path));
    file_delete($project_path);

    // If we unpacked it, return the path:
    return $dir;
  }

  // Something went wrong:
  return FALSE;
}