8000 [Cache] Fix locking on Solaris by nicolas-grekas · Pull Request #27670 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Cache] Fix locking on Solaris #27670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Cache] Fix locking on Solaris
  • Loading branch information
nicolas-grekas committed Jun 21, 2018
commit 43da583267deb4f10f45ceacad3b6056c872bb1d
21 changes: 14 additions & 7 deletions src/Symfony/Component/Cache/LockRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ public static function setFiles(array $files): array
8000 $previousFiles = self::$files;
self::$files = $files;

foreach (self::$openedFiles as $k => $file) {
flock($file, LOCK_UN);
fclose($file);
foreach (self::$openedFiles as $file) {
if ($file) {
flock($file, LOCK_UN);
fclose($file);
}
}
self::$openedFiles = self::$lockedFiles = array();

Expand Down Expand Up @@ -112,19 +114,24 @@ function (CacheItemPoolInterface $pool, CacheItemInterface $item, $value, float
flock($lock, LOCK_SH);
} finally {
flock($lock, LOCK_UN);
self::$lockedFiles[$key] = false;
unset(self::$lockedFiles[$key]);
}

return false;
}

private static function open(int $key)
{
if ($h = self::$openedFiles[$key] ?? null) {
if (null !== $h = self::$openedFiles[$key] ?? null) {
return $h;
}
if ($h = fopen(self::$files[$key], 'rb')) {
return self::$openedFiles[$key] = $h;
set_error_handler(function () {});
try {
$h = fopen(self::$files[$key], 'r+');
} finally {
restore_error_handler();
}

self::$openedFiles[$key] = $h ?: @fopen(self::$files[$key], 'r');
}
}
0