From 2d2d22d0ecfa9148f15ce13969fd614417d26ab1 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 5 May 2023 14:14:26 +0200 Subject: [PATCH] Fix lock file being more recent than vendor dir when require guesses the constraint after resolution, fixes #11405 --- src/Composer/Command/RequireCommand.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Composer/Command/RequireCommand.php b/src/Composer/Command/RequireCommand.php index 0ef69066a..90ca115b0 100644 --- a/src/Composer/Command/RequireCommand.php +++ b/src/Composer/Command/RequireCommand.php @@ -551,10 +551,15 @@ EOT if (false === $contents) { throw new \RuntimeException('Unable to read '.$this->json->getPath().' contents to update the lock file hash.'); } - $lock = new JsonFile(Factory::getLockFile($this->json->getPath())); + $lockFile = Factory::getLockFile($this->json->getPath()); + $lockMtime = filemtime($lockFile); + $lock = new JsonFile($lockFile); $lockData = $lock->read(); $lockData['content-hash'] = Locker::getContentHash($contents); $lock->write($lockData); + if (is_int($lockMtime)) { + @touch($lockFile, $lockMtime); + } } }