/** * Tests a simple composer install without core, but adding core later. */ public function testComposerInstallAndUpdate() { $exampleScaffoldFile = $this->tmpDir . DIRECTORY_SEPARATOR . 'index.php'; $this->assertFileNotExists($exampleScaffoldFile, 'Scaffold file should not be exist.'); $this->composer('install'); $this->assertFileExists($this->tmpDir . DIRECTORY_SEPARATOR . 'core', 'Drupal core is installed.'); $this->assertFileExists($exampleScaffoldFile, 'Scaffold file should be automatically installed.'); $this->fs->remove($exampleScaffoldFile); $this->assertFileNotExists($exampleScaffoldFile, 'Scaffold file should not be exist.'); $this->composer('drupal-scaffold'); $this->assertFileExists($exampleScaffoldFile, 'Scaffold file should be installed by "drupal-scaffold" command.'); foreach (['8.0.1', '8.1.x-dev'] as $version) { // We touch a scaffold file, so we can check the file was modified after // the scaffold update. touch($exampleScaffoldFile); $mtime_touched = filemtime($exampleScaffoldFile); // Requiring a newer version triggers "composer update" $this->composer('require --update-with-dependencies drupal/core:"' . $version . '"'); clearstatcache(); $mtime_after = filemtime($exampleScaffoldFile); $this->assertNotEquals($mtime_after, $mtime_touched, 'Scaffold file was modified by composer update. (' . $version . ')'); } // We touch a scaffold file, so we can check the file was modified after // the custom commandscaffold update. touch($exampleScaffoldFile); clearstatcache(); $mtime_touched = filemtime($exampleScaffoldFile); $this->composer('drupal-scaffold'); clearstatcache(); $mtime_after = filemtime($exampleScaffoldFile); $this->assertNotEquals($mtime_after, $mtime_touched, 'Scaffold file was modified by custom command.'); }
public function tearDown() { if (is_dir($this->workingDir)) { $this->fs->removeDirectory($this->workingDir); } if (is_file($this->testFile)) { $this->fs->remove($this->testFile); } }
protected function tearDown() { $this->package = null; $this->composer = null; $this->io = null; $fs = new Filesystem(); $fs->remove(sys_get_temp_dir() . '/composer-test-repo-cache'); $fs->remove(sys_get_temp_dir() . '/composer-test/vendor'); }
/** * Remove style.css and functions.php if the package type * is not a wordpress-theme */ public function complete() { $type = $this->getConfigKey('Placeholders', 'type')['value']; if ($type === 'wordpress-theme') { return; } $fs = new Util\Filesystem(); $base_dir = $this->getConfigKey('BaseDir'); $this->io->write("Removing theme files"); $fs->remove("{$base_dir}/style.css"); $fs->remove("{$base_dir}/functions.php"); }
/** * Remove (unlink) the destination file * * @param string $source * @param string $dest * * @throws \ErrorException */ public function remove($source, $dest) { $sourcePath = $this->getSourceDir() . '/' . ltrim($this->removeTrailingSlash($source), '\\/'); $destPath = $this->getDestDir() . '/' . ltrim($dest, '\\/'); // If source doesn't exist, check if it's a glob expression, otherwise we have nothing we can do if (!file_exists($sourcePath)) { // Handle globing $matches = glob($sourcePath); if (!empty($matches)) { foreach ($matches as $match) { $newDest = substr($destPath . '/' . basename($match), strlen($this->getDestDir())); $newDest = ltrim($newDest, ' \\/'); $this->remove(substr($match, strlen($this->getSourceDir()) + 1), $newDest); } } return; } // MP Avoid removing whole folders in case the modman file is not 100% well-written // e.g. app/etc/modules/Testmodule.xml app/etc/modules/ installs correctly, // but would otherwise delete the whole app/etc/modules folder! if (basename($sourcePath) !== basename($destPath)) { $destPath .= '/' . basename($source); } $this->filesystem->remove($destPath); $this->addRemovedFile($destPath); }
protected function tearDown() { parent::tearDown(); $fs = new Filesystem(); $fs->remove($this::TEST_PATH); }
/** * Clean a package, based on its rules. * * @param BasePackage $package The package to clean * @return bool True if cleaned */ protected function cleanPackage(BasePackage $package) { // Only clean 'dist' packages if ($package->getInstallationSource() !== 'dist') { return false; } $vendorDir = $this->config->get('vendor-dir'); $targetDir = $package->getTargetDir(); $packageName = $package->getPrettyName(); $packageDir = $targetDir ? $packageName . '/' . $targetDir : $packageName; $rules = isset($this->rules[$packageName]) ? $this->rules[$packageName] : null; if (!$rules) { return; } $dir = $this->filesystem->normalizePath(realpath($vendorDir . '/' . $packageDir)); if (!is_dir($dir)) { return false; } foreach ((array) $rules as $part) { // Split patterns for single globs (should be max 260 chars) $patterns = explode(' ', trim($part)); foreach ($patterns as $pattern) { try { foreach (glob($dir . '/' . $pattern) as $file) { $this->filesystem->remove($file); } } catch (\Exception $e) { $this->io->write("Could not parse {$packageDir} ({$pattern}): " . $e->getMessage()); } } } return true; }
/** * Clean a package, based on its rules. * * @param BasePackage $package The package to clean * @return bool True if cleaned * * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function cleanPackage(BasePackage $package) { $vendorDir = $this->config->get('vendor-dir'); $targetDir = $package->getTargetDir(); $packageName = $package->getPrettyName(); $packageDir = $targetDir ? $packageName . '/' . $targetDir : $packageName; $rules = isset($this->rules[$packageName]) ? $this->rules[$packageName] : null; if (!$rules) { $this->io->writeError('Rules not found: ' . $packageName); return false; } $dir = $this->filesystem->normalizePath(realpath($vendorDir . '/' . $packageDir)); if (!is_dir($dir)) { $this->io->writeError('Vendor dir not found: ' . $vendorDir . '/' . $packageDir); return false; } //$this->io->write('Rules: ' . print_r($rules, true)); foreach ((array) $rules as $part) { // Split patterns for single globs (should be max 260 chars) $patterns = (array) $part; foreach ($patterns as $pattern) { try { foreach (glob($dir . '/' . $pattern) as $file) { $this->filesystem->remove($file); //$this->io->write('File removed: ' . $file); } } catch (\Exception $e) { $this->io->write("Could not parse {$packageDir} ({$pattern}): " . $e->getMessage()); } } } return true; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $filesystem = new Filesystem(); $packageName = $this->getPackageFilename($name = $this->argument('name')); if (!($targetDir = $this->option('dir'))) { $targetDir = $this->container->path(); } $sourcePath = $this->container->get('path.packages') . '/' . $name; $filesystem->ensureDirectoryExists($targetDir); $target = realpath($targetDir) . '/' . $packageName . '.zip'; $filesystem->ensureDirectoryExists(dirname($target)); $exludes = []; if (file_exists($composerJsonPath = $sourcePath . '/composer.json')) { $jsonFile = new JsonFile($composerJsonPath); $jsonData = $jsonFile->read(); if (!empty($jsonData['archive']['exclude'])) { $exludes = $jsonData['archive']['exclude']; } if (!empty($jsonData['archive']['scripts'])) { system($jsonData['archive']['scripts'], $return); if ($return !== 0) { throw new \RuntimeException('Can not executes scripts.'); } } } $tempTarget = sys_get_temp_dir() . '/composer_archive' . uniqid() . '.zip'; $filesystem->ensureDirectoryExists(dirname($tempTarget)); $archiver = new PharArchiver(); $archivePath = $archiver->archive($sourcePath, $tempTarget, 'zip', $exludes); rename($archivePath, $target); $filesystem->remove($tempTarget); return $target; }
/** * Try to cleanup a file/dir, output on exception */ private function tryCleanup(string $path, string $errorMsg) { try { $this->filesystem->remove($path); } catch (\RuntimeException $ex) { $this->io->write($errorMsg); } }
protected function execute(InputInterface $input, OutputInterface $output) { $baseUrl = (extension_loaded('openssl') ? 'https' : 'http') . '://' . self::HOMEPAGE; $remoteFilesystem = new RemoteFilesystem($this->getIO()); $config = Factory::createConfig(); $cacheDir = $config->get('cache-dir'); $rollbackDir = $config->get('home'); $localFilename = realpath($_SERVER['argv'][0]) ?: $_SERVER['argv'][0]; $tmpDir = is_writable(dirname($localFilename)) ? dirname($localFilename) : $cacheDir; if (!is_writable($tmpDir)) { throw new FilesystemException('Composer update failed: the "' . $tmpDir . '" directory used to download the temp file could not be written'); } if (!is_writable($localFilename)) { throw new FilesystemException('Composer update failed: the "' . $localFilename . '" file could not be written'); } if ($input->getOption('rollback')) { return $this->rollback($output, $rollbackDir, $localFilename); } $latestVersion = trim($remoteFilesystem->getContents(self::HOMEPAGE, $baseUrl . '/version', false)); $updateVersion = $input->getArgument('version') ?: $latestVersion; if (preg_match('{^[0-9a-f]{40}$}', $updateVersion) && $updateVersion !== $latestVersion) { $output->writeln('<error>You can not update to a specific SHA-1 as those phars are not available for download</error>'); return 1; } if (Composer::VERSION === $updateVersion) { $output->writeln('<info>You are already using composer version ' . $updateVersion . '.</info>'); return 0; } $tempFilename = $tmpDir . '/' . basename($localFilename, '.phar') . '-temp.phar'; $backupFile = sprintf('%s/%s-%s%s', $rollbackDir, strtr(Composer::RELEASE_DATE, ' :', '_-'), preg_replace('{^([0-9a-f]{7})[0-9a-f]{33}$}', '$1', Composer::VERSION), self::OLD_INSTALL_EXT); $output->writeln(sprintf("Updating to version <info>%s</info>.", $updateVersion)); $remoteFilename = $baseUrl . (preg_match('{^[0-9a-f]{40}$}', $updateVersion) ? '/composer.phar' : "/download/{$updateVersion}/composer.phar"); $remoteFilesystem->copy(self::HOMEPAGE, $remoteFilename, $tempFilename); if (!file_exists($tempFilename)) { $output->writeln('<error>The download of the new composer version failed for an unexpected reason</error>'); return 1; } if ($input->getOption('clean-backups')) { $files = $this->getOldInstallationFiles($rollbackDir); if (!empty($files)) { $fs = new Filesystem(); foreach ($files as $file) { $output->writeln('<info>Removing: ' . $file . '</info>'); $fs->remove($file); } } } if ($err = $this->setLocalPhar($localFilename, $tempFilename, $backupFile)) { $output->writeln('<error>The file is corrupted (' . $err->getMessage() . ').</error>'); $output->writeln('<error>Please re-run the self-update command to try again.</error>'); return 1; } if (file_exists($backupFile)) { $output->writeln('Use <info>composer self-update --rollback</info> to return to version ' . Composer::VERSION); } else { $output->writeln('<warning>A backup of the current version could not be written to ' . $backupFile . ', no rollback possible</warning>'); } }
/** * Deletes all files and directories that matches patterns. */ public function cleanup() { if ($this->isEnabled() && $this->hasPattern() && realpath($this->installDir)) { $paths = iterator_to_array($this->finder->in($this->installDir)); /* @var \SplFileInfo $path */ foreach ($paths as $path) { $this->filesystem->remove($path); } } }
/** * Complete the setup task. * * @since 0.1.0 * * @return void */ public function complete() { $filesystem = new Filesystem(); foreach ($this->getRootFiles() as $file) { try { $filesystem->remove(SetupHelper::getFile($file)); } catch (Exception $exception) { $this->io->writeError(sprintf('Could not remove file "%1$s". Reason: %2$s', SetupHelper::getFile($file), $exception->getMessage())); } } }
/** * Override the default task due to static directory references */ public function complete() { $fs = new Util\Filesystem(); $base_dir = $this->getConfigKey('BaseDir'); foreach ($this->getRootFiles() as $file) { try { $fs->remove("{$base_dir}/{$file}"); } catch (Exception $exception) { $this->io->writeError(sprintf(_('Could not remove file "%1$s". Reason: %2$s'), $file, $exception->getMessage())); } } }
/** * Renames the plugin file to {{package}}.php, * removes it, if the package is not of type wordpress-plugin */ public function complete() { $fs = new Util\Filesystem(); $base_dir = $this->getConfigKey('BaseDir'); $type = $this->getConfigKey('Placeholders', 'type')['value']; $package = $this->getConfigKey('Placeholders', 'package_key')['value']; $plugin_file = "{$base_dir}/plugin.php"; if ('wordpress-plugin' === $type) { $fs->copyThenRemove($plugin_file, "{$base_dir}/{$package}.php"); return; } $this->io->write("Removing plugin file"); $fs->remove($plugin_file); }
/** * Renames the relevant license file to 'LICENSE' and removes * the one we don't use */ public function complete() { $fs = new Util\Filesystem(); $base_dir = $this->getConfigKey('BaseDir'); $license = $this->getConfigKey('Placeholders', 'license')['value']; $license_files = ['MIT' => 'LICENSE.mit', 'GPL-2.0' => 'LICENSE.gpl2']; if (!isset($license_files[$license])) { throw new Exception\LogicException("No file found for license '{$license}'"); } $license_file = "{$base_dir}/{$license_files[$license]}"; $fs->copyThenRemove($license_file, "{$base_dir}/LICENSE"); foreach ($license_files as $file) { $this->io->write(sprintf("Removing license file %s", basename($file))); $fs->remove($file); } }
public function process($message = '') { // Mirror each package's assets into the component directory. $fs = new Filesystem(); foreach ($this->packages as $package) { $packageDir = $this->getVendorDir($package); $name = isset($package['name']) ? $package['name'] : '__component__'; $extra = isset($package['extra']) ? $package['extra'] : array(); $componentName = $this->getComponentName($name, $extra); $fileType = array('scripts', 'styles', 'files'); foreach ($fileType as $type) { // Only act on the files if they're available. if (isset($extra['component'][$type]) && is_array($extra['component'][$type])) { foreach ($extra['component'][$type] as $file) { // Make sure the file itself is available. $source = $packageDir . DIRECTORY_SEPARATOR . $file; if (file_exists($source)) { // Find where the file destination should be. $destination = $this->componentDir . DIRECTORY_SEPARATOR . $componentName . DIRECTORY_SEPARATOR . $file; // Ensure the directory is available. $fs->ensureDirectoryExists(dirname($destination)); // Delete the file before creating its mirror. $fs->remove($destination); // Symlink the file using a relative path from the destination. $cwd = getcwd(); $fullDestination = $cwd . DIRECTORY_SEPARATOR . $destination; $relative = $fs->findShortestPath($fullDestination, realpath($source)); try { chdir(dirname($destination)); symlink($relative, $fullDestination); } catch (\ErrorException $e) { // If Symlinking failed, try copying. if (!copy($relative, $fullDestination)) { $this->io->write(sprintf('<error>Failed to produce %s as %s.</error>', $fullDestination, $relative)); return false; } } chdir($cwd); } } } } } return true; }
public function updateCode(PackageInterface $initial, PackageInterface $target) { $actualLegacyDir = $this->innomaticLegacyDir; $this->innomaticLegacyDir = $packageDir = $this->generateTempDirName(); if ($this->io->isVerbose()) { $this->io->write("Installing in temporary directory."); } $this->installCode($target); $fileSystem = new Filesystem(); if ($this->io->isVerbose()) { $this->io->write("Updating Innomatic application over existing installation."); } $this->deployApplication($packageDir); if ($this->io->isVerbose()) { $this->io->write("Innomatic application upgrade finished."); } $fileSystem->remove($this->innomaticLegacyDir); }
/** * {@inheritDoc} */ public function initialize() { if (Filesystem::isLocalPath($this->url)) { $this->checkoutDir = $this->url; } else { $this->repoFile = $this->config->get('cache-repo-dir') . '/' . preg_replace('{[^a-z0-9]}i', '-', $this->url) . '.fossil'; $this->checkoutDir = $this->config->get('cache-vcs-dir') . '/' . preg_replace('{[^a-z0-9]}i', '-', $this->url) . '/'; $fs = new Filesystem(); $fs->ensureDirectoryExists($this->checkoutDir); if (!is_writable(dirname($this->checkoutDir))) { throw new \RuntimeException('Can not clone ' . $this->url . ' to access package information. The "' . $this->checkoutDir . '" directory is not writable by the current user.'); } // Ensure we are allowed to use this URL by config $this->config->prohibitUrlByConfig($this->url, $this->io); // update the repo if it is a valid fossil repository if (is_file($this->repoFile) && is_dir($this->checkoutDir) && 0 === $this->process->execute('fossil info', $output, $this->checkoutDir)) { if (0 !== $this->process->execute('fossil pull', $output, $this->checkoutDir)) { $this->io->writeError('<error>Failed to update ' . $this->url . ', package information from this repository may be outdated (' . $this->process->getErrorOutput() . ')</error>'); } } else { // clean up directory and do a fresh clone into it $fs->removeDirectory($this->checkoutDir); $fs->remove($this->repoFile); $fs->ensureDirectoryExists($this->checkoutDir); if (0 !== $this->process->execute(sprintf('fossil clone %s %s', ProcessExecutor::escape($this->url), ProcessExecutor::escape($this->repoFile)), $output)) { $output = $this->process->getErrorOutput(); if (0 !== $this->process->execute('fossil version', $ignoredOutput)) { throw new \RuntimeException('Failed to clone ' . $this->url . ', fossil was not found, check that it is installed and in your PATH env.' . "\n\n" . $this->process->getErrorOutput()); } throw new \RuntimeException('Failed to clone ' . $this->url . ' to repository ' . $this->repoFile . "\n\n" . $output); } if (0 !== $this->process->execute(sprintf('fossil open %s', ProcessExecutor::escape($this->repoFile)), $output, $this->checkoutDir)) { $output = $this->process->getErrorOutput(); throw new \RuntimeException('Failed to open repository ' . $this->repoFile . ' in ' . $this->checkoutDir . "\n\n" . $output); } } } $this->getTags(); $this->getBranches(); }
/** * Uninstalls NodeJS. * Note: other classes cannot be loaded here since the package has already been removed. */ private function onUninstall($binDir, $targetDir) { $fileSystem = new Filesystem(); if (file_exists($targetDir)) { $this->verboseLog("Removing NodeJS local install"); // Let's remove target directory $fileSystem->remove($targetDir); $vendorNodeDir = dirname($targetDir); if ($fileSystem->isDirEmpty($vendorNodeDir)) { $fileSystem->remove($vendorNodeDir); } } // Now, let's remove the links $this->verboseLog("Removing NodeJS and NPM links from Composer bin directory"); foreach (array("node", "npm", "node.bat", "npm.bat") as $file) { $realFile = $binDir . DIRECTORY_SEPARATOR . $file; if (file_exists($realFile)) { $fileSystem->remove($realFile); } } }
public function tearDown() { if (file_exists('htdocs')) { $fs = new Filesystem(); $fs->remove('htdocs'); } }
protected function cleanBackups($rollbackDir, $except = null) { $finder = $this->getOldInstallationFinder($rollbackDir); $io = $this->getIO(); $fs = new Filesystem(); foreach ($finder as $file) { if ($except && $file->getBasename(self::OLD_INSTALL_EXT) === $except) { continue; } $file = (string) $file; $io->writeError('<info>Removing: ' . $file . '</info>'); $fs->remove($file); } }
/** * @param string $sourcePath * @param Filesystem $fileSystemUtil * @param string $installPath * @param ProcessExecutor $processExecutor */ private static function cleanupAndCopy($sourcePath, $installPath, Filesystem $fileSystemUtil, ProcessExecutor $processExecutor) { $cleanupPath = $installPath; $fileWildcard = '/*'; if (is_file($sourcePath)) { $fileWildcard = ''; $cleanupPath .= basename($sourcePath); } $fileSystemUtil->remove($cleanupPath); $fileSystemUtil->ensureDirectoryExists($installPath); if (defined('PHP_WINDOWS_VERSION_BUILD')) { $processExecutor->execute("xcopy {$sourcePath} {$installPath} /E /I /Q /Y"); } else { $processExecutor->execute("cp -r {$sourcePath}{$fileWildcard} {$installPath}"); } }
public function archive(PackageInterface $package, $format, $targetDir) { if (empty($format)) { throw new \InvalidArgumentException('Format must be specified'); } $usableArchiver = null; foreach ($this->archivers as $archiver) { if ($archiver->supports($format, $package->getSourceType())) { $usableArchiver = $archiver; break; } } if (null === $usableArchiver) { throw new \RuntimeException(sprintf('No archiver found to support %s format', $format)); } $filesystem = new Filesystem(); $packageName = $this->getPackageFilename($package); $filesystem->ensureDirectoryExists($targetDir); $target = realpath($targetDir) . '/' . $packageName . '.' . $format; $filesystem->ensureDirectoryExists(dirname($target)); if (!$this->overwriteFiles && file_exists($target)) { return $target; } if ($package instanceof RootPackageInterface) { $sourcePath = realpath('.'); } else { $sourcePath = sys_get_temp_dir() . '/composer_archive' . uniqid(); $filesystem->ensureDirectoryExists($sourcePath); $this->downloadManager->download($package, $sourcePath); if (file_exists($composerJsonPath = $sourcePath . '/composer.json')) { $jsonFile = new JsonFile($composerJsonPath); $jsonData = $jsonFile->read(); if (!empty($jsonData['archive']['exclude'])) { $package->setArchiveExcludes($jsonData['archive']['exclude']); } } } $tempTarget = sys_get_temp_dir() . '/composer_archive' . uniqid() . '.' . $format; $filesystem->ensureDirectoryExists(dirname($tempTarget)); $archivePath = $usableArchiver->archive($sourcePath, $tempTarget, $format, $package->getArchiveExcludes()); rename($archivePath, $target); if (!$package instanceof RootPackageInterface) { $filesystem->removeDirectory($sourcePath); } $filesystem->remove($tempTarget); return $target; }
protected function execute(InputInterface $input, OutputInterface $output) { $config = Factory::createConfig(); if ($config->get('disable-tls') === true) { $baseUrl = 'http://' . self::HOMEPAGE; } else { $baseUrl = 'https://' . self::HOMEPAGE; } $io = $this->getIO(); $remoteFilesystem = Factory::createRemoteFilesystem($io, $config); $cacheDir = $config->get('cache-dir'); $rollbackDir = $config->get('data-dir'); $home = $config->get('home'); $localFilename = realpath($_SERVER['argv'][0]) ?: $_SERVER['argv'][0]; if ($input->getOption('update-keys')) { return $this->fetchKeys($io, $config); } // check if current dir is writable and if not try the cache dir from settings $tmpDir = is_writable(dirname($localFilename)) ? dirname($localFilename) : $cacheDir; // check for permissions in local filesystem before start connection process if (!is_writable($tmpDir)) { throw new FilesystemException('Composer update failed: the "' . $tmpDir . '" directory used to download the temp file could not be written'); } if (!is_writable($localFilename)) { throw new FilesystemException('Composer update failed: the "' . $localFilename . '" file could not be written'); } if ($input->getOption('rollback')) { return $this->rollback($output, $rollbackDir, $localFilename); } $latestVersion = trim($remoteFilesystem->getContents(self::HOMEPAGE, $baseUrl . '/version', false)); $updateVersion = $input->getArgument('version') ?: $latestVersion; if (preg_match('{^[0-9a-f]{40}$}', $updateVersion) && $updateVersion !== $latestVersion) { $io->writeError('<error>You can not update to a specific SHA-1 as those phars are not available for download</error>'); return 1; } if (Composer::VERSION === $updateVersion) { $io->writeError('<info>You are already using composer version ' . $updateVersion . '.</info>'); return 0; } $tempFilename = $tmpDir . '/' . basename($localFilename, '.phar') . '-temp.phar'; $backupFile = sprintf('%s/%s-%s%s', $rollbackDir, strtr(Composer::RELEASE_DATE, ' :', '_-'), preg_replace('{^([0-9a-f]{7})[0-9a-f]{33}$}', '$1', Composer::VERSION), self::OLD_INSTALL_EXT); $updatingToTag = !preg_match('{^[0-9a-f]{40}$}', $updateVersion); $io->write(sprintf("Updating to version <info>%s</info>.", $updateVersion)); $remoteFilename = $baseUrl . ($updatingToTag ? "/download/{$updateVersion}/composer.phar" : '/composer.phar'); $signature = $remoteFilesystem->getContents(self::HOMEPAGE, $remoteFilename . '.sig', false); $remoteFilesystem->copy(self::HOMEPAGE, $remoteFilename, $tempFilename, !$input->getOption('no-progress')); if (!file_exists($tempFilename) || !$signature) { $io->writeError('<error>The download of the new composer version failed for an unexpected reason</error>'); return 1; } // verify phar signature if (!extension_loaded('openssl') && $config->get('disable-tls')) { $io->writeError('<warning>Skipping phar signature verification as you have disabled OpenSSL via config.disable-tls</warning>'); } else { if (!extension_loaded('openssl')) { throw new \RuntimeException('The openssl extension is required for phar signatures to be verified but it is not available. ' . 'If you can not enable the openssl extension, you can disable this error, at your own risk, by setting the \'disable-tls\' option to true.'); } $sigFile = 'file://' . $home . '/' . ($updatingToTag ? 'keys.tags.pub' : 'keys.dev.pub'); if (!file_exists($sigFile)) { file_put_contents($home . '/keys.dev.pub', <<<DEVPUBKEY -----BEGIN PUBLIC KEY----- MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAnBDHjZS6e0ZMoK3xTD7f FNCzlXjX/Aie2dit8QXA03pSrOTbaMnxON3hUL47Lz3g1SC6YJEMVHr0zYq4elWi i3ecFEgzLcj+pZM5X6qWu2Ozz4vWx3JYo1/a/HYdOuW9e3lwS8VtS0AVJA+U8X0A hZnBmGpltHhO8hPKHgkJtkTUxCheTcbqn4wGHl8Z2SediDcPTLwqezWKUfrYzu1f o/j3WFwFs6GtK4wdYtiXr+yspBZHO3y1udf8eFFGcb2V3EaLOrtfur6XQVizjOuk 8lw5zzse1Qp/klHqbDRsjSzJ6iL6F4aynBc6Euqt/8ccNAIz0rLjLhOraeyj4eNn 8iokwMKiXpcrQLTKH+RH1JCuOVxQ436bJwbSsp1VwiqftPQieN+tzqy+EiHJJmGf TBAbWcncicCk9q2md+AmhNbvHO4PWbbz9TzC7HJb460jyWeuMEvw3gNIpEo2jYa9 pMV6cVqnSa+wOc0D7pC9a6bne0bvLcm3S+w6I5iDB3lZsb3A9UtRiSP7aGSo7D72 8tC8+cIgZcI7k9vjvOqH+d7sdOU2yPCnRY6wFh62/g8bDnUpr56nZN1G89GwM4d4 r/TU7BQQIzsZgAiqOGXvVklIgAMiV0iucgf3rNBLjjeNEwNSTTG9F0CtQ+7JLwaE wSEuAuRm+pRqi8BRnQ/GKUcCAwEAAQ== -----END PUBLIC KEY----- DEVPUBKEY ); file_put_contents($home . '/keys.tags.pub', <<<TAGSPUBKEY -----BEGIN PUBLIC KEY----- MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA0Vi/2K6apCVj76nCnCl2 MQUPdK+A9eqkYBacXo2wQBYmyVlXm2/n/ZsX6pCLYPQTHyr5jXbkQzBw8SKqPdlh vA7NpbMeNCz7wP/AobvUXM8xQuXKbMDTY2uZ4O7sM+PfGbptKPBGLe8Z8d2sUnTO bXtX6Lrj13wkRto7st/w/Yp33RHe9SlqkiiS4MsH1jBkcIkEHsRaveZzedUaxY0M mba0uPhGUInpPzEHwrYqBBEtWvP97t2vtfx8I5qv28kh0Y6t+jnjL1Urid2iuQZf noCMFIOu4vksK5HxJxxrN0GOmGmwVQjOOtxkwikNiotZGPR4KsVj8NnBrLX7oGuM nQvGciiu+KoC2r3HDBrpDeBVdOWxDzT5R4iI0KoLzFh2pKqwbY+obNPS2bj+2dgJ rV3V5Jjry42QOCBN3c88wU1PKftOLj2ECpewY6vnE478IipiEu7EAdK8Zwj2LmTr RKQUSa9k7ggBkYZWAeO/2Ag0ey3g2bg7eqk+sHEq5ynIXd5lhv6tC5PBdHlWipDK tl2IxiEnejnOmAzGVivE1YGduYBjN+mjxDVy8KGBrjnz1JPgAvgdwJ2dYw4Rsc/e TzCFWGk/HM6a4f0IzBWbJ5ot0PIi4amk07IotBXDWwqDiQTwyuGCym5EqWQ2BD95 RGv89BPD+2DLnJysngsvVaUCAwEAAQ== -----END PUBLIC KEY----- TAGSPUBKEY ); } $pubkeyid = openssl_pkey_get_public($sigFile); $algo = defined('OPENSSL_ALGO_SHA384') ? OPENSSL_ALGO_SHA384 : 'SHA384'; if (!in_array('SHA384', openssl_get_md_methods())) { throw new \RuntimeException('SHA384 is not supported by your openssl extension, could not verify the phar file integrity'); } $signature = json_decode($signature, true); $signature = base64_decode($signature['sha384']); $verified = 1 === openssl_verify(file_get_contents($tempFilename), $signature, $pubkeyid, $algo); openssl_free_key($pubkeyid); if (!$verified) { throw new \RuntimeException('The phar signature did not match the file you downloaded, this means your public keys are outdated or that the phar file is corrupt/has been modified'); } } // remove saved installations of composer if ($input->getOption('clean-backups')) { $finder = $this->getOldInstallationFinder($rollbackDir); $fs = new Filesystem(); foreach ($finder as $file) { $file = (string) $file; $io->writeError('<info>Removing: ' . $file . '</info>'); $fs->remove($file); } } if ($err = $this->setLocalPhar($localFilename, $tempFilename, $backupFile)) { $io->writeError('<error>The file is corrupted (' . $err->getMessage() . ').</error>'); $io->writeError('<error>Please re-run the self-update command to try again.</error>'); return 1; } if (file_exists($backupFile)) { $io->writeError('Use <info>composer self-update --rollback</info> to return to version ' . Composer::VERSION); } else { $io->writeError('<warning>A backup of the current version could not be written to ' . $backupFile . ', no rollback possible</warning>'); } }
protected function tearDown() { $fs = new Filesystem(); $fs->remove($this->target); }
/** * Create an archive of the specified package. * * @param PackageInterface $package The package to archive * @param string $format The format of the archive (zip, tar, ...) * @param string $targetDir The directory where to build the archive * @param string|null $fileName The relative file name to use for the archive, or null to generate * the package name. Note that the format will be appended to this name * @throws \InvalidArgumentException * @throws \RuntimeException * @return string The path of the created archive */ public function archive(PackageInterface $package, $format, $targetDir, $fileName = null) { if (empty($format)) { throw new \InvalidArgumentException('Format must be specified'); } // Search for the most appropriate archiver $usableArchiver = null; foreach ($this->archivers as $archiver) { if ($archiver->supports($format, $package->getSourceType())) { $usableArchiver = $archiver; break; } } // Checks the format/source type are supported before downloading the package if (null === $usableArchiver) { throw new \RuntimeException(sprintf('No archiver found to support %s format', $format)); } $filesystem = new Filesystem(); if (null === $fileName) { $packageName = $this->getPackageFilename($package); } else { $packageName = $fileName; } // Archive filename $filesystem->ensureDirectoryExists($targetDir); $target = realpath($targetDir) . '/' . $packageName . '.' . $format; $filesystem->ensureDirectoryExists(dirname($target)); if (!$this->overwriteFiles && file_exists($target)) { return $target; } if ($package instanceof RootPackageInterface) { $sourcePath = realpath('.'); } else { // Directory used to download the sources $sourcePath = sys_get_temp_dir() . '/composer_archive' . uniqid(); $filesystem->ensureDirectoryExists($sourcePath); // Download sources $this->downloadManager->download($package, $sourcePath); // Check exclude from downloaded composer.json if (file_exists($composerJsonPath = $sourcePath . '/composer.json')) { $jsonFile = new JsonFile($composerJsonPath); $jsonData = $jsonFile->read(); if (!empty($jsonData['archive']['exclude'])) { $package->setArchiveExcludes($jsonData['archive']['exclude']); } } } // Create the archive $tempTarget = sys_get_temp_dir() . '/composer_archive' . uniqid() . '.' . $format; $filesystem->ensureDirectoryExists(dirname($tempTarget)); $archivePath = $usableArchiver->archive($sourcePath, $tempTarget, $format, $package->getArchiveExcludes()); rename($archivePath, $target); // cleanup temporary download if (!$package instanceof RootPackageInterface) { $filesystem->removeDirectory($sourcePath); } $filesystem->remove($tempTarget); return $target; }
protected function prepareCwd() { $this->cwd = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'typo3-copydriver-test'; $this->filesystem->remove($this->cwd); $this->filesystem->ensureDirectoryExists($this->cwd); }
/** * Clean the backup directory. * * @param string $rollbackDir The backup directory. * * @return void */ protected function cleanupOldBackups($rollbackDir) { $finder = $this->getOldInstallationFinder($rollbackDir); $fileSystem = new Filesystem(); foreach ($finder as $file) { $file = (string) $file; $this->getIO()->writeError('<info>Removing: ' . $file . '</info>'); $fileSystem->remove($file); } }