Skip to content
Snippets Groups Projects
Commit f3864c60 authored by Arto Bendiken's avatar Arto Bendiken
Browse files

Refactored recursive file expiry to avoid spurious watchdog warnings on...

Refactored recursive file expiry to avoid spurious watchdog warnings on non-empty directories (fixes #99646).
parent 1c1ec5f9
No related branches found
No related tags found
No related merge requests found
...@@ -21,18 +21,35 @@ function _boost_mkdir_p($pathname, $mode = 0775, $recursive = TRUE) { ...@@ -21,18 +21,35 @@ function _boost_mkdir_p($pathname, $mode = 0775, $recursive = TRUE) {
/** /**
* Recursive version of rmdir(); use with extreme caution. * 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) { function _boost_rmdir_rf($dirname, $callback = NULL) {
$empty = TRUE; // Start with an optimistic mindset
foreach (glob($dirname . '/*', GLOB_NOSORT) as $file) { foreach (glob($dirname . '/*', GLOB_NOSORT) as $file) {
if (is_dir($file)) { if (is_dir($file)) {
_boost_rmdir_rf($file, $callback); if (!_boost_rmdir_rf($file, $callback))
$empty = FALSE;
} }
else if (is_file($file)) { else if (is_file($file)) {
if (!$callback || (function_exists($callback) && $callback($file))) if (function_exists($callback)) {
if (!$callback($file)) {
$empty = FALSE;
continue;
}
}
@unlink($file); @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));
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment