Skip to content
Permalink
Browse files

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
  • Loading branch information...
markstory committed Feb 23, 2010
1 parent b1a3e05 commit fbf054b22b04e6d8205e3a523afa9d40c74981c7
Showing with 25 additions and 17 deletions.
  1. +7 −17 cake/libs/cache/file.php
  2. +18 −0 cake/tests/cases/libs/cache/file.test.php
@@ -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,19 +80,16 @@ function init($settings = array()) {
$settings
));
if (!isset($this->__File)) {
if (!class_exists('File')) {
require LIBS . 'file.php';
}
$this->__File =& new File($this->settings['path'] . DS . 'cake');
}
if (DIRECTORY_SEPARATOR === '\\') {
$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 @@ function __setKey($key) {
* @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;
}
@@ -355,5 +355,23 @@ function testWriteQuotedString() {
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');
}
}
?>

0 comments on commit fbf054b

Please sign in to comment.
You can’t perform that action at this time.