From 389d3a552e36e52b97281f0c083631c15cf8690e Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Tue, 25 Jan 2011 10:45:52 +0100 Subject: Replaced rm_rf() by rm_tree(). Implemented recursive directory deletion in PHP properly without the use of exec(). This improves security, performance and portability and makes the code compatible with PHP's Safe Mode as well as with PHP setups that disable exec() using the "disable_functions" directive. Signed-off-by: Lukas Fleischer --- web/lib/aur.inc | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'web/lib') diff --git a/web/lib/aur.inc b/web/lib/aur.inc index a6292ca..835b8a8 100644 --- a/web/lib/aur.inc +++ b/web/lib/aur.inc @@ -348,11 +348,23 @@ function can_submit_pkg($name="", $sid="") { # recursive delete directory # -function rm_rf($dirname="") { - if ($dirname != "") { - exec('rm -rf ' . escapeshellcmd($dirname)); +function rm_tree($dirname) { + if (empty($dirname) || !is_dir($dirname)) return; + + foreach (scandir($dirname) as $item) { + if ($item != '.' && $item != '..') { + $path = $dirname . '/' . $item; + if (is_file($path) || is_link($path)) { + unlink($path); + } + else { + rm_tree($path); + } + } } + rmdir($dirname); + return; } -- cgit v1.2.3-54-g00ecf