fixing Folder->chmod() to take account files in subfolders as well when the recursive option is set; adding tests to prove the fix; fixes #5392

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7574 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
DarkAngelBGE 2008-09-09 04:34:11 +00:00
parent 7e55088b77
commit 8346bba694
2 changed files with 48 additions and 19 deletions

View file

@ -353,7 +353,7 @@ class Folder extends Object {
}
}
/**
* Change the mode on a directory structure recursively.
* Change the mode on a directory structure recursively. This includes changing the mode on files as well.
*
* @param string $path The path to chmod
* @param integer $mode octal value 0755
@ -371,29 +371,32 @@ class Folder extends Object {
if (@chmod($path, intval($mode, 8))) {
$this->__messages[] = sprintf(__('%s changed to %s', true), $path, $mode);
return true;
} else {
$this->__errors[] = sprintf(__('%s NOT changed to %s', true), $path, $mode);
return false;
}
$this->__errors[] = sprintf(__('%s NOT changed to %s', true), $path, $mode);
return false;
}
if (is_dir($path)) {
list($paths) = $this->tree($path);
$paths = $this->tree($path);
foreach ($paths as $key => $fullpath) {
$check = explode(DS, $fullpath);
$count = count($check);
foreach ($paths as $type) {
foreach ($type as $key => $fullpath) {
$check = explode(DS, $fullpath);
$count = count($check);
if (in_array($check[$count - 1], $exceptions)) {
continue;
}
if (in_array($check[$count - 1], $exceptions)) {
continue;
}
if (@chmod($fullpath, intval($mode, 8))) {
$this->__messages[] = sprintf(__('%s changed to %s', true), $fullpath, $mode);
} else {
$this->__errors[] = sprintf(__('%s NOT changed to %s', true), $fullpath, $mode);
if (@chmod($fullpath, intval($mode, 8))) {
$this->__messages[] = sprintf(__('%s changed to %s', true), $fullpath, $mode);
} else {
$this->__errors[] = sprintf(__('%s NOT changed to %s', true), $fullpath, $mode);
}
}
}
if (empty($this->__errors)) {
return true;
}
@ -419,12 +422,12 @@ class Folder extends Object {
if ($exceptions == false) {
$exceptions = true;
}
while (count($this->__directories)) {
$dir = array_pop($this->__directories);
$this->__tree($dir, $exceptions);
array_push($directories, $dir);
}
if ($type === null) {
return array($directories, $this->__files);
}

View file

@ -96,7 +96,7 @@ class FolderTest extends CakeTestCase {
* @return void
*/
function testOperations() {
$path = TEST_CAKE_CORE_INCLUDE_PATH.'console'.DS.'libs'.DS.'templates'.DS.'skel';
$path = TEST_CAKE_CORE_INCLUDE_PATH . 'console' . DS . 'libs' . DS . 'templates' . DS . 'skel';
$Folder =& new Folder($path);
$result = is_dir($Folder->pwd());
@ -152,6 +152,33 @@ class FolderTest extends CakeTestCase {
$result = $Folder->pwd();
$this->assertNull($result);
}
/**
* testChmod method
*
* @return void
* @access public
*/
function testChmod() {
$path = TEST_CAKE_CORE_INCLUDE_PATH . 'console' . DS . 'libs' . DS . 'templates' . DS . 'skel';
$Folder =& new Folder($path);
$subdir = 'test_folder_new';
$new = TMP . $subdir;
$this->assertTrue($Folder->create($new));
$this->assertTrue($Folder->create($new . DS . 'test1'));
$this->assertTrue($Folder->create($new . DS . 'test2'));
$filePath = $new . DS . 'test1.php';
$File =& new File($filePath);
$this->assertTrue($File->create());
$copy = TMP . 'test_folder_copy';
$this->assertTrue($Folder->chmod($new, 0777, true));
$this->assertEqual($File->perms(), '0777');
$Folder->delete($new);
}
/**
* testRealPathForWebroot method
*
@ -171,8 +198,7 @@ class FolderTest extends CakeTestCase {
function testZeroAsDirectory() {
$Folder =& new Folder(TMP);
$new = TMP . '0';
$result = $Folder->create($new);
$this->assertTrue($result);
$this->assertTrue($Folder->create($new));
$result = $Folder->read(true, true);
$expected = array(array('0', 'cache', 'logs', 'sessions', 'tests'), array());