Skip to content

Commit

Permalink
Fixing recursive directory creation when nested create() calls fail. F…
Browse files Browse the repository at this point in the history
…ixes #347
  • Loading branch information
markstory committed Feb 20, 2010
1 parent f4c670e commit 763aa52
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cake/libs/folder.php
Expand Up @@ -473,7 +473,7 @@ function create($pathname, $mode = false) {
}
}
}
return true;
return false;
}
/**
* Returns the size in bytes of this Folder.
Expand Down
42 changes: 42 additions & 0 deletions cake/tests/cases/libs/folder.test.php
Expand Up @@ -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
*
Expand Down

0 comments on commit 763aa52

Please sign in to comment.