Resolve all dirs before initializing them, fixes #4802
parent
546730dcf3
commit
395d115d9b
|
@ -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];
|
||||||
|
|
|
@ -146,15 +146,21 @@ class Factory
|
||||||
{
|
{
|
||||||
$cwd = $cwd ?: getcwd();
|
$cwd = $cwd ?: getcwd();
|
||||||
|
|
||||||
// determine home and cache dirs
|
$config = new Config(true, $cwd);
|
||||||
$home = self::getHomeDir();
|
|
||||||
$cacheDir = self::getCacheDir($home);
|
// determine and add main dirs to the config
|
||||||
$dataDir = self::getDataDir($home);
|
$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()) {
|
||||||
|
|
Loading…
Reference in New Issue