[Cache] Fix locking on Solaris

This commit is contained in:
Nicolas Grekas 2018-06-21 11:23:42 +02:00
parent 92c37b9711
commit 43da583267

View File

@ -64,9 +64,11 @@ class LockRegistry
$previousFiles = self::$files; $previousFiles = self::$files;
self::$files = $files; self::$files = $files;
foreach (self::$openedFiles as $k => $file) { foreach (self::$openedFiles as $file) {
flock($file, LOCK_UN); if ($file) {
fclose($file); flock($file, LOCK_UN);
fclose($file);
}
} }
self::$openedFiles = self::$lockedFiles = array(); self::$openedFiles = self::$lockedFiles = array();
@ -112,7 +114,7 @@ class LockRegistry
flock($lock, LOCK_SH); flock($lock, LOCK_SH);
} finally { } finally {
flock($lock, LOCK_UN); flock($lock, LOCK_UN);
self::$lockedFiles[$key] = false; unset(self::$lockedFiles[$key]);
} }
return false; return false;
@ -120,11 +122,16 @@ class LockRegistry
private static function open(int $key) private static function open(int $key)
{ {
if ($h = self::$openedFiles[$key] ?? null) { if (null !== $h = self::$openedFiles[$key] ?? null) {
return $h; return $h;
} }
if ($h = fopen(self::$files[$key], 'rb')) { set_error_handler(function () {});
return self::$openedFiles[$key] = $h; try {
$h = fopen(self::$files[$key], 'r+');
} finally {
restore_error_handler();
} }
self::$openedFiles[$key] = $h ?: @fopen(self::$files[$key], 'r');
} }
} }