Force all glob results to be realpath'd.

main
Richard Quadling 10 years ago committed by Jordi Boggiano
parent effacc1185
commit 443858dae7

@ -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();
}
}

@ -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) !== '..';

@ -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));
}

@ -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);
}
}

@ -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;
}
/**

Loading…
Cancel
Save