From 42a7176b594d93ee8813c9d8d5b89f4f82ef606d Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 13 Apr 2022 12:57:19 +0200 Subject: [PATCH] Fixed lock file being used when lock:false is in config, refs #10715 --- doc/06-config.md | 2 +- src/Composer/Factory.php | 5 ++++- src/Composer/Util/Platform.php | 9 +++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/doc/06-config.md b/doc/06-config.md index 636cf955508c..d89aa062d913 100644 --- a/doc/06-config.md +++ b/doc/06-config.md @@ -396,7 +396,7 @@ in the Composer home, cache, and data directories. ## lock Defaults to `true`. If set to `false`, Composer will not create a `composer.lock` -file. +file and will ignore it if one is present. ## platform-check diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php index ee0b07f3e3bb..9288da19b914 100644 --- a/src/Composer/Factory.php +++ b/src/Composer/Factory.php @@ -442,8 +442,11 @@ public function createComposer(IOInterface $io, $localConfig = null, $disablePlu // init locker if possible if ($fullLoad && isset($composerFile)) { $lockFile = self::getLockFile($composerFile); + if (!$config->get('lock') && file_exists($lockFile)) { + $io->writeError(''.$lockFile.' is present but ignored as the "lock" config option is disabled.'); + } - $locker = new Package\Locker($io, new JsonFile($lockFile, null, $io), $im, file_get_contents($composerFile), $process); + $locker = new Package\Locker($io, new JsonFile($config->get('lock') ? $lockFile : Platform::getDevNull(), null, $io), $im, file_get_contents($composerFile), $process); $composer->setLocker($locker); } diff --git a/src/Composer/Util/Platform.php b/src/Composer/Util/Platform.php index 756c115063ac..163bf36d4aed 100644 --- a/src/Composer/Util/Platform.php +++ b/src/Composer/Util/Platform.php @@ -249,4 +249,13 @@ private static function isVirtualBoxGuest() return self::$isVirtualBoxGuest; } + + public static function getDevNull() + { + if (self::isWindows()) { + return 'NUL'; + } + + return '/dev/null'; + } }