Browse Source

Merge pull request #1194 from dereuromark/2.4-file-improvements

Allow creating of missing tmp directories in debug (development) mode
Mark Story 12 years ago
parent
commit
054668f149

+ 7 - 1
lib/Cake/Cache/Engine/FileEngine.php

@@ -326,7 +326,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);
 
@@ -359,6 +359,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);

+ 4 - 0
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') {

+ 6 - 0
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);
 	}
 
 /**

+ 6 - 7
lib/Cake/Test/Case/Cache/Engine/FileEngineTest.php

@@ -373,20 +373,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');
 	}
 
 /**