From ed919b11cc702a2b071cb6877cbff87171a37449 Mon Sep 17 00:00:00 2001 From: Colin Smith Date: Sun, 12 Jun 2005 18:52:22 +0000 Subject: rmdir_recursive: Handle single files and remove an extra foreach. --- etc/inc/pfsense-utils.inc | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) (limited to 'etc/inc') diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc index 4af92fa..23d0899 100644 --- a/etc/inc/pfsense-utils.inc +++ b/etc/inc/pfsense-utils.inc @@ -786,34 +786,23 @@ if (!function_exists('php_check_syntax')){ */ function rmdir_recursive($path,$follow_links=false) { $to_do = glob($path); - if(!is_array($to_do)) { - if(file_exists($to_do)) { - $dir = opendir($path); - while ($entry = readdir($dir)) { - if (is_file("$path/$entry") || ((!$follow_links) && is_link("$path/$entry"))) - unlink("$path/$entry"); - elseif (is_dir("$path/$entry") && $entry!='.' && $entry!='..') - rmdir_recursive("$path/$entry"); - } - closedir($dir); - rmdir($path); - return; - } - } else { - foreach($to_do as $workingdir) { // Handle wildcards by foreaching. - if(file_exists($workingdir)) { + if(!is_array($to_do)) $to_do = array($to_do); + foreach($to_do as $workingdir) { // Handle wildcards by foreaching. + if(file_exists($workingdir)) { + if(is_dir($workingdir)) { $dir = opendir($workingdir); while ($entry = readdir($dir)) { if (is_file("$workingdir/$entry") || ((!$follow_links) && is_link("$workingdir/$entry"))) - unlink("$workingdir/$entry"); + unlink("$workingdir/$entry"); elseif (is_dir("$workingdir/$entry") && $entry!='.' && $entry!='..') - rmdir_recursive("$workingdir/$entry"); + rmdir_recursive("$workingdir/$entry"); } closedir($dir); rmdir($workingdir); - } - } - return; + } elseif (is_file($workingdir)) { + unlink($workingdir); + } + } } return; } @@ -937,4 +926,4 @@ function fetch_latest_pkg_config() { return; } -?> \ No newline at end of file +?> -- cgit v1.1