From 91976f7d562b65c77705820a26410e1e6ac95e2f Mon Sep 17 00:00:00 2001 From: Dag Date: Sat, 8 Jul 2023 17:06:49 +0200 Subject: [PATCH] fix(file cache): acquire lock before writing (#3509) --- caches/FileCache.php | 6 +++--- lib/Logger.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/caches/FileCache.php b/caches/FileCache.php index 3447aa76..a4f48962 100644 --- a/caches/FileCache.php +++ b/caches/FileCache.php @@ -41,9 +41,9 @@ class FileCache implements CacheInterface public function saveData($data): void { - $writeStream = file_put_contents($this->getCacheFile(), serialize($data)); - if ($writeStream === false) { - throw new \Exception('The cache path is not writeable. You probably want: chown www-data:www-data cache'); + $bytes = file_put_contents($this->getCacheFile(), serialize($data), LOCK_EX); + if ($bytes === false) { + throw new \Exception(sprintf('Failed to write to: %s', $this->getCacheFile())); } } diff --git a/lib/Logger.php b/lib/Logger.php index 22553dce..b97de978 100644 --- a/lib/Logger.php +++ b/lib/Logger.php @@ -77,6 +77,6 @@ final class Logger // Log to file // todo: extract to log handler - //file_put_contents('/tmp/rss-bridge.log', $text, FILE_APPEND); + // file_put_contents('/tmp/rss-bridge.log', $text, FILE_APPEND | LOCK_EX); } }