summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Smith <colin@pfsense.org>2005-03-21 04:18:48 +0000
committerColin Smith <colin@pfsense.org>2005-03-21 04:18:48 +0000
commit7eb2e498b1c0fff310e9d9b9b12fa721605cd5f0 (patch)
tree87906706624cab403fb4858a19ccd6dcc5f40bf6
parent8e8f7ff7ce5ededa9ac158bc2cbd618adf4f2ce9 (diff)
downloadpfsense-7eb2e498b1c0fff310e9d9b9b12fa721605cd5f0.zip
pfsense-7eb2e498b1c0fff310e9d9b9b12fa721605cd5f0.tar.gz
Add wildcard support to rmdir_recursive().
-rw-r--r--etc/inc/pfsense-utils.inc31
1 files changed, 22 insertions, 9 deletions
diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc
index 43b970a..da10da7 100644
--- a/etc/inc/pfsense-utils.inc
+++ b/etc/inc/pfsense-utils.inc
@@ -910,20 +910,33 @@ function sync_package($pkg_name, $sync_depends = true, $show_message = false) {
}
/*
- * rmdir_recursive($path,$followLinks=false)
+ * rmdir_recursive($path,$follow_links=false)
* Recursively remove a directory tree (rm -rf path)
* This is for directories _only_
*/
function rmdir_recursive($path,$follow_links=false) {
- $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");
+ $to_do = glob($path);
+ if(!is_array($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);
+ } else {
+ foreach($to_do as $workingdir) { // Handle wildcards by foreaching.
+ $dir = opendir($workingdir);
+ while ($entry = readdir($dir)) {
+ if (is_file("$workingdir/$entry") || ((!$follow_links) && is_link("$workingdir/$entry")))
+ unlink("$workingdir/$entry");
+ elseif (is_dir("$workingdir/$entry") && $entry!='.' && $entry!='..')
+ rmdir_recursive("$workingdir/$entry");
+ }
+ closedir($dir);
+ }
}
- closedir($dir) ;
return rmdir($path);
}
OpenPOWER on IntegriCloud