Home » Networking » Net_FTP » Bug #7270
rm_dir recursive
Details
| Submitted | 2006-03-31 12:47 UTC |
|---|---|
| From | fabio dot esposito at gmail dot com |
| Assigned | jorrit |
| Status | Closed |
| Package | Net_FTP |
| PHP Version | 4.3.11 |
| OS | Linux |
| Roadmaps | 1.3.3 |
Comments
[2006-03-31 12:47 UTC] fabio dot esposito at gmail dot com
Description:
------------
When we try to remove recursively a dir on a unix server this error appear: "Uninitialized string offset: 0" (on windows it works)
Test script:
---------------
We change your _rm_dir_recursive function as below
(see "/**/" comments) and now the code works on any plataform
function _rm_dir_recursive($dir)
{
if (substr($dir, (strlen($dir) - 1), 1) != "/") {
return $this->raiseError("Directory name '$dir' is invalid, has to end with '/'", NET_FTP_ERR_REMOTEPATHNODIR);
}
$file_list = $this->_ls_files($dir);
foreach ($file_list as $file) {
$file = $dir.$file["name"];
$res = $this->rm($file);
if ($this->isError($res)) {
return $res;
}
}
$dir_list = $this->_ls_dirs($dir);
foreach ($dir_list as $new_dir) {
/**
*
in past the test isn't the position 'name' of the array but the entire array and the loop never ends. now works fine
*
**/
if ($new_dir['name'] == '.' || $new_dir['name'] == '..') {
continue;
}
$new_dir = $dir.$new_dir["name"]."/";
//echo $new_dir."<br/>";
$res = $this->_rm_dir_recursive($new_dir);
if ($this->isError($res)) {
return $res;
}
}
$res = $this->_rm_dir($dir);
if (PEAR::isError($res)) {
return $res;
} else {
return true;
}
}
Expected result:
----------------
remove recursively a directory
Actual result:
--------------
with the patch the script works fine