Commit 9cbf4d8d by Carsten Brandt

Merge pull request #4091 from resurtm/4080-file-helper-remove-directory-symlinks

Fix possibility of non-removed symlinked directory.
parents 06f27758 9bc8c330
......@@ -277,32 +277,29 @@ class BaseFileHelper
*/
public static function removeDirectory($dir, $options = [])
{
if (!isset($options['traverseSymlinks'])) {
$options['traverseSymlinks'] = false;
}
if (!is_dir($dir) || !($handle = opendir($dir))) {
if (!is_dir($dir)) {
return;
}
while (($file = readdir($handle)) !== false) {
if ($file === '.' || $file === '..') {
continue;
if (!is_link($dir) || isset($options['traverseSymlinks']) && $options['traverseSymlinks']) {
if (!($handle = opendir($dir))) {
return;
}
$path = $dir . DIRECTORY_SEPARATOR . $file;
if (is_link($path)) {
if ($options['traverseSymlinks'] && is_dir($path)) {
static::removeDirectory($path, $options);
while (($file = readdir($handle)) !== false) {
if ($file === '.' || $file === '..') {
continue;
}
unlink($path);
} else {
if (is_file($path)) {
unlink($path);
} else {
$path = $dir . DIRECTORY_SEPARATOR . $file;
if (is_dir($path)) {
static::removeDirectory($path, $options);
} else {
unlink($path);
}
}
closedir($handle);
}
closedir($handle);
if (!is_link($dir)) {
if (is_link($dir)) {
unlink($dir);
} else {
rmdir($dir);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment