Making FileEngine emit errors when a path does not exist but is used for caching. Should make cryptic errors coming from Cache easier to figure out. Removed useless private property.

Tests added.
Fixes #384
This commit is contained in:
Mark Story 2010-02-22 23:21:30 -05:00
parent b1a3e05374
commit fbf054b22b
2 changed files with 25 additions and 17 deletions

View file

@ -19,6 +19,9 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
if (!class_exists('File')) {
require LIBS . 'file.php';
}
/**
* File Storage engine for cache
*
@ -50,14 +53,6 @@ class FileEngine extends CacheEngine {
*/
var $settings = array();
/**
* Set to true if FileEngine::init(); and FileEngine::__active(); do not fail.
*
* @var boolean
* @access private
*/
var $__active = false;
/**
* True unless FileEngine::__active(); fails
*
@ -85,9 +80,6 @@ class FileEngine extends CacheEngine {
$settings
));
if (!isset($this->__File)) {
if (!class_exists('File')) {
require LIBS . 'file.php';
}
$this->__File =& new File($this->settings['path'] . DS . 'cake');
}
@ -95,9 +87,9 @@ class FileEngine extends CacheEngine {
$this->settings['isWindows'] = true;
}
$this->settings['path'] = $this->__File->Folder->cd($this->settings['path']);
if (empty($this->settings['path'])) {
return false;
$path = $this->__File->Folder->cd($this->settings['path']);
if ($path) {
$this->settings['path'] = $path;
}
return $this->__active();
}
@ -266,11 +258,9 @@ class FileEngine extends CacheEngine {
* @access private
*/
function __active() {
if (!$this->__active && $this->__init && !is_writable($this->settings['path'])) {
if ($this->__init && !is_writable($this->settings['path'])) {
$this->__init = false;
trigger_error(sprintf(__('%s is not writable', true), $this->settings['path']), E_USER_WARNING);
} else {
$this->__active = true;
}
return true;
}

View file

@ -355,5 +355,23 @@ class FileEngineTest extends CakeTestCase {
Cache::write('App.singleQuoteTest', "'this is a quoted string'");
$this->assertIdentical(Cache::read('App.singleQuoteTest'), "'this is a quoted string'");
}
/**
* check that FileEngine generates an error when a configured Path does not exist.
*
* @return void
*/
function testErrorWhenPathDoesNotExist() {
if ($this->skipIf(is_dir(TMP . 'tests' . DS . 'file_failure'), 'Cannot run test directory exists. %s')) {
return;
}
$this->expectError();
Cache::config('failure', array(
'engine' => 'File',
'path' => TMP . 'tests' . DS . 'file_failure'
));
Cache::drop('failure');
}
}
?>