diff --git a/CHANGELOG.md b/CHANGELOG.md index f475d14a..5a3c9625 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ All notable changes to this project will be documented in this file, in reverse ### Added -- Nothing. +- [#9](https://github.com/laminas/laminas-modulemanager/pull/9) adds [webimpress/safe-writer](https://github.com/webimpress/safe-writer) for saving cache files safely to avoid race conditions when the same file is written multiple times in a short time period. ### Changed diff --git a/composer.json b/composer.json index c3f609a7..4d1ca6b2 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,8 @@ "laminas/laminas-config": "^3.1 || ^2.6", "laminas/laminas-eventmanager": "^3.2 || ^2.6.3", "laminas/laminas-stdlib": "^3.1 || ^2.7", - "laminas/laminas-zendframework-bridge": "^1.0" + "laminas/laminas-zendframework-bridge": "^1.0", + "webimpress/safe-writer": "^1.0.2 || ^2.1" }, "require-dev": { "laminas/laminas-coding-standard": "~1.0.0", diff --git a/src/Listener/AbstractListener.php b/src/Listener/AbstractListener.php index 6989b004..9be65c72 100644 --- a/src/Listener/AbstractListener.php +++ b/src/Listener/AbstractListener.php @@ -8,6 +8,8 @@ namespace Laminas\ModuleManager\Listener; +use Webimpress\SafeWriter\FileWriter; + /** * Abstract listener */ @@ -60,17 +62,8 @@ public function setOptions(ListenerOptions $options) */ protected function writeArrayToFile($filePath, $array) { - // Write cache file to temporary file first and then rename it. - // We don't want cache file to be read when it is not written completely. - // include/require functions require additional lock, see: - // https://bugs.php.net/bug.php?id=52895 - $tmp = tempnam(sys_get_temp_dir(), md5($filePath)); - $content = "