mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
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 <archlinux@cryptocrack.de>
This commit is contained in:
parent
2c098d73a2
commit
389d3a552e
2 changed files with 16 additions and 4 deletions
|
@ -216,7 +216,7 @@ if ($_COOKIE["AURSID"]):
|
||||||
if (can_submit_pkg($pkg_name, $_COOKIE["AURSID"])) {
|
if (can_submit_pkg($pkg_name, $_COOKIE["AURSID"])) {
|
||||||
if (file_exists($incoming_pkgdir)) {
|
if (file_exists($incoming_pkgdir)) {
|
||||||
# Blow away the existing file/dir and contents
|
# Blow away the existing file/dir and contents
|
||||||
rm_rf($incoming_pkgdir);
|
rm_tree($incoming_pkgdir);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!@mkdir($incoming_pkgdir)) {
|
if (!@mkdir($incoming_pkgdir)) {
|
||||||
|
|
|
@ -348,11 +348,23 @@ function can_submit_pkg($name="", $sid="") {
|
||||||
|
|
||||||
# recursive delete directory
|
# recursive delete directory
|
||||||
#
|
#
|
||||||
function rm_rf($dirname="") {
|
function rm_tree($dirname) {
|
||||||
if ($dirname != "") {
|
if (empty($dirname) || !is_dir($dirname)) return;
|
||||||
exec('rm -rf ' . escapeshellcmd($dirname));
|
|
||||||
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue