diff --git a/src/Composer/Command/SelfUpdateCommand.php b/src/Composer/Command/SelfUpdateCommand.php index 8ce355d9c..010f68984 100644 --- a/src/Composer/Command/SelfUpdateCommand.php +++ b/src/Composer/Command/SelfUpdateCommand.php @@ -213,6 +213,7 @@ EOT protected function getOldInstallationFiles($rollbackDir) { - return glob($rollbackDir . '/*' . self::OLD_INSTALL_EXT) ?: array(); + $fs = new Filesystem; + return $fs->realpathGlob($rollbackDir . '/*' . self::OLD_INSTALL_EXT) ?: array(); } } diff --git a/src/Composer/Downloader/ArchiveDownloader.php b/src/Composer/Downloader/ArchiveDownloader.php index bfe174fb7..a412dc830 100644 --- a/src/Composer/Downloader/ArchiveDownloader.php +++ b/src/Composer/Downloader/ArchiveDownloader.php @@ -132,7 +132,7 @@ abstract class ArchiveDownloader extends FileDownloader */ private function listFiles($dir) { - $files = array_merge(glob($dir . '/.*') ?: array(), glob($dir . '/*') ?: array()); + $files = array_merge($this->filesystem->realpathGlob($dir . '/.*') ?: array(), $this->filesystem->realpathGlob($dir . '/*') ?: array()); return array_values(array_filter($files, function ($el) { return basename($el) !== '.' && basename($el) !== '..'; diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php index 099ad37ea..5a4747b48 100644 --- a/src/Composer/Factory.php +++ b/src/Composer/Factory.php @@ -20,6 +20,7 @@ use Composer\Repository\RepositoryManager; use Composer\Repository\RepositoryInterface; use Composer\Util\ProcessExecutor; use Composer\Util\RemoteFilesystem; +use Composer\Util\Filesystem; use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Composer\EventDispatcher\EventDispatcher; use Composer\Autoload\AutoloadGenerator; @@ -132,6 +133,7 @@ class Factory 'cache-vcs-dir' => array('/cache.git' => '/*', '/cache.hg' => '/*'), 'cache-files-dir' => array('/cache.files' => '/*'), ); + $fs = new Filesystem; foreach ($legacyPaths as $key => $oldPaths) { foreach ($oldPaths as $oldPath => $match) { $dir = $config->get($key); @@ -146,7 +148,7 @@ class Factory continue; } } - if (is_array($children = glob($oldPathMatch))) { + if (is_array($children = $fs->realpathGlob($oldPathMatch))) { foreach ($children as $child) { @rename($child, $dir.'/'.basename($child)); } diff --git a/src/Composer/Installer/LibraryInstaller.php b/src/Composer/Installer/LibraryInstaller.php index 646f801d3..7fb0f394c 100644 --- a/src/Composer/Installer/LibraryInstaller.php +++ b/src/Composer/Installer/LibraryInstaller.php @@ -126,7 +126,7 @@ class LibraryInstaller implements InstallerInterface $downloadPath = $this->getPackageBasePath($package); if (strpos($package->getName(), '/')) { $packageVendorDir = dirname($downloadPath); - if (is_dir($packageVendorDir) && !glob($packageVendorDir.'/*')) { + if (is_dir($packageVendorDir) && !$this->filesystem->realpathGlob($packageVendorDir.'/*')) { @rmdir($packageVendorDir); } } diff --git a/src/Composer/Util/Filesystem.php b/src/Composer/Util/Filesystem.php index e8755645a..3ef17452e 100644 --- a/src/Composer/Util/Filesystem.php +++ b/src/Composer/Util/Filesystem.php @@ -41,6 +41,23 @@ class Filesystem return false; } + /** + * Force the results of a glob to be realpaths. + * + * @param string $pattern + * @param int $flags + * @return array + */ + public function realpathGlob($pattern, $flags = 0) + { + $matches = glob($pattern, $flags); + if (!$matches) { + return false; + } + var_dump($matches); + return array_map('realpath', $matches); + } + /** * Checks if a directory is empty * @@ -51,7 +68,7 @@ class Filesystem { $dir = rtrim($dir, '/\\'); - return count(glob($dir.'/*') ?: array()) === 0 && count(glob($dir.'/.*') ?: array()) === 2; + return count($this->realpathGlob($dir.'/*') ?: array()) === 0 && count($this->realpathGlob($dir.'/.*') ?: array()) === 2; } /**