From fec44f883cc2fb9e0750029706d7e9377800600b Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 11 Nov 2020 10:47:42 +0100 Subject: [PATCH] Always load the current InstalledVersions when writing to disk, fixes #9457 --- src/Composer/Factory.php | 5 +++++ src/Composer/Repository/FilesystemRepository.php | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php index 3862ee78d..aa1052887 100644 --- a/src/Composer/Factory.php +++ b/src/Composer/Factory.php @@ -335,6 +335,11 @@ class Factory if ($fullLoad) { // load auth configs into the IO instance $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); diff --git a/src/Composer/Repository/FilesystemRepository.php b/src/Composer/Repository/FilesystemRepository.php index b63c802a7..85e3532e9 100644 --- a/src/Composer/Repository/FilesystemRepository.php +++ b/src/Composer/Repository/FilesystemRepository.php @@ -206,6 +206,14 @@ class FilesystemRepository extends WritableArrayRepository $installedVersionsClass = file_get_contents(__DIR__.'/../InstalledVersions.php'); $installedVersionsClass = str_replace('private static $installed;', 'private static $installed = '.var_export($versions, true).';', $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); + } } } }