protected function extract($file, $path) { $processError = null; // Try to use unrar on *nix if (!Platform::isWindows()) { $command = 'unrar x ' . ProcessExecutor::escape($file) . ' ' . ProcessExecutor::escape($path) . ' >/dev/null && chmod -R u+w ' . ProcessExecutor::escape($path); if (0 === $this->process->execute($command, $ignoredOutput)) { return; } $processError = 'Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput(); } if (!class_exists('RarArchive')) { // php.ini path is added to the error message to help users find the correct file $iniMessage = IniHelper::getMessage(); $error = "Could not decompress the archive, enable the PHP rar extension or install unrar.\n" . $iniMessage . "\n" . $processError; if (!Platform::isWindows()) { $error = "Could not decompress the archive, enable the PHP rar extension.\n" . $iniMessage; } throw new \RuntimeException($error); } $rarArchive = RarArchive::open($file); if (false === $rarArchive) { throw new \UnexpectedValueException('Could not open RAR archive: ' . $file); } $entries = $rarArchive->getEntries(); if (false === $entries) { throw new \RuntimeException('Could not retrieve RAR archive entries'); } foreach ($entries as $entry) { if (false === $entry->extract($path)) { throw new \RuntimeException('Could not extract entry'); } } $rarArchive->close(); }
protected function get($originUrl, $fileUrl, $options = [], $fileName = null, $progress = true) { if (strpos($fileUrl, 'ssh://') !== 0) { throw new \UnexpectedValueException("This does not appear to be a file that should be downloaded via ssh: {$fileUrl}"); } // strip off the pseudo protocol $fileUrl = substr($fileUrl, 6); if ($this->io->isVerbose()) { $this->io->write("Downloading {$fileUrl} via ssh."); } // filename means we want to save if ($fileName) { $cmd = 'scp ' . ProcessExecutor::escape($fileUrl) . ' ' . ProcessExecutor::escape($fileName); } else { // otherwise just return the file contents list($host, $path) = explode(':', $fileUrl); $cmd = 'ssh ' . ProcessExecutor::escape($host) . ' ' . ProcessExecutor::escape('cat ' . ProcessExecutor::escape($path)); } if ($progress) { $this->io->writeError(' Downloading: <comment>Connecting...</comment>', false); } // success? // @todo: do we need to catch any exceptions here? if ($this->process->execute($cmd, $output) === 0) { if ($progress) { $this->io->overwriteError(' Downloading: <comment>100%</comment>'); } return $output; } else { // some sort of error - boo! throw new \RuntimeException("Could not download {$fileUrl}. " . $process->getErrorOutput()); } }
protected function extract($file, $path) { $processError = null; if (self::$hasSystemUnzip && !(class_exists('ZipArchive') && Platform::isWindows())) { $command = 'unzip ' . ProcessExecutor::escape($file) . ' -d ' . ProcessExecutor::escape($path); if (!Platform::isWindows()) { $command .= ' && chmod -R u+w ' . ProcessExecutor::escape($path); } try { if (0 === $this->process->execute($command, $ignoredOutput)) { return; } $processError = 'Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput(); } catch (\Exception $e) { $processError = 'Failed to execute ' . $command . "\n\n" . $e->getMessage(); } if (!class_exists('ZipArchive')) { throw new \RuntimeException($processError); } } $zipArchive = new ZipArchive(); if (true !== ($retval = $zipArchive->open($file))) { throw new \UnexpectedValueException(rtrim($this->getErrorMessage($retval, $file) . "\n" . $processError), $retval); } if (true !== $zipArchive->extractTo($path)) { throw new \RuntimeException(rtrim("There was an error extracting the ZIP file, it is either corrupted or using an invalid format.\n" . $processError)); } $zipArchive->close(); }
protected function extract($file, $path) { // we must use cmdline tar, as PharData::extract() messes up symlinks $command = 'tar -xzf ' . ProcessExecutor::escape($file) . ' -C ' . ProcessExecutor::escape($path); if (0 === $this->process->execute($command, $ignoredOutput)) { return; } throw new \RuntimeException("Failed to execute '{$command}'\n\n" . $this->process->getErrorOutput()); }
protected function extract($file, $path) { $command = 'tar -xJf ' . ProcessExecutor::escape($file) . ' -C ' . ProcessExecutor::escape($path); if (0 === $this->process->execute($command, $ignoredOutput)) { return; } $processError = 'Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput(); throw new \RuntimeException($processError); }
public function doUpdate(PackageInterface $initial, PackageInterface $target, $path, $url) { $url = ProcessExecutor::escape($url); $ref = ProcessExecutor::escape($target->getSourceReference()); $this->io->writeError(" Updating to " . $target->getSourceReference()); if (!is_dir($path . '/.hg')) { throw new \RuntimeException('The .hg directory is missing from ' . $path . ', see http://getcomposer.org/commit-deps for more information'); } $command = sprintf('hg pull %s && hg up %s', $url, $ref); if (0 !== $this->process->execute($command, $ignoredOutput, realpath($path))) { throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); } }
/** * {@inheritDoc} */ public function doUpdate(PackageInterface $initial, PackageInterface $target, $path, $url) { // Ensure we are allowed to use this URL by config $this->config->prohibitUrlByConfig($url, $this->io); $url = ProcessExecutor::escape($url); $ref = ProcessExecutor::escape($target->getSourceReference()); $this->io->writeError(" Updating to " . $target->getSourceReference()); if (!$this->hasMetadataRepository($path)) { throw new \RuntimeException('The .hg directory is missing from ' . $path . ', see https://getcomposer.org/commit-deps for more information'); } $command = sprintf('hg pull %s && hg up %s', $url, $ref); if (0 !== $this->process->execute($command, $ignoredOutput, realpath($path))) { throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); } }
protected function extract($file, $path) { $targetFilepath = $path . DIRECTORY_SEPARATOR . basename(substr($file, 0, -3)); if (!defined('PHP_WINDOWS_VERSION_BUILD')) { $command = 'gzip -cd ' . ProcessExecutor::escape($file) . ' > ' . ProcessExecutor::escape($targetFilepath); if (0 === $this->process->execute($command, $ignoredOutput)) { return; } $processError = 'Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput(); throw new \RuntimeException($processError); } $archiveFile = gzopen($file, 'rb'); $targetFile = fopen($targetFilepath, 'wb'); while ($string = gzread($archiveFile, 4096)) { fwrite($targetFile, $string, strlen($string)); } gzclose($archiveFile); fclose($targetFile); }
protected function generateWindowsProxyCode($bin, $link) { $binPath = $this->filesystem->findShortestPath($link, $bin); if ('.bat' === substr($bin, -4)) { $caller = 'call'; } else { $handle = fopen($bin, 'r'); $line = fgets($handle); fclose($handle); if (preg_match('{^#!/(?:usr/bin/env )?(?:[^/]+/)*(.+)$}m', $line, $match)) { $caller = trim($match[1]); } else { $caller = 'php'; } if ($caller === 'php') { return "@echo off\r\n" . "pushd .\r\n" . "cd %~dp0\r\n" . "set PHP_PROXY=%CD%\\composer-php.bat\r\n" . "cd " . ProcessExecutor::escape(dirname($binPath)) . "\r\n" . "set BIN_TARGET=%CD%\\" . basename($binPath) . "\r\n" . "popd\r\n" . "%PHP_PROXY% \"%BIN_TARGET%\" %*\r\n"; } } return "@echo off\r\n" . "pushd .\r\n" . "cd %~dp0\r\n" . "cd " . ProcessExecutor::escape(dirname($binPath)) . "\r\n" . "set BIN_TARGET=%CD%\\" . basename($binPath) . "\r\n" . "popd\r\n" . $caller . " \"%BIN_TARGET%\" %*\r\n"; }
protected function extract($file, $path) { $targetFilepath = $path . DIRECTORY_SEPARATOR . basename(substr($file, 0, -3)); // Try to use gunzip on *nix if (!Platform::isWindows()) { $command = 'gzip -cd ' . ProcessExecutor::escape($file) . ' > ' . ProcessExecutor::escape($targetFilepath); if (0 === $this->process->execute($command, $ignoredOutput)) { return; } if (extension_loaded('zlib')) { // Fallback to using the PHP extension. $this->extractUsingExt($file, $targetFilepath); return; } $processError = 'Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput(); throw new \RuntimeException($processError); } // Windows version of PHP has built-in support of gzip functions $this->extractUsingExt($file, $targetFilepath); }
protected function extract($file, $path) { $processError = null; // Try to use unrar on *nix if (!defined('PHP_WINDOWS_VERSION_BUILD')) { $command = 'unrar x ' . ProcessExecutor::escape($file) . ' ' . ProcessExecutor::escape($path) . ' && chmod -R u+w ' . ProcessExecutor::escape($path); if (0 === $this->process->execute($command, $ignoredOutput)) { return; } $processError = 'Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput(); } if (!class_exists('RarArchive')) { // php.ini path is added to the error message to help users find the correct file $iniPath = php_ini_loaded_file(); if ($iniPath) { $iniMessage = 'The php.ini used by your command-line PHP is: ' . $iniPath; } else { $iniMessage = 'A php.ini file does not exist. You will have to create one.'; } $error = "Could not decompress the archive, enable the PHP rar extension or install unrar.\n" . $iniMessage . "\n" . $processError; if (!defined('PHP_WINDOWS_VERSION_BUILD')) { $error = "Could not decompress the archive, enable the PHP rar extension.\n" . $iniMessage; } throw new \RuntimeException($error); } $rarArchive = RarArchive::open($file); if (false === $rarArchive) { throw new \UnexpectedValueException('Could not open RAR archive: ' . $file); } $entries = $rarArchive->getEntries(); if (false === $entries) { throw new \RuntimeException('Could not retrieve RAR archive entries'); } foreach ($entries as $entry) { if (false === $entry->extract($path)) { throw new \RuntimeException('Could not extract entry'); } } $rarArchive->close(); }
protected function extract($file, $path) { $processError = null; if (self::$hasSystemUnzip) { $command = 'unzip ' . ProcessExecutor::escape($file) . ' -d ' . ProcessExecutor::escape($path); if (!Platform::isWindows()) { $command .= ' && chmod -R u+w ' . ProcessExecutor::escape($path); } try { if (0 === $this->process->execute($command, $ignoredOutput)) { return; } $processError = 'Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput(); } catch (\Exception $e) { $processError = 'Failed to execute ' . $command . "\n\n" . $e->getMessage(); } } if (!class_exists('ZipArchive')) { // php.ini path is added to the error message to help users find the correct file $iniPath = php_ini_loaded_file(); if ($iniPath) { $iniMessage = 'The php.ini used by your command-line PHP is: ' . $iniPath; } else { $iniMessage = 'A php.ini file does not exist. You will have to create one.'; } $error = "Could not decompress the archive, enable the PHP zip extension or install unzip.\n" . $iniMessage . ($processError ? "\n" . $processError : ''); throw new \RuntimeException($error); } $zipArchive = new ZipArchive(); if (true !== ($retval = $zipArchive->open($file))) { throw new \UnexpectedValueException(rtrim($this->getErrorMessage($retval, $file) . "\n" . $processError), $retval); } if (true !== $zipArchive->extractTo($path)) { $this->io->writeError("<warn>As there is no 'unzip' command installed zip files are being unpacked using the PHP zip extension.</warn>"); $this->io->writeError("<warn>This may cause invalid reports of corrupted archives. Installing 'unzip' may remediate them.</warn>"); throw new \RuntimeException("There was an error extracting the ZIP file, it is either corrupted or using an invalid format"); } $zipArchive->close(); }
protected function extract($file, $path) { $processError = null; // try to use unzip on *nix if (!defined('PHP_WINDOWS_VERSION_BUILD')) { $command = 'unzip ' . ProcessExecutor::escape($file) . ' -d ' . ProcessExecutor::escape($path) . ' && chmod -R u+w ' . ProcessExecutor::escape($path); try { if (0 === $this->process->execute($command, $ignoredOutput)) { return; } $processError = 'Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput(); } catch (\Exception $e) { $processError = 'Failed to execute ' . $command . "\n\n" . $e->getMessage(); } } if (!class_exists('ZipArchive')) { // php.ini path is added to the error message to help users find the correct file $iniPath = php_ini_loaded_file(); if ($iniPath) { $iniMessage = 'The php.ini used by your command-line PHP is: ' . $iniPath; } else { $iniMessage = 'A php.ini file does not exist. You will have to create one.'; } $error = "Could not decompress the archive, enable the PHP zip extension or install unzip.\n" . $iniMessage . "\n" . $processError; if (!defined('PHP_WINDOWS_VERSION_BUILD')) { $error = "Could not decompress the archive, enable the PHP zip extension.\n" . $iniMessage; } throw new \RuntimeException($error); } $zipArchive = new ZipArchive(); if (true !== ($retval = $zipArchive->open($file))) { throw new \UnexpectedValueException($this->getErrorMessage($retval, $file), $retval); } if (true !== $zipArchive->extractTo($path)) { throw new \RuntimeException("There was an error extracting the ZIP file. Corrupt file?"); } $zipArchive->close(); }
protected function setPushUrl($path, $url) { // set push url for github projects if (preg_match('{^(?:https?|git)://' . GitUtil::getGitHubDomainsRegex($this->config) . '/([^/]+)/([^/]+?)(?:\\.git)?$}', $url, $match)) { $protocols = $this->config->get('github-protocols'); $pushUrl = 'git@' . $match[1] . ':' . $match[2] . '/' . $match[3] . '.git'; if (!in_array('ssh', $protocols, true)) { $pushUrl = 'https://' . $match[1] . '/' . $match[2] . '/' . $match[3] . '.git'; } $cmd = sprintf('git remote set-url --push origin %s', ProcessExecutor::escape($pushUrl)); $this->process->execute($cmd, $ignoredOutput, $path); } }
/** * {@inheritDoc} */ public static function supports(IOInterface $io, Config $config, $url, $deep = false) { if (preg_match('#(^(?:https?|ssh)://(?:[^@]@)?bitbucket.org|https://(?:.*?)\\.kilnhg.com)#i', $url)) { return true; } // local filesystem if (Filesystem::isLocalPath($url)) { $url = Filesystem::getPlatformPath($url); if (!is_dir($url)) { throw new \RuntimeException('Directory does not exist: ' . $url); } $process = new ProcessExecutor(); // check whether there is a hg repo in that path if ($process->execute('hg summary', $output, $url) === 0) { return true; } } if (!$deep) { return false; } $processExecutor = new ProcessExecutor(); $exit = $processExecutor->execute(sprintf('hg identify %s', ProcessExecutor::escape($url)), $ignored); return $exit === 0; }
protected function getCredentialString() { if (!$this->hasAuth()) { return ''; } return sprintf(' %s--username %s --password %s ', $this->getAuthCache(), ProcessExecutor::escape($this->getUsername()), ProcessExecutor::escape($this->getPassword())); }
/** * opens a url in your system default browser * * @param string $url */ private function openBrowser($url) { $url = ProcessExecutor::escape($url); if (Platform::isWindows()) { return passthru('start "web" explorer "' . $url . '"'); } passthru('which xdg-open', $linux); passthru('which open', $osx); if (0 === $linux) { passthru('xdg-open ' . $url); } elseif (0 === $osx) { passthru('open ' . $url); } else { $this->getIO()->writeError('no suitable browser opening command found, open yourself: ' . $url); } }
/** * opens a url in your system default browser * * @param string $url */ private function openBrowser($url) { $url = ProcessExecutor::escape($url); if (defined('PHP_WINDOWS_VERSION_MAJOR')) { return passthru('start "web" explorer "' . $url . '"'); } passthru('which xdg-open', $linux); passthru('which open', $osx); if (0 === $linux) { passthru('xdg-open ' . $url); } elseif (0 === $osx) { passthru('open ' . $url); } else { $this->getIO()->write('no suitable browser opening command found, open yourself: ' . $url); } }
/** * {@inheritDoc} */ public function getComposerInformation($identifier) { if (!isset($this->infoCache[$identifier])) { $command = sprintf('fossil cat -r %s composer.json', ProcessExecutor::escape($identifier)); $this->process->execute($command, $composer, $this->checkoutDir); if (trim($composer) === '') { return; } $composer = JsonFile::parseJson(trim($composer), $identifier); if (empty($composer['time'])) { $this->process->execute(sprintf('fossil finfo composer.json | head -n 2 | tail -n 1 | awk \'{print $1}\''), $output, $this->checkoutDir); $date = new \DateTime(trim($output), new \DateTimeZone('UTC')); $composer['time'] = $date->format('Y-m-d H:i:s'); } $this->infoCache[$identifier] = $composer; } return $this->infoCache[$identifier]; }
protected function generateUnixyProxyCode($bin, $link) { $binPath = $this->filesystem->findShortestPath($link, $bin); return "#!/usr/bin/env sh\n" . 'SRC_DIR="`pwd`"' . "\n" . 'cd "`dirname "$0"`"' . "\n" . 'cd ' . ProcessExecutor::escape(dirname($binPath)) . "\n" . 'BIN_TARGET="`pwd`/' . basename($binPath) . "\"\n" . 'cd "$SRC_DIR"' . "\n" . '"$BIN_TARGET" "$@"' . "\n"; }
/** * @dataProvider getAssetTypes * * @param string $type * @param string $filename */ public function testPublicRepositoryWithFilesystemCache($type, $filename) { $repoUrl = 'https://bitbucket.org/composer-test/repo-name'; $identifier = '92bebbfdcde75ef2368317830e54b605bc938123'; $repoConfig = array('url' => $repoUrl, 'asset-type' => $type, 'filename' => $filename); $io = $this->getMockBuilder('Composer\\IO\\IOInterface')->getMock(); $process = $this->getMockBuilder('Composer\\Util\\ProcessExecutor')->getMock(); $process->expects($this->any())->method('splitLines')->will($this->returnValue(array())); $process->expects($this->any())->method('execute')->will($this->returnCallback(function ($command, &$output = null) use($identifier, $repoConfig) { if ($command === sprintf('hg cat -r %s %s', ProcessExecutor::escape($identifier), $repoConfig['filename'])) { $output = '{"name": "foo"}'; } elseif (false !== strpos($command, 'hg log')) { $date = new \DateTime(null, new \DateTimeZone('UTC')); $output = $date->format(\DateTime::RFC3339); } return 0; })); /* @var IOInterface $io */ /* @var ProcessExecutor $process */ $driver1 = new HgDriver($repoConfig, $io, $this->config, $process, null); $driver2 = new HgDriver($repoConfig, $io, $this->config, $process, null); $driver1->initialize(); $driver2->initialize(); $composer1 = $driver1->getComposerInformation($identifier); $composer2 = $driver2->getComposerInformation($identifier); $this->assertNotNull($composer1); $this->assertNotNull($composer2); $this->assertSame($composer1, $composer2); }
/** * {@inheritDoc} */ public static function supports(IOInterface $io, Config $config, $url, $deep = false) { if (preg_match('#(^git://|\\.git/?$|git(?:olite)?@|//git\\.|//github.com/)#i', $url)) { return true; } // local filesystem if (Filesystem::isLocalPath($url)) { $url = Filesystem::getPlatformPath($url); if (!is_dir($url)) { return false; } $process = new ProcessExecutor($io); // check whether there is a git repo in that path if ($process->execute('git tag', $output, $url) === 0) { return true; } } if (!$deep) { return false; } $process = new ProcessExecutor($io); if ($process->execute('git ls-remote --heads ' . ProcessExecutor::escape($url), $output) === 0) { return true; } return false; }
/** * Removes a Windows NTFS junction. * * @param string $junction * @return bool */ public function removeJunction($junction) { if (!Platform::isWindows()) { return false; } $junction = rtrim(str_replace('/', DIRECTORY_SEPARATOR, $junction), DIRECTORY_SEPARATOR); if (!$this->isJunction($junction)) { throw new IOException(sprintf('%s is not a junction and thus cannot be removed as one', $junction)); } $cmd = sprintf('rmdir /S /Q %s', ProcessExecutor::escape($junction)); clearstatcache(true, $junction); return $this->getProcess()->execute($cmd, $output) === 0; }
/** * Returns the packages's datetime for its source reference. * * @param PackageInterface $package The package to scan. * @return string|null The formatted datetime or null if none was found. */ private function getPackageTime(PackageInterface $package) { if (!function_exists('proc_open')) { return null; } $path = realpath($this->installationManager->getInstallPath($package)); $sourceType = $package->getSourceType(); $datetime = null; if ($path && in_array($sourceType, array('git', 'hg'))) { $sourceRef = $package->getSourceReference() ?: $package->getDistReference(); switch ($sourceType) { case 'git': GitUtil::cleanEnv(); if (0 === $this->process->execute('git log -n1 --pretty=%ct ' . ProcessExecutor::escape($sourceRef), $output, $path) && preg_match('{^\\s*\\d+\\s*$}', $output)) { $datetime = new \DateTime('@' . trim($output), new \DateTimeZone('UTC')); } break; case 'hg': if (0 === $this->process->execute('hg log --template "{date|hgdate}" -r ' . ProcessExecutor::escape($sourceRef), $output, $path) && preg_match('{^\\s*(\\d+)\\s*}', $output, $match)) { $datetime = new \DateTime('@' . $match[1], new \DateTimeZone('UTC')); } break; } } return $datetime ? $datetime->format('Y-m-d H:i:s') : null; }
public function rename($source, $target) { if (true === @rename($source, $target)) { return; } if (!function_exists('proc_open')) { return $this->copyThenRemove($source, $target); } if (defined('PHP_WINDOWS_VERSION_BUILD')) { // Try to copy & delete - this is a workaround for random "Access denied" errors. $command = sprintf('xcopy %s %s /E /I /Q', ProcessExecutor::escape($source), ProcessExecutor::escape($target)); $result = $this->processExecutor->execute($command, $output); // clear stat cache because external processes aren't tracked by the php stat cache clearstatcache(); if (0 === $result) { $this->remove($source); return; } } else { // We do not use PHP's "rename" function here since it does not support // the case where $source, and $target are located on different partitions. $command = sprintf('mv %s %s', ProcessExecutor::escape($source), ProcessExecutor::escape($target)); $result = $this->processExecutor->execute($command, $output); // clear stat cache because external processes aren't tracked by the php stat cache clearstatcache(); if (0 === $result) { return; } } return $this->copyThenRemove($source, $target); }
protected function generateUnixyProxyCode($bin, $link) { $binPath = $this->filesystem->findShortestPath($link, $bin); $binDir = ProcessExecutor::escape(dirname($binPath)); $binFile = basename($binPath); $proxyCode = <<<PROXY #!/usr/bin/env sh dir=\$(d=\${0%[/\\\\]*}; cd "\$d"; cd {$binDir} && pwd) # See if we are running in Cygwin by checking for cygpath program if command -v 'cygpath' >/dev/null 2>&1; then \t# Cygwin paths start with /cygdrive/ which will break windows PHP, \t# so we need to translate the dir path to windows format. However \t# we could be using cygwin PHP which does not require this, so we \t# test if the path to PHP starts with /cygdrive/ rather than /usr/bin \tif [[ \$(which php) == /cygdrive/* ]]; then \t\tdir=\$(cygpath -m "\$dir"); \tfi fi dir=\$(echo \$dir | sed 's/ /\\ /g') "\${dir}/{$binFile}" "\$@" PROXY; return $proxyCode; }
/** * @dataProvider getAssetTypes */ public function testPublicRepositoryWithFilesystemCache($type, $filename, $identifier) { $repoBaseUrl = 'svn://example.tld/composer-test/repo-name'; $repoUrl = $repoBaseUrl . '/trunk'; $repoConfig = array('url' => $repoUrl, 'asset-type' => $type, 'filename' => $filename); $io = $this->getMock('Composer\\IO\\IOInterface'); $process = $this->getMock('Composer\\Util\\ProcessExecutor'); $process->expects($this->any())->method('splitLines')->will($this->returnCallback(function ($value) { return is_string($value) ? preg_split('{\\r?\\n}', $value) : array(); })); $process->expects($this->any())->method('execute')->will($this->returnCallback(function ($command, &$output) use($repoBaseUrl, $identifier, $repoConfig) { if ($command === sprintf('svn cat --non-interactive %s', ProcessExecutor::escape(sprintf('%s/%s/%s', $repoBaseUrl, $identifier, $repoConfig['filename']))) || $command === sprintf('svn cat --non-interactive %s', ProcessExecutor::escape(sprintf('%s/%s%s', $repoBaseUrl, $repoConfig['filename'], trim($identifier, '/'))))) { $output('out', '{"name": "foo"}'); } elseif ($command === sprintf('svn info --non-interactive %s', ProcessExecutor::escape(sprintf('%s/%s/', $repoBaseUrl, $identifier))) || $command === sprintf('svn info --non-interactive %s', ProcessExecutor::escape(sprintf('%s/%s', $repoBaseUrl, trim($identifier, '/'))))) { $date = new \DateTime(null, new \DateTimeZone('UTC')); $value = array('Last Changed Rev: ' . $identifier, 'Last Changed Date: ' . $date->format('Y-m-d H:i:s O') . ' (' . $date->format('l, j F Y') . ')'); $output('out', implode(PHP_EOL, $value)); } return 0; })); /* @var IOInterface $io */ /* @var ProcessExecutor $process */ $driver1 = new SvnDriver($repoConfig, $io, $this->config, $process, null); $driver2 = new SvnDriver($repoConfig, $io, $this->config, $process, null); $driver1->initialize(); $driver2->initialize(); $composer1 = $driver1->getComposerInformation($identifier); $composer2 = $driver2->getComposerInformation($identifier); $this->assertNotNull($composer1); $this->assertNotNull($composer2); $this->assertSame($composer1, $composer2); $this->assertArrayHasKey('time', $composer1); }
public function syncMirror($url, $dir) { // update the repo if it is a valid git repository if (is_dir($dir) && 0 === $this->process->execute('git rev-parse --git-dir', $output, $dir) && trim($output) === '.') { try { $commandCallable = function ($url) { return sprintf('git remote set-url origin %s && git remote update --prune origin', ProcessExecutor::escape($url)); }; $this->runCommand($commandCallable, $url, $dir); } catch (\Exception $e) { return false; } return true; } // clean up directory and do a fresh clone into it $this->filesystem->removeDirectory($dir); $commandCallable = function ($url) use($dir) { return sprintf('git clone --mirror %s %s', ProcessExecutor::escape($url), ProcessExecutor::escape($dir)); }; $this->runCommand($commandCallable, $url, $dir, true); return true; }
protected function getGitConfig() { if (null !== $this->gitConfig) { return $this->gitConfig; } $finder = new ExecutableFinder(); $gitBin = $finder->find('git'); $cmd = new Process(sprintf('%s config -l', ProcessExecutor::escape($gitBin))); $cmd->run(); if ($cmd->isSuccessful()) { $this->gitConfig = array(); preg_match_all('{^([^=]+)=(.*)$}m', $cmd->getOutput(), $matches, PREG_SET_ORDER); foreach ($matches as $match) { $this->gitConfig[$match[1]] = $match[2]; } return $this->gitConfig; } return $this->gitConfig = array(); }
/** * Clone repository * * @param PackageInterface $package * @param string $path * @param string $url * @return $this */ protected function cloneRepository(PackageInterface $package, $path, $url) { $command = $this->getCloneCommand(); $this->io->write(" Cloning " . $package->getSourceReference()); $commandCallable = $this->getCloneCommandCallback($path, $package->getSourceReference(), $command); $this->gitUtil->runCommand($commandCallable, $url, $path, true); if ($url !== $package->getSourceUrl()) { $url = $package->getSourceUrl(); $this->process->execute(sprintf('git remote set-url origin %s', ProcessExecutor::escape($url)), $output, $path); } $this->setPushUrl($path, $url); return $this; }