summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArto Bendiken2006-11-25 10:39:55 (GMT)
committerArto Bendiken2006-11-25 10:39:55 (GMT)
commitf3864c609a92184c8a6d20934417a7f28f1649d9 (patch)
tree04dc71815e432b8432248a1f110c9701b5395b86
parent1c1ec5f96636ae5e9975d6643c3c0d02448cdc94 (diff)
Refactored recursive file expiry to avoid spurious watchdog warnings on non-empty directories (fixes #99646).
-rw-r--r--boost.helpers.inc25
1 files changed, 21 insertions, 4 deletions
diff --git a/boost.helpers.inc b/boost.helpers.inc
index e7a3f74..ebe67f8 100644
--- a/boost.helpers.inc
+++ b/boost.helpers.inc
@@ -21,18 +21,35 @@ function _boost_mkdir_p($pathname, $mode = 0775, $recursive = TRUE) {
/**
* Recursive version of rmdir(); use with extreme caution.
+ *
+ * @param $dirname
+ * the top-level directory that will be recursively removed
+ * @param $callback
+ * optional predicate function for determining if a file should be removed
*/
function _boost_rmdir_rf($dirname, $callback = NULL) {
+ $empty = TRUE; // Start with an optimistic mindset
+
foreach (glob($dirname . '/*', GLOB_NOSORT) as $file) {
if (is_dir($file)) {
- _boost_rmdir_rf($file, $callback);
+ if (!_boost_rmdir_rf($file, $callback))
+ $empty = FALSE;
}
else if (is_file($file)) {
- if (!$callback || (function_exists($callback) && $callback($file)))
- @unlink($file);
+ if (function_exists($callback)) {
+ if (!$callback($file)) {
+ $empty = FALSE;
+ continue;
+ }
+ }
+ @unlink($file);
}
}
- return @rmdir($dirname);
+
+ // The reason for this elaborate safeguard is that Drupal will log even
+ // warnings that should have been suppressed with the @ sign. Otherwise,
+ // we'd just rely on the FALSE return value from rmdir().
+ return ($empty && @rmdir($dirname));
}
/**