Skip to content

Commit

Permalink
Making FileEngine emit errors when a path does not exist but is used …
Browse files Browse the repository at this point in the history
…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 fbf054b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
24 changes: 7 additions & 17 deletions cake/libs/cache/file.php
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;
}
Expand Down
18 changes: 18 additions & 0 deletions cake/tests/cases/libs/cache/file.test.php
Expand Up @@ -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.