Fixing recursive directory creation when nested create() calls fail. Fixes #347

This commit is contained in:
Mark Story 2010-02-20 11:25:46 -05:00
parent f4c670e5be
commit 763aa524b9
2 changed files with 43 additions and 1 deletions

View file

@ -473,7 +473,7 @@ class Folder extends Object {
}
}
}
return true;
return false;
}
/**
* Returns the size in bytes of this Folder.

View file

@ -82,6 +82,48 @@ class FolderTest extends CakeTestCase {
$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
*