1
0
Fork 0

Add workaround for php bug 53460 glob() can return false, fixes #2278

pull/2294/head
Jordi Boggiano 2013-09-26 11:38:33 +02:00
parent 807600b255
commit 3f6227a996
4 changed files with 21 additions and 5 deletions

View File

@ -152,6 +152,7 @@ EOT
} }
$composer = Factory::create($io, null, $disablePlugins); $composer = Factory::create($io, null, $disablePlugins);
$fs = new Filesystem();
if ($noScripts === false) { if ($noScripts === false) {
// dispatch event // dispatch event
@ -187,7 +188,6 @@ EOT
} }
try { try {
$fs = new Filesystem();
$dirs = iterator_to_array($finder); $dirs = iterator_to_array($finder);
unset($finder); unset($finder);
foreach ($dirs as $dir) { foreach ($dirs as $dir) {
@ -222,10 +222,10 @@ EOT
chdir($oldCwd); chdir($oldCwd);
$vendorComposerDir = $composer->getConfig()->get('vendor-dir').'/composer'; $vendorComposerDir = $composer->getConfig()->get('vendor-dir').'/composer';
if (is_dir($vendorComposerDir) && glob($vendorComposerDir.'/*') === array() && count(glob($vendorComposerDir.'/.*')) === 2) { if (is_dir($vendorComposerDir) && $fs->isDirEmpty($vendorComposerDir)) {
@rmdir($vendorComposerDir); @rmdir($vendorComposerDir);
$vendorDir = $composer->getConfig()->get('vendor-dir'); $vendorDir = $composer->getConfig()->get('vendor-dir');
if (is_dir($vendorDir) && glob($vendorDir.'/*') === array() && count(glob($vendorDir.'/.*')) === 2) { if (is_dir($vendorDir) && $fs->isDirEmpty($vendorDir)) {
@rmdir($vendorDir); @rmdir($vendorDir);
} }
} }

View File

@ -132,7 +132,7 @@ abstract class ArchiveDownloader extends FileDownloader
*/ */
private function listFiles($dir) private function listFiles($dir)
{ {
$files = array_merge(glob($dir . '/.*'), glob($dir . '/*')); $files = array_merge(glob($dir . '/.*') ?: array(), glob($dir . '/*') ?: array());
return array_values(array_filter($files, function ($el) { return array_values(array_filter($files, function ($el) {
return basename($el) !== '.' && basename($el) !== '..'; return basename($el) !== '.' && basename($el) !== '..';

View File

@ -15,6 +15,7 @@ namespace Composer\Installer;
use Composer\Package\PackageInterface; use Composer\Package\PackageInterface;
use Composer\Downloader\DownloadManager; use Composer\Downloader\DownloadManager;
use Composer\Repository\InstalledRepositoryInterface; use Composer\Repository\InstalledRepositoryInterface;
use Composer\Util\Filesystem;
/** /**
* Project Installer is used to install a single package into a directory as * Project Installer is used to install a single package into a directory as
@ -26,11 +27,13 @@ class ProjectInstaller implements InstallerInterface
{ {
private $installPath; private $installPath;
private $downloadManager; private $downloadManager;
private $filesystem;
public function __construct($installPath, DownloadManager $dm) public function __construct($installPath, DownloadManager $dm)
{ {
$this->installPath = rtrim(strtr($installPath, '\\', '/'), '/').'/'; $this->installPath = rtrim(strtr($installPath, '\\', '/'), '/').'/';
$this->downloadManager = $dm; $this->downloadManager = $dm;
$this->filesystem = new Filesystem;
} }
/** /**
@ -58,7 +61,7 @@ class ProjectInstaller implements InstallerInterface
public function install(InstalledRepositoryInterface $repo, PackageInterface $package) public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
{ {
$installPath = $this->installPath; $installPath = $this->installPath;
if (file_exists($installPath) && (count(glob($installPath.'*')) || (count(glob($installPath.'.*')) > 2))) { if (file_exists($installPath) && !$this->filesystem->isDirEmpty($installPath)) {
throw new \InvalidArgumentException("Project directory $installPath is not empty."); throw new \InvalidArgumentException("Project directory $installPath is not empty.");
} }
if (!is_dir($installPath)) { if (!is_dir($installPath)) {

View File

@ -41,6 +41,19 @@ class Filesystem
return false; return false;
} }
/**
* Checks if a directory is empty
*
* @param string $dir
* @return bool
*/
public function isDirEmpty($dir)
{
$dir = rtrim($dir, '/\\');
return count(glob($dir.'/*') ?: array()) === 0 && count(glob($dir.'/.*') ?: array()) === 2;
}
/** /**
* Recursively remove a directory * Recursively remove a directory
* *