From dc509b236fad2604d12b251c69884a9f3b3f4173 Mon Sep 17 00:00:00 2001 From: Fedir Kryvytskyi Date: Wed, 6 Sep 2017 21:25:12 +0200 Subject: [PATCH] Fixed error, when composer.phar was broken, if it compiled inside folder, that has /composer in path --- src/Composer/Compiler.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Composer/Compiler.php b/src/Composer/Compiler.php index 69e98e91a..6fccb8e96 100644 --- a/src/Composer/Compiler.php +++ b/src/Composer/Compiler.php @@ -164,10 +164,24 @@ class Compiler $util->save($pharFile, \Phar::SHA1); } + /** + * @param \SplFileInfo $file + * @return string + */ + private function getRelativeFilePath($file) + { + $realPath = $file->getRealPath(); + $pathPrefix = dirname(dirname(__DIR__)).DIRECTORY_SEPARATOR; + + $pos = strpos($realPath, $pathPrefix); + $relativePath = ($pos !== false) ? substr_replace($realPath, '', $pos, strlen($pathPrefix)) : $realPath; + + return strtr($relativePath, '\\', '/'); + } + private function addFile($phar, $file, $strip = true) { - $path = strtr(str_replace(dirname(dirname(__DIR__)).DIRECTORY_SEPARATOR, '', $file->getRealPath()), '\\', '/'); - + $path = $this->getRelativeFilePath($file); $content = file_get_contents($file); if ($strip) { $content = $this->stripWhitespace($content);