fix(file cache): acquire lock before writing (#3509)

This commit is contained in:
Dag 2023-07-08 17:06:49 +02:00 committed by GitHub
parent 8b996e3056
commit 91976f7d56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -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()));
}
}

View File

@ -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);
}
}