Permalink
Browse files

Fixing recursive directory creation when nested create() calls fail. F…

…ixes #347
  • Loading branch information...
markstory committed Feb 20, 2010
1 parent f4c670e commit 763aa524b95f666d1a20d7e58b896f39d830dbd0
Showing with 43 additions and 1 deletion.
  1. +1 −1 cake/libs/folder.php
  2. +42 −0 cake/tests/cases/libs/folder.test.php
View
@@ -473,7 +473,7 @@ function create($pathname, $mode = false) {
}
}
}
- return true;
+ return false;
}
/**
* Returns the size in bytes of this Folder.
@@ -82,6 +82,48 @@ function testInPath() {
$result = $Folder->inPath(DS . 'non-existing' . $inside);
$this->assertFalse($result);
}
+
+/**
+ * test creation of single and mulitple paths.
+ *
+ * @return void
+ */
+ function testCreation() {
+ $folder =& new Folder(TMP . 'tests');
+ $result = $folder->create(TMP . 'tests' . DS . 'first' . DS . 'second' . DS . 'third');
+ $this->assertTrue($result);
+
+ rmdir(TMP . 'tests' . DS . 'first' . DS . 'second' . DS . 'third');
+ rmdir(TMP . 'tests' . DS . 'first' . DS . 'second');
+ rmdir(TMP . 'tests' . DS . 'first');
+
+ $folder =& new Folder(TMP . 'tests');
+ $result = $folder->create(TMP . 'tests' . DS . 'first');
+ $this->assertTrue($result);
+ rmdir(TMP . 'tests' . DS . 'first');
+ }
+/**
+ * test recurisve directory create failure.
+ *
+ * @return void
+ */
+ function testRecursiveCreateFailure() {
+ if ($this->skipIf(DS == '\\', 'Cant perform operations using permissions on windows. %s')) {
+ return;
+ }
+ $path = TMP . 'tests' . DS . 'one';
+ mkdir($path);
+ chmod($path, '0444');
+
+ $this->expectError();
+
+ $folder =& new Folder($path);
+ $result = $folder->create($path . DS . 'two' . DS . 'three');
+ $this->assertFalse($result);
+
+ chmod($path, '0777');
+ rmdir($path);
+ }
/**
* testOperations method
*

0 comments on commit 763aa52

Please sign in to comment.