Skip to content

Commit de344f9

Browse files
committed
Fixed initial issue in #782
1 parent 8d1dd05 commit de344f9

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

lib/Phpfastcache/Core/Pool/IO/IOHelperTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,16 +290,16 @@ protected function encodeFilename($keyword): string
290290
*/
291291
protected function readFile($file): string
292292
{
293+
if (!\is_readable($file)) {
294+
throw new PhpfastcacheIOException("Cannot read file located at: {$file}");
295+
}
293296
if (\function_exists('file_get_contents')) {
294297
return (string)\file_get_contents($file);
295298
}
296299

297300
$string = '';
298301

299302
$file_handle = @\fopen($file, 'rb');
300-
if (!$file_handle) {
301-
throw new PhpfastcacheIOException("Cannot read file located at: {$file}");
302-
}
303303
while (!\feof($file_handle)) {
304304
$line = \fgets($file_handle);
305305
$string .= $line;

lib/Phpfastcache/Drivers/Files/Driver.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use FilesystemIterator;
2121
use Phpfastcache\Cluster\AggregatablePoolInterface;
2222
use Phpfastcache\Core\Pool\{DriverBaseTrait, ExtendedCacheItemPoolInterface, IO\IOHelperTrait};
23-
use Phpfastcache\Exceptions\{PhpfastcacheInvalidArgumentException};
23+
use Phpfastcache\Exceptions\{PhpfastcacheInvalidArgumentException, PhpfastcacheIOException};
2424
use Phpfastcache\Util\Directory;
2525
use Psr\Cache\CacheItemInterface;
2626

@@ -74,16 +74,14 @@ protected function driverConnect(): bool
7474
*/
7575
protected function driverRead(CacheItemInterface $item)
7676
{
77-
/**
78-
* Check for Cross-Driver type confusion
79-
*/
8077
$file_path = $this->getFilePath($item->getKey(), true);
81-
if (!\file_exists($file_path)) {
78+
79+
try{
80+
$content = $this->readFile($file_path);
81+
}catch (PhpfastcacheIOException $e){
8282
return null;
8383
}
8484

85-
$content = $this->readFile($file_path);
86-
8785
return $this->decode($content);
8886
}
8987

0 commit comments

Comments
 (0)