1
0
Fork 0

Fixed bug potentially causing broken sites and solved #4431 along the way.

pull/4851/head
Niels Keurentjes 2016-01-30 01:13:37 +01:00
parent 7c3e621102
commit 05caf8349c
1 changed files with 15 additions and 9 deletions

View File

@ -29,6 +29,21 @@ class PathDownloader extends FileDownloader
*/ */
public function download(PackageInterface $package, $path) public function download(PackageInterface $package, $path)
{ {
$url = $package->getDistUrl();
$realUrl = realpath($url);
if (false === $realUrl || !file_exists($realUrl) || !is_dir($realUrl)) {
throw new \RuntimeException(sprintf(
'Source path "%s" is not found for package %s', $url, $package->getName()
));
}
if (strpos(realpath($path) . DIRECTORY_SEPARATOR, $realUrl . DIRECTORY_SEPARATOR) === 0) {
throw new \RuntimeException(sprintf(
'Package %s cannot install to "%s" inside its source at "%s"',
$package->getName(), realpath($path), $realUrl
));
}
$fileSystem = new Filesystem(); $fileSystem = new Filesystem();
$this->filesystem->removeDirectory($path); $this->filesystem->removeDirectory($path);
@ -38,15 +53,6 @@ class PathDownloader extends FileDownloader
$package->getFullPrettyVersion() $package->getFullPrettyVersion()
)); ));
$url = $package->getDistUrl();
$realUrl = realpath($url);
if (false === $realUrl || !file_exists($realUrl) || !is_dir($realUrl)) {
throw new \RuntimeException(sprintf(
'Path "%s" is not found',
$url
));
}
try { try {
$shortestPath = $this->filesystem->findShortestPath($path, $realUrl); $shortestPath = $this->filesystem->findShortestPath($path, $realUrl);
$fileSystem->symlink($shortestPath, $path); $fileSystem->symlink($shortestPath, $path);