aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTristan Darricau <github@nicofuma.fr>2014-06-30 21:38:10 +0200
committerTristan Darricau <github@nicofuma.fr>2014-08-08 14:37:18 +0200
commite7251252ce0fcc2823226dc03b63ae18e8cd1ecb (patch)
tree1ddc385478ea58ac663279d1afa930121adc2c47
parentbef9d641796e08080fe19be8b5a2abd9ff5e140b (diff)
downloadforums-e7251252ce0fcc2823226dc03b63ae18e8cd1ecb.tar
forums-e7251252ce0fcc2823226dc03b63ae18e8cd1ecb.tar.gz
forums-e7251252ce0fcc2823226dc03b63ae18e8cd1ecb.tar.bz2
forums-e7251252ce0fcc2823226dc03b63ae18e8cd1ecb.tar.xz
forums-e7251252ce0fcc2823226dc03b63ae18e8cd1ecb.zip
[ticket/12789] Remove the directories in \phpbb\cache\driver\memory::purge()
PHPBB3-12789
-rw-r--r--phpBB/phpbb/cache/driver/memory.php70
1 files changed, 57 insertions, 13 deletions
diff --git a/phpBB/phpbb/cache/driver/memory.php b/phpBB/phpbb/cache/driver/memory.php
index 5dee375192..65f70ecbb9 100644
--- a/phpBB/phpbb/cache/driver/memory.php
+++ b/phpBB/phpbb/cache/driver/memory.php
@@ -150,28 +150,34 @@ abstract class memory extends \phpbb\cache\driver\base
function purge()
{
// Purge all phpbb cache files
- $dir = @opendir($this->cache_dir);
-
- if (!$dir)
+ try
+ {
+ $iterator = new \DirectoryIterator($this->cache_dir);
+ }
+ catch (\Exception $e)
{
return;
}
- while (($entry = readdir($dir)) !== false)
+ foreach ($iterator as $fileInfo)
{
- if (strpos($entry, 'container_') !== 0 &&
- strpos($entry, 'url_matcher') !== 0 &&
- strpos($entry, 'sql_') !== 0 &&
- strpos($entry, 'data_') !== 0 &&
- strpos($entry, 'ctpl_') !== 0 &&
- strpos($entry, 'tpl_') !== 0)
+ if ($fileInfo->isDot())
{
continue;
}
-
- $this->remove_file($this->cache_dir . $entry);
+ $filename = $fileInfo->getFilename();
+ if ($fileInfo->isDir())
+ {
+ $this->remove_dir($fileInfo->getPathname());
+ }
+ else if (strpos($filename, 'container_') !== 0 &&
+ strpos($filename, 'url_matcher') !== 0 &&
+ strpos($filename, 'sql_') !== 0 &&
+ strpos($filename, 'data_') !== 0)
+ {
+ $this->remove_file($fileInfo->getPathname());
+ }
}
- closedir($dir);
unset($this->vars);
unset($this->sql_rowset);
@@ -426,6 +432,44 @@ abstract class memory extends \phpbb\cache\driver\base
}
/**
+ * Remove directory
+ *
+ * @param string $dir Directory to remove
+ *
+ * @return null
+ */
+ protected function remove_dir($dir)
+ {
+ try
+ {
+ $iterator = new \DirectoryIterator($dir);
+ }
+ catch (\Exception $e)
+ {
+ return;
+ }
+
+ foreach ($iterator as $fileInfo)
+ {
+ if ($fileInfo->isDot())
+ {
+ continue;
+ }
+
+ if ($fileInfo->isDir())
+ {
+ $this->remove_dir($fileInfo->getPathname());
+ }
+ else
+ {
+ $this->remove_file($fileInfo->getPathname());
+ }
+ }
+
+ @rmdir($dir);
+ }
+
+ /**
* Check if a cache var exists
*
* @access protected