Skip to content

Commit 142c726

Browse files
committed
do not ignore flock() return values for PHP 8.5 compat
1 parent 75d9991 commit 142c726

File tree

7 files changed

+6
-21
lines changed

7 files changed

+6
-21
lines changed

Diff for: src/Symfony/Component/Cache/LockRegistry.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ public static function setFiles(array $files): array
7474

7575
foreach (self::$openedFiles as $file) {
7676
if ($file) {
77-
flock($file, \LOCK_UN);
7877
fclose($file);
7978
}
8079
}
@@ -123,9 +122,9 @@ public static function compute(callable $callback, ItemInterface $item, bool &$s
123122
}
124123
// if we failed the race, retry locking in blocking mode to wait for the winner
125124
$logger?->info('Item "{key}" is locked, waiting for it to be released', ['key' => $item->getKey()]);
126-
flock($lock, \LOCK_SH);
125+
(bool) flock($lock, \LOCK_SH);
127126
} finally {
128-
flock($lock, \LOCK_UN);
127+
fclose($lock);
129128
unset(self::$lockedFiles[$key]);
130129
}
131130

Diff for: src/Symfony/Component/HttpKernel/HttpCache/Store.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ public function cleanup()
6262
{
6363
// unlock everything
6464
foreach ($this->locks as $lock) {
65-
flock($lock, \LOCK_UN);
6665
fclose($lock);
6766
}
6867

@@ -106,7 +105,6 @@ public function unlock(Request $request): bool
106105
$key = $this->getCacheKey($request);
107106

108107
if (isset($this->locks[$key])) {
109-
flock($this->locks[$key], \LOCK_UN);
110108
fclose($this->locks[$key]);
111109
unset($this->locks[$key]);
112110

@@ -129,8 +127,7 @@ public function isLocked(Request $request): bool
129127
}
130128

131129
$h = fopen($path, 'r');
132-
flock($h, \LOCK_EX | \LOCK_NB, $wouldBlock);
133-
flock($h, \LOCK_UN); // release the lock we just acquired
130+
flock($h, \LOCK_EX | \LOCK_NB, $wouldBlock) && flock($h, \LOCK_UN); // release the lock we just acquired
134131
fclose($h);
135132

136133
return (bool) $wouldBlock;
@@ -340,7 +337,6 @@ private function doPurge(string $url): bool
340337
{
341338
$key = $this->getCacheKey(Request::create($url));
342339
if (isset($this->locks[$key])) {
343-
flock($this->locks[$key], \LOCK_UN);
344340
fclose($this->locks[$key]);
345341
unset($this->locks[$key]);
346342
}

Diff for: src/Symfony/Component/HttpKernel/Kernel.php

-2
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,6 @@ protected function initializeContainer()
435435
} elseif (!is_file($cachePath) || !\is_object($this->container = include $cachePath)) {
436436
$this->container = null;
437437
} elseif (!$oldContainer || $this->container::class !== $oldContainer->name) {
438-
flock($lock, \LOCK_UN);
439438
fclose($lock);
440439
$this->container->set('kernel', $this);
441440

@@ -517,7 +516,6 @@ protected function initializeContainer()
517516
$this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass());
518517

519518
if ($lock) {
520-
flock($lock, \LOCK_UN);
521519
fclose($lock);
522520
}
523521

Diff for: src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,8 @@ private function doRead($token, ?Profile $profile = null): ?Profile
307307
}
308308

309309
$h = fopen($file, 'r');
310-
flock($h, \LOCK_SH);
310+
(bool) flock($h, \LOCK_SH);
311311
$data = stream_get_contents($h);
312-
flock($h, \LOCK_UN);
313312
fclose($h);
314313

315314
if (\function_exists('gzdecode')) {

Diff for: src/Symfony/Component/Lock/Store/FlockStore.php

-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ public function delete(Key $key)
152152

153153
$handle = $key->getState(__CLASS__)[1];
154154

155-
flock($handle, \LOCK_UN | \LOCK_NB);
156155
fclose($handle);
157156

158157
$key->removeState(__CLASS__);

Diff for: src/Symfony/Component/Process/Pipes/WindowsPipes.php

-4
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,11 @@ public function __construct(mixed $input, bool $haveReadSupport)
6666
continue 2;
6767
}
6868
if (isset($this->lockHandles[$pipe])) {
69-
flock($this->lockHandles[$pipe], \LOCK_UN);
7069
fclose($this->lockHandles[$pipe]);
7170
}
7271
$this->lockHandles[$pipe] = $h;
7372

7473
if (!($h = fopen($file, 'w')) || !fclose($h) || !$h = fopen($file, 'r')) {
75-
flock($this->lockHandles[$pipe], \LOCK_UN);
7674
fclose($this->lockHandles[$pipe]);
7775
unset($this->lockHandles[$pipe]);
7876
continue 2;
@@ -153,7 +151,6 @@ public function readAndWrite(bool $blocking, bool $close = false): array
153151
if ($close) {
154152
ftruncate($fileHandle, 0);
155153
fclose($fileHandle);
156-
flock($this->lockHandles[$type], \LOCK_UN);
157154
fclose($this->lockHandles[$type]);
158155
unset($this->fileHandles[$type], $this->lockHandles[$type]);
159156
}
@@ -178,7 +175,6 @@ public function close(): void
178175
foreach ($this->fileHandles as $type => $handle) {
179176
ftruncate($handle, 0);
180177
fclose($handle);
181-
flock($this->lockHandles[$type], \LOCK_UN);
182178
fclose($this->lockHandles[$type]);
183179
}
184180
$this->fileHandles = $this->lockHandles = [];

Diff for: src/Symfony/Component/Process/Tests/ProcessTest.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,10 @@ public function testIncrementalOutput($getOutput, $getIncrementalOutput, $uri)
413413
{
414414
$lock = tempnam(sys_get_temp_dir(), __FUNCTION__);
415415

416-
$p = $this->getProcessForCode('file_put_contents($s = \''.$uri.'\', \'foo\'); flock(fopen('.var_export($lock, true).', \'r\'), LOCK_EX); file_put_contents($s, \'bar\');');
416+
$p = $this->getProcessForCode('file_put_contents($s = \''.$uri.'\', \'foo\'); (bool) flock(fopen('.var_export($lock, true).', \'r\'), LOCK_EX); file_put_contents($s, \'bar\');');
417417

418418
$h = fopen($lock, 'w');
419-
flock($h, \LOCK_EX);
419+
(bool) flock($h, \LOCK_EX);
420420

421421
$p->start();
422422

@@ -427,8 +427,6 @@ public function testIncrementalOutput($getOutput, $getIncrementalOutput, $uri)
427427

428428
$this->assertSame($s, $p->$getIncrementalOutput());
429429
$this->assertSame('', $p->$getIncrementalOutput());
430-
431-
flock($h, \LOCK_UN);
432430
}
433431

434432
fclose($h);

0 commit comments

Comments
 (0)