From 6e2e07ce98ddf3cb0574245ac56b3863d0865896 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Tue, 31 Jan 2023 09:05:27 +0100 Subject: [PATCH] Merge \MailSo\Base\Utils::RecRmDir() and \MailSo\Base\Utils::RecTimeDirRemove() --- .../0.0.0/app/libraries/MailSo/Base/Utils.php | 25 +++---------------- .../libraries/MailSo/Cache/Drivers/File.php | 6 +---- 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Base/Utils.php b/snappymail/v/0.0.0/app/libraries/MailSo/Base/Utils.php index a1624b00f..7f439d1a0 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Base/Utils.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Base/Utils.php @@ -506,25 +506,7 @@ abstract class Utils public static function RecRmDir(string $sDir) : bool { - \clearstatcache(); - if (\is_dir($sDir)) { - $iterator = new \RecursiveIteratorIterator( - new \RecursiveDirectoryIterator($sDir, \FilesystemIterator::SKIP_DOTS), - \RecursiveIteratorIterator::CHILD_FIRST); - foreach ($iterator as $path) { - if ($path->isDir()) { - \rmdir($path); - } else { - \is_callable('opcache_invalidate') && \opcache_invalidate($path, true); - \unlink($path); - } - } - \clearstatcache(); -// \realpath_cache_size() && \clearstatcache(true); - return \rmdir($sDir); - } - - return false; + return static::RecTimeDirRemove($sDir, 0); } public static function RecTimeDirRemove(string $sDir, int $iTime2Kill) : bool @@ -536,9 +518,10 @@ abstract class Utils new \RecursiveDirectoryIterator($sDir, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST); foreach ($iterator as $path) { - if ($path->isFile() && $path->getMTime() < $iTime) { + if ($path->isFile() && (!$iTime2Kill || $path->getMTime() < $iTime)) { + \is_callable('opcache_invalidate') && \opcache_invalidate($path, true); \unlink($path); - } else if ($path->isDir() && !(new \FilesystemIterator($path))->valid()) { + } else if ($path->isDir() && (!$iTime2Kill || !(new \FilesystemIterator($path))->valid())) { \rmdir($path); } } diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Cache/Drivers/File.php b/snappymail/v/0.0.0/app/libraries/MailSo/Cache/Drivers/File.php index 389295675..0fc9ab15e 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Cache/Drivers/File.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Cache/Drivers/File.php @@ -61,11 +61,7 @@ class File implements \MailSo\Cache\DriverInterface public function GC(int $iTimeToClearInHours = 24) : bool { - if (0 === $iTimeToClearInHours) { - \MailSo\Base\Utils::RecRmDir($this->sCacheFolder); - } else { - \MailSo\Base\Utils::RecTimeDirRemove($this->sCacheFolder, 3600 * $iTimeToClearInHours); - } + \MailSo\Base\Utils::RecTimeDirRemove($this->sCacheFolder, 3600 * $iTimeToClearInHours); return true; }