You are here

function _boost_rmdir_rf in Boost 6

Same name and namespace in other branches
  1. 5 boost.helpers.inc \_boost_rmdir_rf()

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

Parameters

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

$flush: optional nuke it all if true, otherwise kill only expired files

$first: id first call to this function

$nuke: clear it all, everything, ignore multisite restrictions

4 calls to _boost_rmdir_rf()
boost_cache_delete in ./boost.module
Deletes files in the cache.
boost_clear_cache_parallel in ./boost.admin.inc
boost_drush_cache_reset in ./boost.drush.inc
Clears Boost's database and file cache.
boost_reset_database_file_submit in ./boost.admin.inc
Resets boost database & cache directory

File

./boost.module, line 5314
Provides static file caching for Drupal text output. Pages, Feeds, ect...

Code

function _boost_rmdir_rf($dirname, $flush = TRUE, $first = TRUE, $nuke = FALSE, &$timer = NULL) {
  if (empty($dirname)) {
    return FALSE;
  }
  $empty = TRUE;

  // Start with an optimistic mindset
  if (is_null($timer)) {
    $timer = _boost_microtime_float();
  }
  $now = _boost_microtime_float();
  $total_time = $now - $timer;
  if ($total_time > 59) {
    $timer = $now;

    //Ping Database to keep connection alive
    db_query("SHOW PROCESSLIST");
  }
  if ($first || !$first && ($nuke || !file_exists($dirname . '/' . BOOST_ROOT_FILE))) {
    $files = glob($dirname . '/*', GLOB_NOSORT);
    if ($files) {
      foreach ($files as $file) {
        if (is_dir($file)) {
          if (!_boost_rmdir_rf($file, $flush, FALSE, $nuke, $timer)) {
            $empty = FALSE;
          }
        }
        elseif (is_file($file) || is_link($file)) {
          if (!$flush && !boost_db_is_expired($file)) {
            $empty = FALSE;
            continue;
          }
          @unlink($file);
        }
        else {
          $empty = FALSE;

          // it's something else, don't del to be safe.
        }
      }
    }
  }

  //do not delete the root dir
  if (file_exists($dirname . '/' . BOOST_ROOT_FILE)) {
    return $empty;
  }

  // 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 && BOOST_FLUSH_DIR && @rmdir($dirname);
}