You are here

function _print_drush_download_extract in Printer, email and PDF versions 7.2

Helper to extract the downloaded zip/tar archive.

Parameters

string $filename: Filename of the file to extract.

Return value

bool TRUE on success, FALSE on failure

1 call to _print_drush_download_extract()
_print_drush_download_lib in includes/print.drush.inc
Download and extract the lib.

File

includes/print.drush.inc, line 144
Common drush functions for the print submodules.

Code

function _print_drush_download_extract($filename) {
  $arch_ret = FALSE;
  if (drush_op('is_file', $filename)) {
    $mime_type = drush_mime_content_type($filename);
    switch ($mime_type) {
      case 1:
        $arch_ret = TRUE;
        break;
      case 'application/zip':

        // Decompress the zip archive.
        $arch_ret = drush_shell_exec('unzip -qq -o %s', $filename);

        // ZIP archives usually get the access rights wrong.
        drush_log(dt('@filename is a Zip file. Check the access permissions of the extracted files.', array(
          '@filename' => $filename,
        )), 'warning');
        break;
      case 'application/x-gzip':

        // Decompress the tar gz archive.
        $arch_ret = drush_shell_exec('tar xzf %s', $filename);
        break;
      case 'application/x-bzip2':

        // Decompress the tar bz2 archive.
        $arch_ret = drush_shell_exec('tar xjf %s', $filename);
        break;
      case 'application/x-xz':

        // Decompress the tar xz archive.
        $arch_ret = drush_shell_exec('tar xJf %s', $filename);
        break;
      default:
        drush_log(dt('Unknown MIME type: @type', array(
          '@type' => $mime_type,
        )), 'error');
    }
  }
  else {
    drush_log(dt('@filename not found.', array(
      '@filename' => $filename,
    )), 'error');
  }
  return $arch_ret;
}