XzDownloader.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Downloader;
  12. use Composer\Config;
  13. use Composer\Cache;
  14. use Composer\EventDispatcher\EventDispatcher;
  15. use Composer\Package\PackageInterface;
  16. use Composer\Util\ProcessExecutor;
  17. use Composer\Util\RemoteFilesystem;
  18. use Composer\IO\IOInterface;
  19. /**
  20. * Xz archive downloader.
  21. *
  22. * @author Pavel Puchkin <i@neoascetic.me>
  23. * @author Pierre Rudloff <contact@rudloff.pro>
  24. */
  25. class XzDownloader extends ArchiveDownloader
  26. {
  27. protected $process;
  28. public function __construct(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null, Cache $cache = null, ProcessExecutor $process = null, RemoteFilesystem $rfs = null)
  29. {
  30. $this->process = $process ?: new ProcessExecutor($io);
  31. parent::__construct($io, $config, $eventDispatcher, $cache, $rfs);
  32. }
  33. protected function extract($file, $path)
  34. {
  35. $command = 'tar -xJf ' . ProcessExecutor::escape($file) . ' -C ' . ProcessExecutor::escape($path);
  36. if (0 === $this->process->execute($command, $ignoredOutput)) {
  37. return;
  38. }
  39. $processError = 'Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput();
  40. throw new \RuntimeException($processError);
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. protected function getFileName(PackageInterface $package, $path)
  46. {
  47. return $path.'/'.pathinfo(parse_url($package->getDistUrl(), PHP_URL_PATH), PATHINFO_BASENAME);
  48. }
  49. }