diff --git a/system/Cache/Handlers/FileHandler.php b/system/Cache/Handlers/FileHandler.php index aa7b37125e56..50bd14ca242d 100644 --- a/system/Cache/Handlers/FileHandler.php +++ b/system/Cache/Handlers/FileHandler.php @@ -59,7 +59,7 @@ class FileHandler implements CacheInterface public function __construct($config) { $this->prefix = $config->prefix ?: ''; - $this->path = ! empty($config->path) ? $config->path : WRITEPATH . 'cache'; + $this->path = ! empty($config->storePath) ? $config->storePath : WRITEPATH . 'cache'; $this->path = rtrim($this->path, '/') . '/'; } @@ -322,7 +322,14 @@ protected function getItem(string $key) */ protected function writeFile($path, $data, $mode = 'wb') { - if (($fp = @fopen($path, $mode)) === false) + try + { + if (($fp = @fopen($path, $mode)) === false) + { + return false; + } + } + catch (\ErrorException $e) { return false; } diff --git a/tests/system/Cache/Handlers/FileHandlerTest.php b/tests/system/Cache/Handlers/FileHandlerTest.php index ae9b40237893..9433822a0170 100644 --- a/tests/system/Cache/Handlers/FileHandlerTest.php +++ b/tests/system/Cache/Handlers/FileHandlerTest.php @@ -92,9 +92,8 @@ public function testSave() { $this->assertTrue($this->fileHandler->save(self::$key1, 'value')); - // The FileHandler always ensures the directory is writable... chmod($this->config->storePath, 0444); - $this->assertTrue($this->fileHandler->save(self::$key2, 'value')); + $this->assertFalse($this->fileHandler->save(self::$key2, 'value')); } public function testDelete()