summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorstilez <stilez@users.noreply.github.com>2015-12-03 14:13:15 +0000
committerstilez <stilez@users.noreply.github.com>2015-12-03 14:13:15 +0000
commita85ad858e4b98ba8b818e35a0c51e8d36413b17c (patch)
tree2db270b0799127a052d5235fbbe73f9fb0e4cc94 /src
parent6293d7edb1be7aa0813815679809c82a72eb7554 (diff)
downloadpfsense-a85ad858e4b98ba8b818e35a0c51e8d36413b17c.zip
pfsense-a85ad858e4b98ba8b818e35a0c51e8d36413b17c.tar.gz
unlink_if_exists() : minor enhancement
two minor enhancements - 1) add a comment for skim-readers, that patterns are allowed (but not arrays?) and that no error is returned 2) use array_map rather than foreach loop
Diffstat (limited to 'src')
-rw-r--r--src/etc/inc/util.inc10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/etc/inc/util.inc b/src/etc/inc/util.inc
index 88d48fa..8bf41da 100644
--- a/src/etc/inc/util.inc
+++ b/src/etc/inc/util.inc
@@ -1494,13 +1494,13 @@ function mwexec_bg($command, $clearsigmask = false) {
return mwexec($command, false, $clearsigmask, true);
}
-/* unlink a file, if it exists */
+/* unlink a file, or pattern-match of a file, if it exists
+ if the file/path contains glob() compatible wildcards, all matching files will be unlinked
+ if no matches, no error occurs */
function unlink_if_exists($fn) {
$to_do = glob($fn);
- if (is_array($to_do)) {
- foreach ($to_do as $filename) {
- @unlink($filename);
- }
+ if (is_array($to_do) && count($to_do) > 0) {
+ array_map("unlink", $to_do);
} else {
@unlink($fn);
}
OpenPOWER on IntegriCloud