function _boost_rmdir in Boost 7
Recursive version of rmdir(); use with extreme caution.
Function also checks file age and only removes expired files.
Parameters
$dir: The top-level directory that will be recursively removed.
$flush: Instead of removing expired cached files, remove all files.
2 calls to _boost_rmdir()
- boost_cron in ./
boost.module - Implements hook_cron(). Performs periodic actions.
- boost_flush_caches in ./
boost.module - Implements hook_flush_caches(). Deletes all static files.
File
- ./
boost.module, line 1274 - Caches generated output as a static file to be served directly from the webserver.
Code
function _boost_rmdir($dir, $flush = TRUE) {
static $lifetimes = array();
static $counter = 0;
if (is_dir($dir) == FALSE) {
return FALSE;
}
if (!boost_in_cache_dir($dir)) {
return FALSE;
}
// Map extensions to cache lifetimes.
if (empty($lifetimes)) {
$types = boost_get_storage_types();
foreach ($types as $title => $content_types) {
foreach ($content_types as $type => $values) {
$lifetimes[$values['extension']] = $values['lifetime_max'];
}
}
// Be sure to recreate the htaccess file just in case.
boost_form_submit_handler();
}
$objects = scandir($dir);
$empty_dir = TRUE;
foreach ($objects as $object) {
if ($object === '.' || $object === '..') {
continue;
}
if ($object === '.htaccess') {
$empty_dir = FALSE;
continue;
}
$file = $dir . '/' . $object;
if (is_dir($file)) {
_boost_rmdir($file, $flush);
}
elseif ($flush) {
unlink($file);
$counter++;
}
else {
// Need to handle gzipped files.
// Nice if it supported multi level cache expiration per content type.
$ext = substr(strrchr($file, '.'), 1);
$age = boost_file_get_age($file);
if (isset($lifetimes[$ext]) && $age > $lifetimes[$ext]) {
unlink($file);
$counter++;
}
else {
$empty_dir = FALSE;
}
}
}
if ($empty_dir && is_dir($dir)) {
// #1138630 @ error suppression used due to rmdir being a race condition.
@rmdir($dir);
}
return $counter;
}