Race condition during file write and parallel read. #861

This commit is contained in:
wunderfeyd 2023-04-20 06:36:55 +02:00 committed by GitHub
parent bb8d51e9f4
commit 18c683f1f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,7 +2,7 @@
// Core extension, https://github.com/annaesvensson/yellow-core
class YellowCore {
const VERSION = "0.8.108";
const VERSION = "0.8.109";
const RELEASE = "0.8.22";
public $content; // content files
public $media; // media files
@ -1974,8 +1974,11 @@ class YellowToolbox {
$fileHandle = @fopen($fileName, "rb");
if ($fileHandle) {
clearstatcache(true, $fileName);
$fileSize = $sizeMax ? $sizeMax : filesize($fileName);
if ($fileSize) $fileData = fread($fileHandle, $fileSize);
if (flock($fileHandle, LOCK_SH)) {
$fileSize = $sizeMax ? $sizeMax : filesize($fileName);
if ($fileSize) $fileData = fread($fileHandle, $fileSize);
flock($fileHandle, LOCK_UN);
}
fclose($fileHandle);
}
return $fileData;
@ -1988,7 +1991,7 @@ class YellowToolbox {
$path = dirname($fileName);
if (!is_string_empty($path) && !is_dir($path)) @mkdir($path, 0777, true);
}
$fileHandle = @fopen($fileName, "wb");
$fileHandle = @fopen($fileName, "cb");
if ($fileHandle) {
clearstatcache(true, $fileName);
if (flock($fileHandle, LOCK_EX)) {