Added support for backup PHARs
parent
e6560c0462
commit
50c6c100fa
|
@ -61,7 +61,7 @@ EOT
|
|||
$config = Factory::createConfig();
|
||||
$remoteFilesystem = new RemoteFilesystem($this->getIO(), $config);
|
||||
$cacheDir = $config->get('cache-dir');
|
||||
$rollbackDir = $config->get('home');
|
||||
$rollbackDir = $config->get('data-dir');
|
||||
$localFilename = realpath($_SERVER['argv'][0]) ?: $_SERVER['argv'][0];
|
||||
|
||||
// check if current dir is writable and if not try the cache dir from settings
|
||||
|
|
|
@ -28,6 +28,7 @@ class Config
|
|||
'vendor-dir' => 'vendor',
|
||||
'bin-dir' => '{$vendor-dir}/bin',
|
||||
'cache-dir' => '{$home}/cache',
|
||||
'data-dir' => '{$home}',
|
||||
'cache-files-dir' => '{$cache-dir}/files',
|
||||
'cache-repo-dir' => '{$cache-dir}/repo',
|
||||
'cache-vcs-dir' => '{$cache-dir}/vcs',
|
||||
|
@ -151,6 +152,7 @@ class Config
|
|||
case 'vendor-dir':
|
||||
case 'bin-dir':
|
||||
case 'process-timeout':
|
||||
case 'data-dir':
|
||||
case 'cache-dir':
|
||||
case 'cache-files-dir':
|
||||
case 'cache-repo-dir':
|
||||
|
|
|
@ -36,6 +36,7 @@ use Composer\Package\Version\VersionParser;
|
|||
*/
|
||||
class Factory
|
||||
{
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws \RuntimeException
|
||||
|
@ -43,29 +44,28 @@ class Factory
|
|||
protected static function getHomeDir()
|
||||
{
|
||||
$home = getenv('COMPOSER_HOME');
|
||||
$cacheDir = getenv('COMPOSER_CACHE_DIR');
|
||||
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'), '/');
|
||||
$followXDG = false;
|
||||
|
||||
if (!$home) {
|
||||
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
|
||||
if (!getenv('APPDATA')) {
|
||||
throw new \RuntimeException('The APPDATA or COMPOSER_HOME environment variable must be set for composer to run correctly');
|
||||
}
|
||||
$home = getenv('APPDATA') . '/Composer';
|
||||
} elseif (getenv('XDG_CONFIG_DIRS')) {
|
||||
$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'), '/');
|
||||
|
||||
if (getenv('XDG_CONFIG_DIRS')) {
|
||||
// XDG Base Directory Specifications
|
||||
$followXDG = true;
|
||||
$xdgConfig = getenv('XDG_CONFIG_HOME');
|
||||
if (!$xdgConfig) {
|
||||
$xdgConfig = $userDir . '/.config';
|
||||
}
|
||||
$home = $xdgConfig . '/composer';
|
||||
} else {
|
||||
$home = $userDir . '/.composer';
|
||||
$home = $userDir . '/composer';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,23 +87,47 @@ class Factory
|
|||
} else {
|
||||
$cacheDir = $home . '/cache';
|
||||
}
|
||||
|
||||
$cacheDir = strtr($cacheDir, '\\', '/');
|
||||
} elseif (getenv('XDG_CONFIG_DIRS')) {
|
||||
$followXDG = true;
|
||||
$xdgCache = getenv('XDG_CACHE_HOME');
|
||||
if (!$xdgCache) {
|
||||
$xdgCache = $userDir . '/.cache';
|
||||
$xdgCache = $home . '/.cache';
|
||||
}
|
||||
$cacheDir = $xdgCache . '/composer';
|
||||
} else {
|
||||
$cacheDir = $home . '/.cache';
|
||||
$cacheDir = $home . '/cache';
|
||||
}
|
||||
}
|
||||
|
||||
return $cacheDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $home
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function getDataDir($home)
|
||||
{
|
||||
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
|
||||
$dataDir = strtr($home, '\\', '/');
|
||||
} 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'), '/');
|
||||
$xdgData = $userDir . '/.local/share';
|
||||
}
|
||||
$dataDir = $xdgData . '/composer';
|
||||
} else {
|
||||
$dataDir = $home;
|
||||
}
|
||||
|
||||
return $dataDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param IOInterface|null $io
|
||||
* @return Config
|
||||
|
@ -113,11 +137,12 @@ class Factory
|
|||
// determine home and cache dirs
|
||||
$home = self::getHomeDir();
|
||||
$cacheDir = self::getCacheDir($home);
|
||||
$dataDir = 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) as $dir) {
|
||||
foreach (array($home, $cacheDir, $dataDir) as $dir) {
|
||||
if (!file_exists($dir . '/.htaccess')) {
|
||||
if (!is_dir($dir)) {
|
||||
@mkdir($dir, 0777, true);
|
||||
|
@ -127,22 +152,34 @@ class Factory
|
|||
}
|
||||
|
||||
// Move content of old composer dir to XDG
|
||||
if ($followXDG && file_exists($userDir . '/.composer')) {
|
||||
if (getenv('XDG_CONFIG_DIRS') !== false && getenv('COMPOSER_HOME') === false && getenv('COMPOSER_CACHE_DIR') === false) {
|
||||
$userDir = rtrim(getenv('HOME'), '/');
|
||||
$oldComposerHome = $userDir . '/.composer';
|
||||
if (file_exists($oldComposerHome)) {
|
||||
// migrate to XDG
|
||||
@rename($userDir . '/.composer/config.json', $home . '/config.json');
|
||||
@unlink($userDir . '/.composer/.htaccess');
|
||||
@unlink($userDir . '/.composer/cache/.htaccess');
|
||||
foreach (glob($userDir . '/.composer/cache/*') as $oldCacheDir) {
|
||||
@rename($oldCacheDir, $cacheDir . '/' . basename($oldCacheDir));
|
||||
foreach (glob($oldComposerHome . '/*.json') as $file) {
|
||||
rename($file, $home . '/' . basename($file));
|
||||
}
|
||||
|
||||
foreach (glob($oldComposerHome . '/*.phar') as $file) {
|
||||
rename($file, $dataDir . '/' . basename($file));
|
||||
}
|
||||
|
||||
foreach (glob($oldComposerHome . '/cache/*') as $oldCacheDir) {
|
||||
rename($oldCacheDir, $cacheDir . '/' . basename($oldCacheDir));
|
||||
}
|
||||
|
||||
unlink($oldComposerHome . '/.htaccess');
|
||||
unlink($oldComposerHome . '/cache/.htaccess');
|
||||
rmdir($oldComposerHome . '/cache');
|
||||
rmdir($oldComposerHome);
|
||||
}
|
||||
@rmdir($userDir . '/.composer/cache');
|
||||
@rmdir($userDir . '/.composer');
|
||||
}
|
||||
|
||||
$config = new Config();
|
||||
|
||||
// add dirs to the config
|
||||
$config->merge(array('config' => array('home' => $home, 'cache-dir' => $cacheDir)));
|
||||
$config->merge(array('config' => array('home' => $home, 'cache-dir' => $cacheDir, 'data-dir' => $dataDir)));
|
||||
|
||||
// load global config
|
||||
$file = new JsonFile($home.'/config.json');
|
||||
|
@ -326,9 +363,7 @@ class Factory
|
|||
|
||||
// init locker if possible
|
||||
if (isset($composerFile)) {
|
||||
$lockFile = "json" === pathinfo($composerFile, PATHINFO_EXTENSION)
|
||||
? substr($composerFile, 0, -4).'lock'
|
||||
: $composerFile . '.lock';
|
||||
$lockFile = "json" === pathinfo($composerFile, PATHINFO_EXTENSION) ? substr($composerFile, 0, -4) . 'lock' : $composerFile . '.lock';
|
||||
$locker = new Package\Locker($io, new JsonFile($lockFile, new RemoteFilesystem($io, $config)), $rm, $im, md5_file($composerFile));
|
||||
$composer->setLocker($locker);
|
||||
}
|
||||
|
@ -506,4 +541,5 @@ class Factory
|
|||
|
||||
return $factory->createComposer($io, $config, $disablePlugins);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue