Quellcode durchsuchen

Retry json file writing 3 times before failing, fixes #2286

Jordi Boggiano vor 11 Jahren
Ursprung
Commit
46e82cb38d
1 geänderte Dateien mit 15 neuen und 1 gelöschten Zeilen
  1. 15 1
      src/Composer/Json/JsonFile.php

+ 15 - 1
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;
+            }
+        }
     }
 
     /**