Fix directory paths when using XDG
parent
ad9c3d3b30
commit
1a5b87442a
|
@ -37,6 +37,20 @@ use Composer\Package\Version\VersionParser;
|
||||||
class Factory
|
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
|
* @return string
|
||||||
* @throws \RuntimeException
|
* @throws \RuntimeException
|
||||||
|
@ -51,10 +65,7 @@ class Factory
|
||||||
}
|
}
|
||||||
$home = strtr(getenv('APPDATA'), '\\', '/') . '/Composer';
|
$home = strtr(getenv('APPDATA'), '\\', '/') . '/Composer';
|
||||||
} else {
|
} else {
|
||||||
if (!getenv('HOME')) {
|
$userDir = self::getUserDir();
|
||||||
throw new \RuntimeException('The HOME or COMPOSER_HOME environment variable must be set for composer to run correctly');
|
|
||||||
}
|
|
||||||
$userDir = rtrim(getenv('HOME'), '/');
|
|
||||||
|
|
||||||
if (getenv('XDG_CONFIG_DIRS')) {
|
if (getenv('XDG_CONFIG_DIRS')) {
|
||||||
// XDG Base Directory Specifications
|
// XDG Base Directory Specifications
|
||||||
|
@ -88,16 +99,20 @@ class Factory
|
||||||
$cacheDir = $home . '/cache';
|
$cacheDir = $home . '/cache';
|
||||||
}
|
}
|
||||||
$cacheDir = strtr($cacheDir, '\\', '/');
|
$cacheDir = strtr($cacheDir, '\\', '/');
|
||||||
} elseif (getenv('XDG_CONFIG_DIRS')) {
|
} else {
|
||||||
|
$userDir = self::getUserDir();
|
||||||
|
|
||||||
|
if (getenv('XDG_CONFIG_DIRS')) {
|
||||||
$xdgCache = getenv('XDG_CACHE_HOME');
|
$xdgCache = getenv('XDG_CACHE_HOME');
|
||||||
if (!$xdgCache) {
|
if (!$xdgCache) {
|
||||||
$xdgCache = $home . '/.cache';
|
$xdgCache = $userDir . '/.cache';
|
||||||
}
|
}
|
||||||
$cacheDir = $xdgCache . '/composer';
|
$cacheDir = $xdgCache . '/composer';
|
||||||
} else {
|
} else {
|
||||||
$cacheDir = $home . '/cache';
|
$cacheDir = $home . '/cache';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $cacheDir;
|
return $cacheDir;
|
||||||
}
|
}
|
||||||
|
@ -114,10 +129,7 @@ class Factory
|
||||||
} elseif (getenv('XDG_CONFIG_DIRS')) {
|
} elseif (getenv('XDG_CONFIG_DIRS')) {
|
||||||
$xdgData = getenv('XDG_DATA_HOME');
|
$xdgData = getenv('XDG_DATA_HOME');
|
||||||
if (!$xdgData) {
|
if (!$xdgData) {
|
||||||
if (!getenv('HOME')) {
|
$userDir = self::getUserDir();
|
||||||
throw new \RuntimeException('The HOME or COMPOSER_HOME environment variable must be set for composer to run correctly');
|
|
||||||
}
|
|
||||||
$userDir = rtrim(getenv('HOME'), '/');
|
|
||||||
$xdgData = $userDir . '/.local/share';
|
$xdgData = $userDir . '/.local/share';
|
||||||
}
|
}
|
||||||
$dataDir = $xdgData . '/composer';
|
$dataDir = $xdgData . '/composer';
|
||||||
|
@ -490,7 +502,7 @@ class Factory
|
||||||
*/
|
*/
|
||||||
protected function createPluginManager(Composer $composer, IOInterface $io, RepositoryInterface $globalRepository = null)
|
protected function createPluginManager(Composer $composer, IOInterface $io, RepositoryInterface $globalRepository = null)
|
||||||
{
|
{
|
||||||
return new Plugin\PluginManager($composer, $io, $globalRepository);
|
return new Plugin\PluginManager($io, $composer, $globalRepository);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue