Add prevent deleting sub content of linked directories
Sometimes devs may link to library folders elsewhere, then we should prevent traversing and deleting the linked content. Default behavior now is to remove the link and not its content.pull/42/head
parent
e3d7cf2562
commit
dfdfb3bd99
|
@ -2246,9 +2246,23 @@ class H5PCore {
|
||||||
if (!is_dir($dir)) {
|
if (!is_dir($dir)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (is_link($dir)) {
|
||||||
|
// Do not traverse and delete linked content, simply unlink.
|
||||||
|
unlink($dir);
|
||||||
|
return;
|
||||||
|
}
|
||||||
$files = array_diff(scandir($dir), array('.','..'));
|
$files = array_diff(scandir($dir), array('.','..'));
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
(is_dir("$dir/$file")) ? self::deleteFileTree("$dir/$file") : unlink("$dir/$file");
|
$filepath = "$dir/$file";
|
||||||
|
// Note that links may resolve as directories
|
||||||
|
if (!is_dir($filepath) || is_link($filepath)) {
|
||||||
|
// Unlink files and links
|
||||||
|
unlink($filepath);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Traverse subdir and delete files
|
||||||
|
self::deleteFileTree($filepath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return rmdir($dir);
|
return rmdir($dir);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue