Do not realpath relative local URLs, fixes #2916
parent
959cc4d63c
commit
effacc1185
|
@ -60,6 +60,9 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
|
|||
$urls = $package->getSourceUrls();
|
||||
while ($url = array_shift($urls)) {
|
||||
try {
|
||||
if (Filesystem::isLocalPath($url)) {
|
||||
$url = realpath($url);
|
||||
}
|
||||
$this->doDownload($package, $path, $url);
|
||||
break;
|
||||
} catch (\Exception $e) {
|
||||
|
@ -107,6 +110,9 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
|
|||
$urls = $target->getSourceUrls();
|
||||
while ($url = array_shift($urls)) {
|
||||
try {
|
||||
if (Filesystem::isLocalPath($url)) {
|
||||
$url = realpath($url);
|
||||
}
|
||||
$this->doUpdate($initial, $target, $path, $url);
|
||||
break;
|
||||
} catch (\Exception $e) {
|
||||
|
|
|
@ -37,8 +37,9 @@ class GitDriver extends VcsDriver
|
|||
*/
|
||||
public function initialize()
|
||||
{
|
||||
if (static::isLocalUrl($this->url)) {
|
||||
$this->repoDir = str_replace('file://', '', $this->url);
|
||||
if (Filesystem::isLocalPath($this->url)) {
|
||||
$this->repoDir = $this->url;
|
||||
$cacheUrl = realpath($this->url);
|
||||
} else {
|
||||
$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);
|
||||
}
|
||||
|
||||
$cacheUrl = $this->url;
|
||||
}
|
||||
|
||||
$this->getTags();
|
||||
$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
|
||||
if (static::isLocalUrl($url)) {
|
||||
if (Filesystem::isLocalPath($url)) {
|
||||
if (!is_dir($url)) {
|
||||
throw new \RuntimeException('Directory does not exist: '.$url);
|
||||
}
|
||||
|
|
|
@ -34,8 +34,8 @@ class HgDriver extends VcsDriver
|
|||
*/
|
||||
public function initialize()
|
||||
{
|
||||
if (static::isLocalUrl($this->url)) {
|
||||
$this->repoDir = str_replace('file://', '', $this->url);
|
||||
if (Filesystem::isLocalPath($this->url)) {
|
||||
$this->repoDir = $this->url;
|
||||
} else {
|
||||
$cacheDir = $this->config->get('cache-vcs-dir');
|
||||
$this->repoDir = $cacheDir . '/' . preg_replace('{[^a-z0-9]}i', '-', $this->url) . '/';
|
||||
|
@ -197,7 +197,7 @@ class HgDriver extends VcsDriver
|
|||
}
|
||||
|
||||
// local filesystem
|
||||
if (static::isLocalUrl($url)) {
|
||||
if (Filesystem::isLocalPath($url)) {
|
||||
if (!is_dir($url)) {
|
||||
throw new \RuntimeException('Directory does not exist: '.$url);
|
||||
}
|
||||
|
|
|
@ -252,7 +252,7 @@ class SvnDriver extends VcsDriver
|
|||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ use Composer\Config;
|
|||
use Composer\IO\IOInterface;
|
||||
use Composer\Util\ProcessExecutor;
|
||||
use Composer\Util\RemoteFilesystem;
|
||||
use Composer\Util\Filesystem;
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
|
||||
if (self::isLocalUrl($repoConfig['url'])) {
|
||||
$repoConfig['url'] = realpath(
|
||||
preg_replace('/^file:\/\//', '', $repoConfig['url'])
|
||||
);
|
||||
if (Filesystem::isLocalPath($repoConfig['url'])) {
|
||||
$repoConfig['url'] = preg_replace('{^file://}', '', $repoConfig['url']);
|
||||
}
|
||||
|
||||
$this->url = $repoConfig['url'];
|
||||
|
@ -101,17 +99,6 @@ abstract class VcsDriver implements VcsDriverInterface
|
|||
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}
|
||||
*/
|
||||
|
|
|
@ -357,6 +357,17 @@ class Filesystem
|
|||
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)
|
||||
{
|
||||
$it = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS);
|
||||
|
|
Loading…
Reference in New Issue