From 46e82cb38d96d4b2ca875c877922d84f5f0459cc Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 26 Sep 2013 12:23:57 +0200 Subject: [PATCH] Retry json file writing 3 times before failing, fixes #2286 --- src/Composer/Json/JsonFile.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Composer/Json/JsonFile.php b/src/Composer/Json/JsonFile.php index f7e1a2126..155f17e6e 100644 --- a/src/Composer/Json/JsonFile.php +++ b/src/Composer/Json/JsonFile.php @@ -117,7 +117,21 @@ class JsonFile ); } } - file_put_contents($this->path, static::encode($hash, $options). ($options & self::JSON_PRETTY_PRINT ? "\n" : '')); + + $retries = 3; + while ($retries--) { + try { + file_put_contents($this->path, static::encode($hash, $options). ($options & self::JSON_PRETTY_PRINT ? "\n" : '')); + break; + } catch (\Exception $e) { + if ($retries) { + usleep(500000); + continue; + } + + throw $e; + } + } } /**