Skip to content

Commit 9f77525

Browse files
committed
Increase handler robustness
1 parent de9f474 commit 9f77525

1 file changed

Lines changed: 9 additions & 27 deletions

File tree

system/Cache/Handlers/FileHandler.php

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -285,35 +285,13 @@ public function getMetaData(string $key)
285285
{
286286
$key = static::validateKey($key, $this->prefix);
287287

288-
if (! is_file($this->path . $key))
288+
if (false === $data = $this->getItem($key))
289289
{
290290
return false; // This will return null in a future release
291291
}
292292

293-
$data = @unserialize(file_get_contents($this->path . $key));
294-
295-
if (! is_array($data) || ! isset($data['ttl']))
296-
{
297-
return false; // This will return null in a future release
298-
}
299-
300-
// Consider expired items as missing
301-
$expire = $data['time'] + $data['ttl'];
302-
303-
// @phpstan-ignore-next-line
304-
if ($data['ttl'] > 0 && time() > $expire)
305-
{
306-
// If the file is still there then remove it
307-
if (is_file($this->path . $key))
308-
{
309-
unlink($this->path . $key);
310-
}
311-
312-
return false; // This will return null in a future release
313-
}
314-
315293
return [
316-
'expire' => $expire,
294+
'expire' => $data['time'] + $data['ttl'],
317295
'mtime' => filemtime($this->path . $key),
318296
'data' => $data['data'],
319297
];
@@ -348,15 +326,19 @@ protected function getItem(string $filename)
348326
return false;
349327
}
350328

351-
$data = unserialize(file_get_contents($this->path . $filename));
329+
$data = @unserialize(file_get_contents($this->path . $filename));
330+
if (! is_array($data) || ! isset($data['ttl']))
331+
{
332+
return false;
333+
}
352334

353335
// @phpstan-ignore-next-line
354336
if ($data['ttl'] > 0 && time() > $data['time'] + $data['ttl'])
355337
{
356-
// If the file is still there then remove it
338+
// If the file is still there then try to remove it
357339
if (is_file($this->path . $filename))
358340
{
359-
unlink($this->path . $filename);
341+
@unlink($this->path . $filename);
360342
}
361343

362344
return false;

0 commit comments

Comments
 (0)