Skip to content

Commit 3c888d9

Browse files
authored
Merge pull request #784 from Geolim4/master
Fixed issues in #782
2 parents fbf42d4 + 51d686e commit 3c888d9

File tree

4 files changed

+20
-18
lines changed

4 files changed

+20
-18
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

lib/Phpfastcache/Drivers/Riak/Driver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function getStats(): DriverStatistic
6060
return (new DriverStatistic())
6161
->setData(implode(', ', array_keys($this->itemInstances)))
6262
->setRawData($info)
63-
->setSize(false)
63+
->setSize(0)
6464
->setInfo('Riak does not provide size/date information att all :(');
6565
}
6666

lib/Phpfastcache/Util/Directory.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,19 @@ public static function rrmdir(string $source, bool $removeOnlyChildren = false):
101101
/**
102102
* @var SplFileInfo $fileinfo
103103
*/
104-
if ($fileinfo->isDir()) {
105-
if (self::rrmdir($fileinfo->getRealPath()) === false) {
106-
return false;
107-
}
108-
} else {
109-
if (unlink($fileinfo->getRealPath()) === false) {
104+
$realpath = $fileinfo->getRealPath();
105+
if($realpath){
106+
if ($fileinfo->isDir()) {
107+
if (self::rrmdir($fileinfo->getRealPath()) === false) {
108+
return false;
109+
}
110+
} elseif (unlink($realpath) === false) {
110111
return false;
111112
}
112113
}
114+
else{
115+
return false;
116+
}
113117
}
114118

115119
if ($removeOnlyChildren === false) {
@@ -148,4 +152,4 @@ public static function getAbsolutePath(string $path): string
148152
$prefix = $__FILE__[0] === DIRECTORY_SEPARATOR ? DIRECTORY_SEPARATOR : '';
149153
return $prefix . implode(DIRECTORY_SEPARATOR, $absolutes);
150154
}
151-
}
155+
}

0 commit comments

Comments
 (0)