Commit 1327d8ad by resurtm

Fix possibility of non-removed symlinked directory.

parent 06f27758
...@@ -277,32 +277,29 @@ class BaseFileHelper ...@@ -277,32 +277,29 @@ class BaseFileHelper
*/ */
public static function removeDirectory($dir, $options = []) public static function removeDirectory($dir, $options = [])
{ {
if (!isset($options['traverseSymlinks'])) { if (!is_dir($dir)) {
$options['traverseSymlinks'] = false;
}
if (!is_dir($dir) || !($handle = opendir($dir))) {
return; return;
} }
while (($file = readdir($handle)) !== false) { if (!is_link($dir) || isset($options['traverseSymlinks']) && $options['traverseSymlinks']) {
if ($file === '.' || $file === '..') { if (!($handle = opendir($dir))) {
continue; return;
} }
$path = $dir . DIRECTORY_SEPARATOR . $file; while (($file = readdir($handle)) !== false) {
if (is_link($path)) { if ($file === '.' || $file === '..') {
if ($options['traverseSymlinks'] && is_dir($path)) { continue;
static::removeDirectory($path, $options);
} }
unlink($path); $path = $dir . DIRECTORY_SEPARATOR . $file;
} else {
if (is_file($path)) { if (is_file($path)) {
unlink($path); unlink($path);
} else { } else {
static::removeDirectory($path, $options); static::removeDirectory($path, $options);
} }
} }
closedir($handle);
} }
closedir($handle); if (is_link($dir)) {
if (!is_link($dir)) { unlink($dir);
} else {
rmdir($dir); 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