Skip to content

Commit

Permalink
Fixed E_WARNING when clearing cache
Browse files Browse the repository at this point in the history
  • Loading branch information
mystralkk committed Dec 19, 2020
1 parent 2715c88 commit 047e177
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions system/lib-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,37 @@ function CTL_setTemplateRoot($root)
*
* @param string $path
* @param string $needle
* @return int number of files not deleted
*/
function CTL_clearCacheDirectories($path, $needle = '')
{
$path = rtrim($path, '/\\') . DIRECTORY_SEPARATOR;
$numFiles = 0;

if ($dir = @opendir($path)) {
while ($entry = readdir($dir)) {
if ($entry === '.' || $entry === '..' || is_link($entry) || $entry === '.svn' || $entry === 'index.html') {
if ($entry === '.' || $entry === '..') {
continue;
} elseif (is_link($entry) || $entry === '.svn' || $entry === 'index.html') {
$numFiles++;
continue;
} elseif (is_dir($path . $entry)) {
CTL_clearCacheDirectories($path . $entry, $needle);
@rmdir($path . $entry);
if (CTL_clearCacheDirectories($path . $entry, $needle) === 0) {
@rmdir($path . $entry);
} else {
$numFiles++;
}
} elseif (empty($needle) || strpos($entry, $needle) !== false) {
@unlink($path . $entry);
} else {
$numFiles++;
}
}

@closedir($dir);
}

return $numFiles;
}

/**
Expand Down

0 comments on commit 047e177

Please sign in to comment.