Skip to content

Commit 6064cfe

Browse files
bug symfony#27670 [Cache] Fix locking on Solaris (nicolas-grekas)
This PR was merged into the 4.2-dev branch. Discussion ---------- [Cache] Fix locking on Solaris | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - As reported on symfony#27668, the descriptor must be writeable on Solaris to get an exclusive lock. Commits ------- 43da583 [Cache] Fix locking on Solaris
2 parents 31fc855 + 43da583 commit 6064cfe

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/Symfony/Component/Cache/LockRegistry.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,11 @@ public static function setFiles(array $files): array
6464
$previousFiles = self::$files;
6565
self::$files = $files;
6666

67-
foreach (self::$openedFiles as $k => $file) {
68-
flock($file, LOCK_UN);
69-
fclose($file);
67+
foreach (self::$openedFiles as $file) {
68+
if ($file) {
69+
flock($file, LOCK_UN);
70+
fclose($file);
71+
}
7072
}
7173
self::$openedFiles = self::$lockedFiles = array();
7274

@@ -112,19 +114,24 @@ function (CacheItemPoolInterface $pool, CacheItemInterface $item, $value, float
112114
flock($lock, LOCK_SH);
113115
} finally {
114116
flock($lock, LOCK_UN);
115-
self::$lockedFiles[$key] = false;
117+
unset(self::$lockedFiles[$key]);
116118
}
117119

118120
return false;
119121
}
120122

121123
private static function open(int $key)
122124
{
123-
if ($h = self::$openedFiles[$key] ?? null) {
125+
if (null !== $h = self::$openedFiles[$key] ?? null) {
124126
return $h;
125127
}
126-
if ($h = fopen(self::$files[$key], 'rb')) {
127-
return self::$openedFiles[$key] = $h;
128+
set_error_handler(function () {});
129+
try {
130+
$h = fopen(self::$files[$key], 'r+');
131+
} finally {
132+
restore_error_handler();
128133
}
134+
135+
self::$openedFiles[$key] = $h ?: @fopen(self::$files[$key], 'r');
129136
}
130137
}

0 commit comments

Comments
 (0)