From dc09ed313786df03f10523d734ce1cc36eae5730 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sat, 25 May 2013 20:06:10 +0200 Subject: [PATCH] Fixes issue with outdated disk caches Fixes #1289 --- .../cache/source/DiskCacheSource.class.php | 27 ++++++++++++- .../files/lib/util/DirectoryUtil.class.php | 40 +++++++++---------- 2 files changed, 45 insertions(+), 22 deletions(-) diff --git a/wcfsetup/install/files/lib/system/cache/source/DiskCacheSource.class.php b/wcfsetup/install/files/lib/system/cache/source/DiskCacheSource.class.php index 36a5bc1f2e..7c08f503d6 100644 --- a/wcfsetup/install/files/lib/system/cache/source/DiskCacheSource.class.php +++ b/wcfsetup/install/files/lib/system/cache/source/DiskCacheSource.class.php @@ -18,6 +18,12 @@ use wcf\util\FileUtil; * @category Community Framework */ class DiskCacheSource implements ICacheSource { + /** + * up-to-date directory util object for the cache folder + * @var wcf\util\DirectoryUtil + */ + protected $directoryUtil = null; + /** * @see wcf\system\cache\source\ICacheSource::flush() */ @@ -34,7 +40,7 @@ class DiskCacheSource implements ICacheSource { * @see wcf\system\cache\source\ICacheSource::flushAll() */ public function flushAll() { - DirectoryUtil::getInstance(WCF_DIR.'cache/')->removePattern(new Regex('.*\.php$')); + $this->getDirectoryUtil()->removePattern(new Regex('.*\.php$')); } /** @@ -63,6 +69,10 @@ class DiskCacheSource implements ICacheSource { $file->write("\n"); $file->write(serialize($value)); $file->close(); + + // unset current DirectoryUtil object to make sure new cache file + // can be deleted in the same request + $this->directoryUtil = null; } /** @@ -84,7 +94,7 @@ class DiskCacheSource implements ICacheSource { $directory = FileUtil::unifyDirSeperator(WCF_DIR.'cache/'); $pattern = str_replace('*', '.*', str_replace('.', '\.', $pattern)); - DirectoryUtil::getInstance($directory)->executeCallback(new Callback(function ($filename) { + $this->getDirectoryUtil()->executeCallback(new Callback(function ($filename) { if (!@touch($filename, 1)) { @unlink($filename); } @@ -151,4 +161,17 @@ class DiskCacheSource implements ICacheSource { return $value; } + + /** + * Returns an up-to-date directory util object for the cache folder. + * + * @return wcf\util\DirectoryUtil + */ + protected function getDirectoryUtil() { + if ($this->directoryUtil === null) { + $this->directoryUtil = new DirectoryUtil(WCF_DIR.'cache/'); + } + + return $this->directoryUtil; + } } diff --git a/wcfsetup/install/files/lib/util/DirectoryUtil.class.php b/wcfsetup/install/files/lib/util/DirectoryUtil.class.php index 9b353ad7b6..4c7e24df58 100644 --- a/wcfsetup/install/files/lib/util/DirectoryUtil.class.php +++ b/wcfsetup/install/files/lib/util/DirectoryUtil.class.php @@ -65,6 +65,26 @@ final class DirectoryUtil { false => array() // non-recursive instances ); + /** + * Creates a new instance of DirectoryUtil. + * + * @param string $directory directory path + * @param boolean $recursive created a recursive directory iterator + * @see wcf\util\DirectoryUtil::getInstance() + */ + public function __construct($directory, $recursive = true) { + $this->directory = $directory; + $this->recursive = $recursive; + + // handle iterator type + if ($this->recursive) { + $this->obj = new \RecursiveDirectoryIterator($directory); + } + else { + $this->obj = new \DirectoryIterator($directory); + } + } + /** * Returns an instance of DirectoryUtil (or child). * @@ -89,26 +109,6 @@ final class DirectoryUtil { return static::$instances[$recursive][$directory]; } - /** - * Creates a new instance of DirectoryUtil. - * - * @param string $directory directory path - * @param boolean $recursive created a recursive directory iterator - * @see wcf\util\DirectoryUtil::getInstance() - */ - protected function __construct($directory, $recursive = true) { - $this->directory = $directory; - $this->recursive = $recursive; - - // handle iterator type - if ($this->recursive) { - $this->obj = new \RecursiveDirectoryIterator($directory); - } - else { - $this->obj = new \DirectoryIterator($directory); - } - } - /** * @see wcf\util\DirectoryUtil::getInstance() */ -- 2.20.1