1
0
Fork 0

Do not realpath relative local URLs, fixes #2916

pull/2932/merge
Jordi Boggiano 2014-05-31 21:36:09 +02:00
parent 959cc4d63c
commit effacc1185
6 changed files with 31 additions and 24 deletions

View File

@ -60,6 +60,9 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
$urls = $package->getSourceUrls(); $urls = $package->getSourceUrls();
while ($url = array_shift($urls)) { while ($url = array_shift($urls)) {
try { try {
if (Filesystem::isLocalPath($url)) {
$url = realpath($url);
}
$this->doDownload($package, $path, $url); $this->doDownload($package, $path, $url);
break; break;
} catch (\Exception $e) { } catch (\Exception $e) {
@ -107,6 +110,9 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
$urls = $target->getSourceUrls(); $urls = $target->getSourceUrls();
while ($url = array_shift($urls)) { while ($url = array_shift($urls)) {
try { try {
if (Filesystem::isLocalPath($url)) {
$url = realpath($url);
}
$this->doUpdate($initial, $target, $path, $url); $this->doUpdate($initial, $target, $path, $url);
break; break;
} catch (\Exception $e) { } catch (\Exception $e) {

View File

@ -37,8 +37,9 @@ class GitDriver extends VcsDriver
*/ */
public function initialize() public function initialize()
{ {
if (static::isLocalUrl($this->url)) { if (Filesystem::isLocalPath($this->url)) {
$this->repoDir = str_replace('file://', '', $this->url); $this->repoDir = $this->url;
$cacheUrl = realpath($this->url);
} else { } else {
$this->repoDir = $this->config->get('cache-vcs-dir') . '/' . preg_replace('{[^a-z0-9.]}i', '-', $this->url) . '/'; $this->repoDir = $this->config->get('cache-vcs-dir') . '/' . preg_replace('{[^a-z0-9.]}i', '-', $this->url) . '/';
@ -72,12 +73,14 @@ class GitDriver extends VcsDriver
$gitUtil->runCommand($commandCallable, $this->url, $this->repoDir, true); $gitUtil->runCommand($commandCallable, $this->url, $this->repoDir, true);
} }
$cacheUrl = $this->url;
} }
$this->getTags(); $this->getTags();
$this->getBranches(); $this->getBranches();
$this->cache = new Cache($this->io, $this->config->get('cache-repo-dir').'/'.preg_replace('{[^a-z0-9.]}i', '-', $this->url)); $this->cache = new Cache($this->io, $this->config->get('cache-repo-dir').'/'.preg_replace('{[^a-z0-9.]}i', '-', $cacheUrl));
} }
/** /**
@ -215,7 +218,7 @@ class GitDriver extends VcsDriver
} }
// local filesystem // local filesystem
if (static::isLocalUrl($url)) { if (Filesystem::isLocalPath($url)) {
if (!is_dir($url)) { if (!is_dir($url)) {
throw new \RuntimeException('Directory does not exist: '.$url); throw new \RuntimeException('Directory does not exist: '.$url);
} }

View File

@ -34,8 +34,8 @@ class HgDriver extends VcsDriver
*/ */
public function initialize() public function initialize()
{ {
if (static::isLocalUrl($this->url)) { if (Filesystem::isLocalPath($this->url)) {
$this->repoDir = str_replace('file://', '', $this->url); $this->repoDir = $this->url;
} else { } else {
$cacheDir = $this->config->get('cache-vcs-dir'); $cacheDir = $this->config->get('cache-vcs-dir');
$this->repoDir = $cacheDir . '/' . preg_replace('{[^a-z0-9]}i', '-', $this->url) . '/'; $this->repoDir = $cacheDir . '/' . preg_replace('{[^a-z0-9]}i', '-', $this->url) . '/';
@ -197,7 +197,7 @@ class HgDriver extends VcsDriver
} }
// local filesystem // local filesystem
if (static::isLocalUrl($url)) { if (Filesystem::isLocalPath($url)) {
if (!is_dir($url)) { if (!is_dir($url)) {
throw new \RuntimeException('Directory does not exist: '.$url); throw new \RuntimeException('Directory does not exist: '.$url);
} }

View File

@ -252,7 +252,7 @@ class SvnDriver extends VcsDriver
} }
// proceed with deep check for local urls since they are fast to process // proceed with deep check for local urls since they are fast to process
if (!$deep && !static::isLocalUrl($url)) { if (!$deep && !Filesystem::isLocalPath($url)) {
return false; return false;
} }

View File

@ -17,6 +17,7 @@ use Composer\Config;
use Composer\IO\IOInterface; use Composer\IO\IOInterface;
use Composer\Util\ProcessExecutor; use Composer\Util\ProcessExecutor;
use Composer\Util\RemoteFilesystem; use Composer\Util\RemoteFilesystem;
use Composer\Util\Filesystem;
/** /**
* A driver implementation for driver with authentication interaction. * A driver implementation for driver with authentication interaction.
@ -44,11 +45,8 @@ abstract class VcsDriver implements VcsDriverInterface
*/ */
final public function __construct(array $repoConfig, IOInterface $io, Config $config, ProcessExecutor $process = null, RemoteFilesystem $remoteFilesystem = null) final public function __construct(array $repoConfig, IOInterface $io, Config $config, ProcessExecutor $process = null, RemoteFilesystem $remoteFilesystem = null)
{ {
if (Filesystem::isLocalPath($repoConfig['url'])) {
if (self::isLocalUrl($repoConfig['url'])) { $repoConfig['url'] = preg_replace('{^file://}', '', $repoConfig['url']);
$repoConfig['url'] = realpath(
preg_replace('/^file:\/\//', '', $repoConfig['url'])
);
} }
$this->url = $repoConfig['url']; $this->url = $repoConfig['url'];
@ -101,17 +99,6 @@ abstract class VcsDriver implements VcsDriverInterface
return $this->remoteFilesystem->getContents($this->originUrl, $url, false); return $this->remoteFilesystem->getContents($this->originUrl, $url, false);
} }
/**
* Return if current repository url is local
*
* @param string $url
* @return boolean Repository url is local
*/
protected static function isLocalUrl($url)
{
return (bool) preg_match('{^(file://|/|[a-z]:[\\\\/])}i', $url);
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */

View File

@ -357,6 +357,17 @@ class Filesystem
return $prefix.($absolute ? '/' : '').implode('/', $parts); return $prefix.($absolute ? '/' : '').implode('/', $parts);
} }
/**
* Return if the given path is local
*
* @param string $path
* @return bool
*/
public static function isLocalPath($path)
{
return (bool) preg_match('{^(file://|/|[a-z]:[\\\\/]|\.\.[\\\\/]|[a-z0-9_.-]+[\\\\/])}i', $path);
}
protected function directorySize($directory) protected function directorySize($directory)
{ {
$it = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS); $it = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS);