public function testCannotExtractWithoutRootDirectoryNoDirectoryZipFiles() { $this->setExpectedException('Distill\\Exception\\IO\\Output\\NotSingleDirectoryException'); $target = $this->getTemporaryPath(); $this->clearTemporaryPath(); $this->distill->extractWithoutRootDirectory($this->filesPath . 'file_ok.zip', $target, new Format\Zip()); }
public function testCanExtractWithoutRootDirectoryInCurrentDirectory() { $target = $this->getTemporaryPath(); $this->clearTemporaryPath(); mkdir($target); chdir($target); $response = $this->distill->extractWithoutRootDirectory($this->filesPath . 'file_ok_dir.zip', '.', new Format\Simple\Zip()); $this->assertTrue($response); $this->assertUncompressed($target, 'file_ok_dir.zip', false, '/uncompressed'); $this->clearTemporaryPath(); }
public function testCannotExtractWithoutRootDirectoryNoDirectoryZipFiles() { $this->setExpectedException('Distill\\Exception\\IO\\Output\\NotSingleDirectoryException'); $target = $this->getTemporaryPath(); $this->clearTemporaryPath(); try { $this->distill->extractWithoutRootDirectory($this->filesPath . 'file_ok.zip', $target, new Format\Simple\Zip()); } catch (Exception\IO\Output\NotSingleDirectoryException $e) { $this->assertEquals($this->filesPath . 'file_ok.zip', $e->getFilename()); throw $e; } }
/** * Extracts the compressed file (ZIP or TGZ) using the * native operating system commands if available or PHP code otherwise. * * @return DownloadCommand * * @throws \RuntimeException if the downloaded archive could not be extracted */ protected function extract() { $this->output->writeln(sprintf(" Extracting <info>%s</info>\n", $this->projectName)); try { $distill = new Distill(); $extractionSucceeded = $distill->extractWithoutRootDirectory($this->downloadedFilePath, $this->projectDir); } catch (FileCorruptedException $e) { throw new \RuntimeException(sprintf("%s can't be installed because the downloaded package is corrupted.\n" . "To solve this issue, try executing this command again:\n%s", $this->getDownloadedFileName(), $this->getExecutedCommand())); } catch (FileEmptyException $e) { throw new \RuntimeException(sprintf("%s can't be installed because the downloaded package is empty.\n" . "To solve this issue, try executing this command again:\n%s", $this->getDownloadedFileName(), $this->getExecutedCommand())); } catch (TargetDirectoryNotWritableException $e) { throw new \RuntimeException(sprintf("%s can't be installed because the installer doesn't have enough\n" . "permissions to uncompress and rename the package contents.\n" . "To solve this issue, check the permissions of the %s directory and\n" . "try executing this command again:\n%s", $this->getDownloadedFileName(), getcwd(), $this->getExecutedCommand())); } catch (\Exception $e) { throw new \RuntimeException(sprintf("%s can't be installed because the downloaded package is corrupted\n" . "or because the installer doesn't have enough permissions to uncompress and\n" . "rename the package contents.\n" . "To solve this issue, check the permissions of the %s directory and\n" . "try executing this command again:\n%s", $this->getDownloadedFileName(), getcwd(), $this->getExecutedCommand())); } if (!$extractionSucceeded) { throw new \RuntimeException(sprintf("%s can't be installed because the downloaded package is corrupted\n" . "or because the uncompress commands of your operating system didn't work.", $this->getDownloadedFileName())); } return $this; }
/** * Extracts the compressed Symfony file (ZIP or TGZ) using the * native operating system commands if available or PHP code otherwise. * * @throws \RuntimeException if the downloaded archive could not be extracted */ private function extract() { $this->output->writeln(" Preparing new core version...\n"); $this->uncompressedFilePath = dirname($this->compressedFilePath); try { $distill = new Distill(); $extractionSucceeded = $distill->extractWithoutRootDirectory($this->compressedFilePath, $this->uncompressedFilePath); } catch (FileCorruptedException $e) { throw new \RuntimeException(sprintf("ProcessWire can't be installed because the downloaded package is corrupted.\n" . "To solve this issue, try installing ProcessWire again.\n%s", $this->getExecutedCommand())); } catch (FileEmptyException $e) { throw new \RuntimeException(sprintf("ProcessWire can't be installed because the downloaded package is empty.\n" . "To solve this issue, try installing ProcessWire again.\n%s", $this->getExecutedCommand())); } catch (TargetDirectoryNotWritableException $e) { throw new \RuntimeException(sprintf("ProcessWire can't be installed because the installer doesn't have enough\n" . "permissions to uncompress and rename the package contents.\n" . "To solve this issue, check the permissions of the %s directory and\n" . "try installing ProcessWire again.\n%s", getcwd(), $this->getExecutedCommand())); } catch (\Exception $e) { throw new \RuntimeException(sprintf("ProcessWire can't be installed because the downloaded package is corrupted\n" . "or because the installer doesn't have enough permissions to uncompress and\n" . "rename the package contents.\n" . "To solve this issue, check the permissions of the %s directory and\n" . "try installing ProcessWire again.\n%s", getcwd(), $this->getExecutedCommand())); } if (!$extractionSucceeded) { throw new \RuntimeException("ProcessWire can't be installed because the downloaded package is corrupted\n" . "or because the uncompress commands of your operating system didn't work."); } return $this; }
<?php require __DIR__ . '/../vendor/autoload.php'; use Distill\Distill; $distill = new Distill(); $distill->extractWithoutRootDirectory(__DIR__ . '/../tests/files/file_ok_dir.tar.gz', __DIR__ . '/extract');
/** * Extracts the downloaded archive. */ protected function extract() { try { $distill = new Distill(); $extractionSucceeded = $distill->extractWithoutRootDirectory($this->majoraDownloader->getDestinationFile(), $this->destinationPath); } catch (FileCorruptedException $e) { $this->clean(true); throw new \RuntimeException(sprintf("Majora Standard Edition can't be installed because the downloaded package is corrupted")); } catch (FileEmptyException $e) { $this->clean(true); throw new \RuntimeException(sprintf("Majora Standard Edition can't be installed because the downloaded package is empty")); } catch (TargetDirectoryNotWritableException $e) { $this->clean(true); throw new \RuntimeException(sprintf("Majora Standard Edition can't be installed because the installer doesn't have enough\n" . 'permissions to uncompress and rename the package contents.')); } catch (\Exception $e) { $this->clean(true); throw new \RuntimeException(sprintf("Majora Standard Edition can't be installed because the downloaded package is corrupted\n" . "or because the installer doesn't have enough permissions to uncompress and\n" . "rename the package contents.\n" . 'To solve this issue, check the permissions of the %s directory', getcwd()), null, $e); } if (!$extractionSucceeded) { $this->clean(true); throw new \RuntimeException(sprintf("Majora Standard Edition can't be installed because the downloaded package is corrupted\n" . "or because the uncompress commands of your operating system didn't work.")); } }
private function extractProfile($profile) { if (!$profile) { return $this; } $this->output->writeln(" Extracting profile...\n"); try { $distill = new Distill(); $extractPath = getcwd() . DIRECTORY_SEPARATOR . '.' . uniqid(time()) . DIRECTORY_SEPARATOR . 'pwprofile'; $extractionSucceeded = $distill->extractWithoutRootDirectory($profile, $extractPath); if ($extractionSucceeded) { try { $this->fs->mirror($extractPath, $this->projectDir . '/'); } catch (\Exception $e) { } // cleanup $this->fs->remove($extractPath); try { $process = new Process("cd {$this->projectDir}; composer install"); $process->run(function ($type, $buffer) { if (Process::ERR === $type) { echo ' ' . $buffer; } else { echo ' ' . $buffer; } }); } catch (\Exception $e) { } } } catch (FileCorruptedException $e) { throw new \RuntimeException("The profile can't be installed because the downloaded package is corrupted.\n"); } catch (FileEmptyException $e) { throw new \RuntimeException("The profile can't be installed because the downloaded package is empty.\n"); } catch (TargetDirectoryNotWritableException $e) { throw new \RuntimeException("The profile can't be installed because the installer doesn't have enough\n" . "permissions to uncompress and rename the package contents.\n"); } catch (\Exception $e) { throw new \RuntimeException("The profile can't be installed because the downloaded package is corrupted\n" . "or because the installer doesn't have enough permissions to uncompress and\n" . "rename the package contents.\n" . $e->getMessage()); } if (!$extractionSucceeded) { throw new \RuntimeException("The profile can't be installed because the downloaded package is corrupted\n" . "or because the uncompress commands of your operating system didn't work."); } return $this; }
/** * Extracts the compressed Symfony file (ZIP or TGZ) using the * native operating system commands if available or PHP code otherwise. * * param string $module * @return NewCommand * * @throws \RuntimeException if the downloaded archive could not be extracted */ private function extract($module) { $this->output->writeln(" Preparing module...\n"); try { $distill = new Distill(); $extractionSucceeded = $distill->extractWithoutRootDirectory($this->compressedFilePath, wire('config')->paths->siteModules . $module); $dir = wire('config')->paths->siteModules . $module; if (is_dir($dir)) { chmod($dir, 0755); } } catch (FileCorruptedException $e) { throw new \RuntimeException("This module can't be downloaded because the downloaded package is corrupted.\n" . "To solve this issue, try installing the module again.\n"); } catch (FileEmptyException $e) { throw new \RuntimeException("This module can't be downloaded because the downloaded package is empty.\n" . "To solve this issue, try installing the module again.\n"); } catch (TargetDirectoryNotWritableException $e) { throw new \RuntimeException(sprintf("This module can't be downloaded because the installer doesn't have enough\n" . "permissions to uncompress and rename the package contents.\n" . "To solve this issue, check the permissions of the %s directory and\n" . "try installing this module again.\n", getcwd())); } catch (\Exception $e) { throw new \RuntimeException(sprintf("This module can't be downloaded because the downloaded package is corrupted\n" . "or because the installer doesn't have enough permissions to uncompress and\n" . "rename the package contents.\n" . "To solve this issue, check the permissions of the %s directory and\n" . "try installing this module again.\n", getcwd())); } if (!$extractionSucceeded) { throw new \RuntimeException("This module can't be downloaded because the downloaded package is corrupted\n" . "or because the uncompress commands of your operating system didn't work."); } return $this; }
/** * Extract the zip file into the given directory. * * @param string $zipFile * @param string $directory * @return $this */ protected function extract($zipFile, $directory) { $this->stdout("\nExtract project...\n", Console::FG_GREEN); $distill = new Distill(); $distill->extractWithoutRootDirectory($zipFile, $directory); return $this; }