From f5859ca7193dcd82433fb0f617d64b1fbd380801 Mon Sep 17 00:00:00 2001 From: euromark Date: Wed, 7 Aug 2013 13:24:45 +0200 Subject: [PATCH] allow creating of missing tmp directories in debug (development) mode for cache and log to avoid unnecessary errors thrown - using 0775 for dirs and 0664 for files --- lib/Cake/Cache/Engine/FileEngine.php | 8 +++++++- lib/Cake/Log/Engine/FileLog.php | 4 ++++ lib/Cake/Test/Case/Cache/CacheTest.php | 6 ++++++ lib/Cake/Test/Case/Cache/Engine/FileEngineTest.php | 13 ++++++------- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/lib/Cake/Cache/Engine/FileEngine.php b/lib/Cake/Cache/Engine/FileEngine.php index d32f65191..f63821f8f 100644 --- a/lib/Cake/Cache/Engine/FileEngine.php +++ b/lib/Cake/Cache/Engine/FileEngine.php @@ -299,7 +299,7 @@ class FileEngine extends CacheEngine { $dir = $this->settings['path'] . $groups; if (!is_dir($dir)) { - mkdir($dir, 0777, true); + mkdir($dir, 0775, true); } $path = new SplFileInfo($dir . $key); @@ -332,6 +332,12 @@ class FileEngine extends CacheEngine { */ protected function _active() { $dir = new SplFileInfo($this->settings['path']); + if (Configure::read('debug')) { + $path = $dir->getPathname(); + if (!is_dir($path)) { + mkdir($path, 0775, true); + } + } if ($this->_init && !($dir->isDir() && $dir->isWritable())) { $this->_init = false; trigger_error(__d('cake_dev', '%s is not writable', $this->settings['path']), E_USER_WARNING); diff --git a/lib/Cake/Log/Engine/FileLog.php b/lib/Cake/Log/Engine/FileLog.php index 489168467..071f12f8d 100644 --- a/lib/Cake/Log/Engine/FileLog.php +++ b/lib/Cake/Log/Engine/FileLog.php @@ -104,6 +104,10 @@ class FileLog extends BaseLog { if (!empty($config['path'])) { $this->_path = $config['path']; } + if (Configure::read('debug') && !is_dir($this->_path)) { + mkdir($this->_path, 0775, true); + } + if (!empty($config['file'])) { $this->_file = $config['file']; if (substr($this->_file, -4) !== '.log') { diff --git a/lib/Cake/Test/Case/Cache/CacheTest.php b/lib/Cake/Test/Case/Cache/CacheTest.php index 8b6cfd2ad..13116c2f7 100644 --- a/lib/Cake/Test/Case/Cache/CacheTest.php +++ b/lib/Cake/Test/Case/Cache/CacheTest.php @@ -132,6 +132,10 @@ class CacheTest extends CakeTestCase { * @return void */ public function testInvalidConfig() { + // In debug mode it would auto create the folder. + $debug = Configure::read('debug'); + Configure::write('debug', 0); + Cache::config('invalid', array( 'engine' => 'File', 'duration' => '+1 year', @@ -141,6 +145,8 @@ class CacheTest extends CakeTestCase { 'random' => 'wii' )); Cache::read('Test', 'invalid'); + + Configure::write('debug', $debug); } /** diff --git a/lib/Cake/Test/Case/Cache/Engine/FileEngineTest.php b/lib/Cake/Test/Case/Cache/Engine/FileEngineTest.php index e57e94212..02903e632 100644 --- a/lib/Cake/Test/Case/Cache/Engine/FileEngineTest.php +++ b/lib/Cake/Test/Case/Cache/Engine/FileEngineTest.php @@ -338,20 +338,19 @@ class FileEngineTest extends CakeTestCase { } /** - * check that FileEngine generates an error when a configured Path does not exist. + * check that FileEngine does not generate an error when a configured Path does not exist in debug mode. * - * @expectedException PHPUnit_Framework_Error_Warning * @return void */ - public function testErrorWhenPathDoesNotExist() { - $this->skipIf(is_dir(TMP . 'tests' . DS . 'file_failure'), 'Cannot run test directory exists.'); + public function testPathDoesNotExist() { + $this->skipIf(is_dir(TMP . 'tests' . DS . 'autocreate'), 'Cannot run if test directory exists.'); - Cache::config('failure', array( + Cache::config('autocreate', array( 'engine' => 'File', - 'path' => TMP . 'tests' . DS . 'file_failure' + 'path' => TMP . 'tests' . DS . 'autocreate' )); - Cache::drop('failure'); + Cache::drop('autocreate'); } /**