1
0
Fork 0

Fix directory paths when using XDG

pull/1407/head
Nicolas Toniazzi 2014-12-15 15:10:15 +01:00
parent ad9c3d3b30
commit 1a5b87442a
1 changed files with 28 additions and 16 deletions

View File

@ -37,6 +37,20 @@ use Composer\Package\Version\VersionParser;
class Factory
{
/**
* @return string
* @throws \RuntimeException
*/
private static function getUserDir()
{
if (!getenv('HOME')) {
throw new \RuntimeException('The HOME or COMPOSER_HOME environment variable must be set for composer to run correctly');
}
$userDir = rtrim(getenv('HOME'), '/');
return $userDir;
}
/**
* @return string
* @throws \RuntimeException
@ -51,10 +65,7 @@ class Factory
}
$home = strtr(getenv('APPDATA'), '\\', '/') . '/Composer';
} else {
if (!getenv('HOME')) {
throw new \RuntimeException('The HOME or COMPOSER_HOME environment variable must be set for composer to run correctly');
}
$userDir = rtrim(getenv('HOME'), '/');
$userDir = self::getUserDir();
if (getenv('XDG_CONFIG_DIRS')) {
// XDG Base Directory Specifications
@ -88,14 +99,18 @@ class Factory
$cacheDir = $home . '/cache';
}
$cacheDir = strtr($cacheDir, '\\', '/');
} elseif (getenv('XDG_CONFIG_DIRS')) {
$xdgCache = getenv('XDG_CACHE_HOME');
if (!$xdgCache) {
$xdgCache = $home . '/.cache';
}
$cacheDir = $xdgCache . '/composer';
} else {
$cacheDir = $home . '/cache';
$userDir = self::getUserDir();
if (getenv('XDG_CONFIG_DIRS')) {
$xdgCache = getenv('XDG_CACHE_HOME');
if (!$xdgCache) {
$xdgCache = $userDir . '/.cache';
}
$cacheDir = $xdgCache . '/composer';
} else {
$cacheDir = $home . '/cache';
}
}
}
@ -114,10 +129,7 @@ class Factory
} elseif (getenv('XDG_CONFIG_DIRS')) {
$xdgData = getenv('XDG_DATA_HOME');
if (!$xdgData) {
if (!getenv('HOME')) {
throw new \RuntimeException('The HOME or COMPOSER_HOME environment variable must be set for composer to run correctly');
}
$userDir = rtrim(getenv('HOME'), '/');
$userDir = self::getUserDir();
$xdgData = $userDir . '/.local/share';
}
$dataDir = $xdgData . '/composer';
@ -490,7 +502,7 @@ class Factory
*/
protected function createPluginManager(Composer $composer, IOInterface $io, RepositoryInterface $globalRepository = null)
{
return new Plugin\PluginManager($composer, $io, $globalRepository);
return new Plugin\PluginManager($io, $composer, $globalRepository);
}
/**