Home » Networking » Net_FTP » Bug #5895
Recursive chmod ends in endless loop
Details
| Submitted | 2005-11-08 13:22 UTC |
|---|---|
| From | sasha_k at techs dot com dot ua |
| Assigned | toby |
| Status | Closed |
| Package | Net_FTP |
| PHP Version | 4.4.1 |
| Roadmaps | (Not assigned) |
Comments
[2005-11-08 13:22 UTC] sasha_k at techs dot com dot ua
Description:
------------
The problem is as "Bug #4969 Recursive rm ends in endless loop" in "chmode_recursive" too.
was:
------------------------------------
function chmodRecursive($target, $permissions)
{
static $dir_permissions;
if(!isset($dir_permissions)){ // Making directory specific permissions
$dir_permissions = $this->_makeDirPermissions($permissions);
}
// If $target is an array: Loop through it
if (is_array($target)) {
for ($i = 0; $i < count($target); $i++) {
$res = $this->chmodRecursive($target[$i], $permissions);
if (PEAR::isError($res)) {
return $res;
} // end if isError
} // end for i < count($target)
} else {
$remote_path = $this->_construct_path($target);
// Chmod the directory itself
$result = $this->chmod($remote_path, $dir_permissions);
if (PEAR::isError($result)) {
return $result;
}
// If $remote_path last character is not a slash, add one
if (substr($remote_path, strlen($remote_path)-1) != "/") {
$remote_path .= "/";
}
$dir_list = array();
$mode = NET_FTP_DIRS_ONLY;
$dir_list = $this->ls($remote_path, $mode);
foreach ($dir_list as $dir_entry) {
$remote_path_new = $remote_path.$dir_entry["name"]."/";
// Chmod the directory we're about to enter
$result = $this->chmod($remote_path_new, $dir_permissions);
if (PEAR::isError($result)) {
return $result;
}
$result = $this->chmodRecursive($remote_path_new, $permissions);
if (PEAR::isError($result)) {
return $result;
}
} // end foreach dir_list as dir_entry
$file_list = array();
$mode = NET_FTP_FILES_ONLY;
$file_list = $this->ls($remote_path, $mode);
foreach ($file_list as $file_entry) {
$remote_file = $remote_path.$file_entry["name"];
$result = $this->chmod($remote_file, $permissions);
if (PEAR::isError($result)) {
return $result;
}
} // end foreach $file_list
} // end if is_array
return true; // No errors
} // end method chmodRecursive
------------------------------------
patch:
------------------------------------
function chmodRecursive($target, $permissions)
{
static $dir_permissions;
if(!isset($dir_permissions)){ // Making directory specific permissions
$dir_permissions = $this->_makeDirPermissions($permissions);
}
// If $target is an array: Loop through it
if (is_array($target)) {
for ($i = 0; $i < count($target); $i++) {
$res = $this->chmodRecursive($target[$i], $permissions);
if (PEAR::isError($res)) {
return $res;
} // end if isError
} // end for i < count($target)
} else {
$remote_path = $this->_construct_path($target);
// Chmod the directory itself
$result = $this->chmod($remote_path, $dir_permissions);
if (PEAR::isError($result)) {
return $result;
}
// If $remote_path last character is not a slash, add one
if (substr($remote_path, strlen($remote_path)-1) != "/") {
$remote_path .= "/";
}
$dir_list = array();
$mode = NET_FTP_DIRS_ONLY;
$dir_list = $this->ls($remote_path, $mode);
foreach ($dir_list as $dir_entry) {
if (($dir_entry["name"] != '.') && ($dir_entry["name"] != '..')) {
$remote_path_new = $remote_path.$dir_entry["name"]."/";
// Chmod the directory we're about to enter
$result = $this->chmod($remote_path_new, $dir_permissions);
if (PEAR::isError($result)) {
return $result;
}
$result = $this->chmodRecursive($remote_path_new, $permissions);
if (PEAR::isError($result)) {
return $result;
}
}
} // end foreach dir_list as dir_entry
$file_list = array();
$mode = NET_FTP_FILES_ONLY;
$file_list = $this->ls($remote_path, $mode);
foreach ($file_list as $file_entry) {
$remote_file = $remote_path.$file_entry["name"];
$result = $this->chmod($remote_file, $permissions);
if (PEAR::isError($result)) {
return $result;
}
} // end foreach $file_list
} // end if is_array
return true; // No errors
} // end method chmodRecursive
------------------------------------