diff --git a/boost.helpers.inc b/boost.helpers.inc index e7a3f74dad3bc32a5db1b7c1981922b1752df526..ebe67f8885d6ee91cd14cba32fd5a33ae3667d07 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)); } /**