1
0
Fork 0

Trim trailing slash in path downloader to avoid symlink issues, and in FileDownloader::getLocalChanges as we append a string without slash, refs #9422

pull/9426/head
Jordi Boggiano 2020-11-05 16:54:06 +01:00
parent c04c42b7b4
commit bc9336946e
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
3 changed files with 22 additions and 0 deletions

View File

@ -429,6 +429,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
$e = null;
$output = '';
$targetDir = Filesystem::trimTrailingSlash($targetDir);
try {
if (is_dir($targetDir.'_compare')) {
$this->filesystem->removeDirectory($targetDir.'_compare');

View File

@ -47,6 +47,7 @@ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInter
*/
public function download(PackageInterface $package, $path, PackageInterface $prevPackage = null, $output = true)
{
$path = Filesystem::trimTrailingSlash($path);
$url = $package->getDistUrl();
$realUrl = realpath($url);
if (false === $realUrl || !file_exists($realUrl) || !is_dir($realUrl)) {
@ -80,6 +81,7 @@ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInter
*/
public function install(PackageInterface $package, $path, $output = true)
{
$path = Filesystem::trimTrailingSlash($path);
$url = $package->getDistUrl();
$realUrl = realpath($url);
@ -178,6 +180,7 @@ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInter
*/
public function remove(PackageInterface $package, $path, $output = true)
{
$path = Filesystem::trimTrailingSlash($path);
/**
* realpath() may resolve Windows junctions to the source path, so we'll check for a junction first
* to prevent a false positive when checking if the dist and install paths are the same.
@ -209,6 +212,7 @@ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInter
*/
public function getVcsReference(PackageInterface $package, $path)
{
$path = Filesystem::trimTrailingSlash($path);
$parser = new VersionParser;
$guesser = new VersionGuesser($this->config, $this->process, $parser);
$dumper = new ArrayDumper;

View File

@ -506,6 +506,23 @@ class Filesystem
return $prefix.($absolute ? '/' : '').implode('/', $parts);
}
/**
* Remove trailing slashes if present to avoid issues with symlinks
*
* And other possible unforeseen disasters, see https://github.com/composer/composer/pull/9422
*
* @param string $path
* @return bool
*/
public static function trimTrailingSlash($path)
{
if (!preg_match('{^[/\\\\]+$}', $path)) {
$path = rtrim($path, '/\\');
}
return $path;
}
/**
* Return if the given path is local
*