Browse Source

Force all glob results to be realpath'd.

Richard Quadling 11 năm trước cách đây
mục cha
commit
443858dae7

+ 2 - 1
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();
     }
 }

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

+ 3 - 1
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));
                         }

+ 1 - 1
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);
             }
         }

+ 18 - 1
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;
     }
 
     /**