From 03e9c5d74464213a47a2ad8dc8eb249613701d6f Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 14 Jun 2023 11:19:05 +0200 Subject: [PATCH] Only update autoload_runtime.php when it changed --- Internal/ComposerPlugin.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Internal/ComposerPlugin.php b/Internal/ComposerPlugin.php index d689e7f..32c7f68 100644 --- a/Internal/ComposerPlugin.php +++ b/Internal/ComposerPlugin.php @@ -105,7 +105,12 @@ public function updateAutoloadFile(): void '%runtime_options%' => '['.substr(var_export($extra, true), 7, -1)." 'project_dir' => {$projectDir},\n]", ]); - file_put_contents(substr_replace($autoloadFile, '_runtime', -4, 0), $code); + // could use Composer\Util\Filesystem::filePutContentsIfModified once Composer 1.x support is dropped for this plugin + $path = substr_replace($autoloadFile, '_runtime', -4, 0); + $currentContent = @file_exists($path) ? @file_get_contents($path) : false; + if (false === $currentContent || $currentContent !== $code) { + file_put_contents($path, $code); + } } public static function getSubscribedEvents(): array