/** * {@inheritDoc} */ public function download(PackageInterface $package, $path) { parent::download($package, $path); $fileName = $this->getFileName($package, $path); $this->io->write(' Unpacking archive'); $this->extract($fileName, $path); $this->io->write(' Cleaning up'); unlink($fileName); // If we have only a one dir inside it suppose to be a package itself $contentDir = glob($path . '/*'); if (1 === count($contentDir)) { $contentDir = $contentDir[0]; // Rename the content directory to avoid error when moving up // a child folder with the same name $temporaryName = md5(time() . rand()); rename($contentDir, $temporaryName); $contentDir = $temporaryName; foreach (array_merge(glob($contentDir . '/.*'), glob($contentDir . '/*')) as $file) { if (trim(basename($file), '.')) { rename($file, $path . '/' . basename($file)); } } rmdir($contentDir); } $this->io->write(''); }
protected function processUrl(PackageInterface $package, $url) { if ($package->getDistReference() && strpos($url, 'github.com')) { if (preg_match('{^https?://(?:www\\.)?github\\.com/([^/]+)/([^/]+)/(zip|tar)ball/(.+)$}i', $url, $match)) { $url = 'https://api.github.com/repos/' . $match[1] . '/' . $match[2] . '/' . $match[3] . 'ball/' . $package->getDistReference(); } elseif ($package->getDistReference() && preg_match('{^https?://(?:www\\.)?github\\.com/([^/]+)/([^/]+)/archive/.+\\.(zip|tar)(?:\\.gz)?$}i', $url, $match)) { $url = 'https://api.github.com/repos/' . $match[1] . '/' . $match[2] . '/' . $match[3] . 'ball/' . $package->getDistReference(); } elseif ($package->getDistReference() && preg_match('{^https?://api\\.github\\.com/repos/([^/]+)/([^/]+)/(zip|tar)ball(?:/.+)?$}i', $url, $match)) { $url = 'https://api.github.com/repos/' . $match[1] . '/' . $match[2] . '/' . $match[3] . 'ball/' . $package->getDistReference(); } } if (!extension_loaded('openssl') && (0 === strpos($url, 'https:') || 0 === strpos($url, 'http://github.com'))) { throw new \RuntimeException('You must enable the openssl extension to download files via https'); } return parent::processUrl($package, $url); }
/** * {@inheritDoc} */ public function download(PackageInterface $package, $path) { parent::download($package, $path); $fileName = $this->getFileName($package, $path); if ($this->io->isVerbose()) { $this->io->write(' Installing PEAR package'); } try { $pearExtractor = new PearPackageExtractor($fileName); $pearExtractor->extractTo($path); if ($this->io->isVerbose()) { $this->io->write(' Cleaning up'); } unlink($fileName); } catch (\Exception $e) { // clean up $this->filesystem->removeDirectory($path); throw $e; } $this->io->write(''); }
/** * {@inheritdoc} */ protected function processUrl(PackageInterface $package, $url) { if ($package->getDistReference() && strpos($url, 'github.com')) { if (preg_match('{^https?://(?:www\\.)?github\\.com/([^/]+)/([^/]+)/(zip|tar)ball/(.+)$}i', $url, $match)) { // update legacy github archives to API calls with the proper reference $url = 'https://api.github.com/repos/' . $match[1] . '/' . $match[2] . '/' . $match[3] . 'ball/' . $package->getDistReference(); } elseif ($package->getDistReference() && preg_match('{^https?://(?:www\\.)?github\\.com/([^/]+)/([^/]+)/archive/.+\\.(zip|tar)(?:\\.gz)?$}i', $url, $match)) { // update current github web archives to API calls with the proper reference $url = 'https://api.github.com/repos/' . $match[1] . '/' . $match[2] . '/' . $match[3] . 'ball/' . $package->getDistReference(); } elseif ($package->getDistReference() && preg_match('{^https?://api\\.github\\.com/repos/([^/]+)/([^/]+)/(zip|tar)ball(?:/.+)?$}i', $url, $match)) { // update api archives to the proper reference $url = 'https://api.github.com/repos/' . $match[1] . '/' . $match[2] . '/' . $match[3] . 'ball/' . $package->getDistReference(); } } if (!extension_loaded('openssl') && (0 === strpos($url, 'https:') || 0 === strpos($url, 'http://github.com'))) { // bypass https for github if openssl is disabled if (preg_match('{^https://api\\.github\\.com/repos/([^/]+/[^/]+)/(zip|tar)ball/([^/]+)$}i', $url, $match)) { $url = 'http://nodeload.github.com/' . $match[1] . '/' . $match[2] . '/' . $match[3]; } elseif (preg_match('{^https://github\\.com/([^/]+/[^/]+)/(zip|tar)ball/([^/]+)$}i', $url, $match)) { $url = 'http://nodeload.github.com/' . $match[1] . '/' . $match[2] . '/' . $match[3]; } elseif (preg_match('{^https://github\\.com/([^/]+/[^/]+)/archive/([^/]+)\\.(zip|tar\\.gz)$}i', $url, $match)) { $url = 'http://nodeload.github.com/' . $match[1] . '/' . $match[3] . '/' . $match[2]; } else { throw new \RuntimeException('You must enable the openssl extension to download files via https'); } } return parent::processUrl($package, $url); }
/** * {@inheritdoc} */ protected function processUrl(PackageInterface $package, $url) { if ($package->getDistReference() && strpos($url, 'github.com')) { if (preg_match('{^https?://(?:www\\.)?github\\.com/([^/]+)/([^/]+)/(zip|tar)ball/(.+)$}i', $url, $match)) { // update legacy github archives to API calls with the proper reference $url = 'https://api.github.com/repos/' . $match[1] . '/' . $match[2] . '/' . $match[3] . 'ball/' . $package->getDistReference(); } elseif ($package->getDistReference() && preg_match('{^https?://(?:www\\.)?github\\.com/([^/]+)/([^/]+)/archive/.+\\.(zip|tar)(?:\\.gz)?$}i', $url, $match)) { // update current github web archives to API calls with the proper reference $url = 'https://api.github.com/repos/' . $match[1] . '/' . $match[2] . '/' . $match[3] . 'ball/' . $package->getDistReference(); } elseif ($package->getDistReference() && preg_match('{^https?://api\\.github\\.com/repos/([^/]+)/([^/]+)/(zip|tar)ball(?:/.+)?$}i', $url, $match)) { // update api archives to the proper reference $url = 'https://api.github.com/repos/' . $match[1] . '/' . $match[2] . '/' . $match[3] . 'ball/' . $package->getDistReference(); } } elseif ($package->getDistReference() && strpos($url, 'bitbucket.org')) { if (preg_match('{^https?://(?:www\\.)?bitbucket\\.org/([^/]+)/([^/]+)/get/(.+)\\.(zip|tar\\.gz|tar\\.bz2)$}i', $url, $match)) { // update Bitbucket archives to the proper reference $url = 'https://bitbucket.org/' . $match[1] . '/' . $match[2] . '/get/' . $package->getDistReference() . '.' . $match[4]; } } return parent::processUrl($package, $url); }
public function __construct(IOInterface $io, ProcessExecutor $process = null) { $this->process = $process ?: new ProcessExecutor(); parent::__construct($io); }
/** * {@inheritDoc} */ public function remove(PackageInterface $package, $path) { /** * For junctions don't blindly rely on Filesystem::removeDirectory as it may be overzealous. If a process * inadvertently locks the file the removal will fail, but it would fall back to recursive delete which * is disastrous within a junction. So in that case we have no other real choice but to fail hard. */ if (Platform::isWindows() && $this->filesystem->isJunction($path)) { $this->io->writeError(" - Removing junction for <info>" . $package->getName() . "</info> (<comment>" . $package->getFullPrettyVersion() . "</comment>)"); if (!$this->filesystem->removeJunction($path)) { $this->io->writeError("<warn>Could not remove junction at " . $path . " - is another process locking it?</warn>"); throw new \RuntimeException('Could not reliably remove junction for package ' . $package->getName()); } } else { parent::remove($package, $path); } }
public function testDownloadFileWithInvalidChecksum() { $packageMock = $this->getMock('Composer\\Package\\PackageInterface'); $packageMock->expects($this->any())->method('getDistUrl')->will($this->returnValue('http://example.com/script.js')); $packageMock->expects($this->any())->method('getDistSha1Checksum')->will($this->returnValue('invalid')); do { $path = sys_get_temp_dir() . '/' . md5(time() . rand()); } while (file_exists($path)); $downloader = new FileDownloader($this->getMock('Composer\\IO\\IOInterface')); try { $downloader->download($packageMock, $path); $this->fail(); } catch (\Exception $e) { if (is_dir($path)) { $fs = new Filesystem(); $fs->removeDirectory($path); } else { if (is_file($path)) { unset($path); } } $this->assertInstanceOf('UnexpectedValueException', $e); $this->assertContains('checksum verification', $e->getMessage()); } }