1
0
Fork 0

Always load the current InstalledVersions when writing to disk, fixes #9457

pull/9461/head
Jordi Boggiano 2020-11-11 10:47:42 +01:00
parent 14d20776a2
commit fec44f883c
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
2 changed files with 13 additions and 0 deletions

View File

@ -335,6 +335,11 @@ class Factory
if ($fullLoad) { if ($fullLoad) {
// load auth configs into the IO instance // load auth configs into the IO instance
$io->loadConfiguration($config); $io->loadConfiguration($config);
// load existing Composer\InstalledVersions instance if available
if (!class_exists('Composer\InstalledVersions', false) && file_exists($installedVersionsPath = $config->get('vendor-dir').'/composer/InstalledVersions.php')) {
include $installedVersionsPath;
}
} }
$httpDownloader = self::createHttpDownloader($io, $config); $httpDownloader = self::createHttpDownloader($io, $config);

View File

@ -206,6 +206,14 @@ class FilesystemRepository extends WritableArrayRepository
$installedVersionsClass = file_get_contents(__DIR__.'/../InstalledVersions.php'); $installedVersionsClass = file_get_contents(__DIR__.'/../InstalledVersions.php');
$installedVersionsClass = str_replace('private static $installed;', 'private static $installed = '.var_export($versions, true).';', $installedVersionsClass); $installedVersionsClass = str_replace('private static $installed;', 'private static $installed = '.var_export($versions, true).';', $installedVersionsClass);
$fs->filePutContentsIfModified($repoDir.'/InstalledVersions.php', $installedVersionsClass); $fs->filePutContentsIfModified($repoDir.'/InstalledVersions.php', $installedVersionsClass);
// make sure the InstalledVersions class is loaded and has the latest state
// not using the autoloader here to avoid loading the one from Composer's vendor dir
if (!class_exists('Composer\InstalledVersions', false)) {
include $repoDir.'/InstalledVersions.php';
} else {
\Composer\InstalledVersions::reload($versions);
}
} }
} }
} }