瀏覽代碼

Resolve all dirs before initializing them, fixes #4802

Jordi Boggiano 9 年之前
父節點
當前提交
395d115d9b
共有 2 個文件被更改,包括 14 次插入11 次删除
  1. 3 1
      src/Composer/Config.php
  2. 11 10
      src/Composer/Factory.php

+ 3 - 1
src/Composer/Config.php

@@ -225,7 +225,9 @@ class Config
                 return (int) $this->config['cache-ttl'];
                 return (int) $this->config['cache-ttl'];
 
 
             case 'home':
             case 'home':
-                return rtrim($this->process($this->config[$key], $flags), '/\\');
+                $val = preg_replace('#^(\$HOME|~)(/|$)#', rtrim(getenv('HOME') ?: getenv('USERPROFILE'), '/\\') . '/', $this->config[$key]);
+
+                return rtrim($this->process($val, $flags), '/\\');
 
 
             case 'bin-compat':
             case 'bin-compat':
                 $value = $this->getComposerEnv('COMPOSER_BIN_COMPAT') ?: $this->config[$key];
                 $value = $this->getComposerEnv('COMPOSER_BIN_COMPAT') ?: $this->config[$key];

+ 11 - 10
src/Composer/Factory.php

@@ -146,15 +146,21 @@ class Factory
     {
     {
         $cwd = $cwd ?: getcwd();
         $cwd = $cwd ?: getcwd();
 
 
-        // determine home and cache dirs
-        $home     = self::getHomeDir();
-        $cacheDir = self::getCacheDir($home);
-        $dataDir  = self::getDataDir($home);
+        $config = new Config(true, $cwd);
+
+        // determine and add main dirs to the config
+        $home = self::getHomeDir();
+        $config->merge(array('config' => array(
+            'home' => $home,
+            'cache-dir' => self::getCacheDir($home),
+            'data-dir' => self::getDataDir($home),
+        )));
 
 
         // Protect directory against web access. Since HOME could be
         // Protect directory against web access. Since HOME could be
         // the www-data's user home and be web-accessible it is a
         // the www-data's user home and be web-accessible it is a
         // potential security risk
         // potential security risk
-        foreach (array($home, $cacheDir, $dataDir) as $dir) {
+        $dirs = array($config->get('home'), $config->get('cache-dir'), $config->get('data-dir'));
+        foreach ($dirs as $dir) {
             if (!file_exists($dir . '/.htaccess')) {
             if (!file_exists($dir . '/.htaccess')) {
                 if (!is_dir($dir)) {
                 if (!is_dir($dir)) {
                     @mkdir($dir, 0777, true);
                     @mkdir($dir, 0777, true);
@@ -163,11 +169,6 @@ class Factory
             }
             }
         }
         }
 
 
-        $config = new Config(true, $cwd);
-
-        // add dirs to the config
-        $config->merge(array('config' => array('home' => $home, 'cache-dir' => $cacheDir, 'data-dir' => $dataDir)));
-
         // load global config
         // load global config
         $file = new JsonFile($config->get('home').'/config.json');
         $file = new JsonFile($config->get('home').'/config.json');
         if ($file->exists()) {
         if ($file->exists()) {