From ef6c224ec2191eaaaf094fc234c42f3c7f393d81 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 6 Feb 2024 13:46:46 +0100 Subject: [PATCH] Fix require command crashing at the end if no lock file is present, fixes #11814 --- src/Composer/Command/RequireCommand.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Composer/Command/RequireCommand.php b/src/Composer/Command/RequireCommand.php index 4a8a47559..b7ee15681 100644 --- a/src/Composer/Command/RequireCommand.php +++ b/src/Composer/Command/RequireCommand.php @@ -558,13 +558,15 @@ EOT throw new \RuntimeException('Unable to read '.$this->json->getPath().' contents to update the lock file hash.'); } $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); + if (file_exists($lockFile)) { + $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); + } } } }