You are here

function _boost_rmdir_rf in Boost 5

Same name and namespace in other branches
  1. 6 boost.module \_boost_rmdir_rf()

Recursive version of rmdir(); use with extreme caution.

Parameters

$dirname: the top-level directory that will be recursively removed

$callback: optional predicate function for determining if a file should be removed

2 calls to _boost_rmdir_rf()
boost_cache_clear_all in ./boost.api.inc
Deletes all static files currently in the cache.
boost_cache_expire_all in ./boost.api.inc
Deletes all expired static files currently in the cache.

File

./boost.helpers.inc, line 29
Various helper functions for the Boost module, to make life a bit easier.

Code

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)) {
      if (!_boost_rmdir_rf($file, $callback)) {
        $empty = FALSE;
      }
    }
    else {
      if (is_file($file)) {
        if (function_exists($callback)) {
          if (!$callback($file)) {
            $empty = FALSE;
            continue;
          }
        }
        @unlink($file);
      }
      else {
        $empty = FALSE;

        // it's probably a symbolic link
      }
    }
  }

  // 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);
}