1
0
Fork 0

Resolve all dirs before initializing them, fixes #4802

pull/4813/head
Jordi Boggiano 2016-01-20 11:17:40 +00:00
parent 546730dcf3
commit 395d115d9b
2 changed files with 14 additions and 11 deletions

View File

@ -225,7 +225,9 @@ class Config
return (int) $this->config['cache-ttl'];
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':
$value = $this->getComposerEnv('COMPOSER_BIN_COMPAT') ?: $this->config[$key];

View File

@ -146,15 +146,21 @@ class Factory
{
$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
// the www-data's user home and be web-accessible it is a
// 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 (!is_dir($dir)) {
@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
$file = new JsonFile($config->get('home').'/config.json');
if ($file->exists()) {