From ec80404eed54ad7e790ad472148094e72f304f9a Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Tue, 13 Dec 2022 12:29:18 +0100 Subject: [PATCH] Better log failed mkdir() --- .../libraries/MailSo/Cache/Drivers/File.php | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) 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 ed54f97f0..389295675 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 @@ -45,19 +45,16 @@ class File implements \MailSo\Cache\DriverInterface { $sValue = ''; $sPath = $this->generateCachedFileName($sKey); - if ('' !== $sPath && \file_exists($sPath)) - { + if ('' !== $sPath && \file_exists($sPath)) { $sValue = \file_get_contents($sPath); } - return \is_string($sValue) ? $sValue : ''; } public function Delete(string $sKey) : void { $sPath = $this->generateCachedFileName($sKey); - if ('' !== $sPath && \file_exists($sPath)) - { + if ('' !== $sPath && \file_exists($sPath)) { \unlink($sPath); } } @@ -75,19 +72,18 @@ class File implements \MailSo\Cache\DriverInterface private function generateCachedFileName(string $sKey, bool $bMkDir = false) : string { $sFilePath = ''; - if (3 < \strlen($sKey)) - { + if (3 < \strlen($sKey)) { $sKeyPath = \sha1($sKey); - $sKeyPath = \substr($sKeyPath, 0, 2).'/'.\substr($sKeyPath, 2, 2).'/'.$sKeyPath; - - $sFilePath = $this->sCacheFolder.$this->sKeyPrefix.$sKeyPath; - $dir = \dirname($sFilePath); - if ($bMkDir && !\is_dir($dir) && !\mkdir($dir, 0700, true)) - { - $sFilePath = ''; + $sFilePath = $this->sCacheFolder . $this->sKeyPrefix + . \substr($sKeyPath, 0, 2) . '/' . \substr($sKeyPath, 2, 2) . '/' . $sKeyPath; + if ($bMkDir) { + $dir = \dirname($sFilePath); + if (!\is_dir($dir) && !\mkdir($dir, 0700, true)) { + \error_log("mkdir({$dir}) failed"); + $sFilePath = ''; + } } } - return $sFilePath; } }