From 08e2b43b94f3fe5f70a44e813bf2ba2a5d4151ed Mon Sep 17 00:00:00 2001 From: Karol-Stelmaczonek <118974926+Karol-Stelmaczonek@users.noreply.github.com> Date: Thu, 21 Dec 2023 09:41:19 +0100 Subject: [PATCH] bugfix: check if dir exist before trying to create one (#1099) (#1101) * bugfix: check if dir exist before trying to create one * bugfix: change for logging * bugfix: add file check * bugfix: file_exist() * bugfix: add else * bugfix: small refactor * bugfix: add return type, change log to info * bugfix: codestyle (cherry picked from commit 2dc006c3b86a741127783e751c9d0a5b007cdcf9) --- common/persistence/class.PhpFileDriver.php | 34 ++++++++++------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/common/persistence/class.PhpFileDriver.php b/common/persistence/class.PhpFileDriver.php index a434e8887..b6969c19e 100755 --- a/common/persistence/class.PhpFileDriver.php +++ b/common/persistence/class.PhpFileDriver.php @@ -260,30 +260,28 @@ private function writeFile($id, $value, $preWriteValueProcessor = null) /** * Create directory and suppress warning message - * @param $path + * @param string $path * @param int $mode - * @return bool */ - private function makeDirectory(string $path, int $mode) + private function makeDirectory(string $path, int $mode): void { - if (is_dir($path) || @mkdir($path, $mode, true)) { - return true; - } - - if (is_dir($path)) { - \common_Logger::w(sprintf('Directory already exists. Path: \'%s\'', $path)); - } elseif (is_file($path)) { - \common_Logger::w( - sprintf( - 'Directory was not created. File with the same name already exists. Path: \'%s\'', + if (file_exists($path)) { + if (is_dir($path)) { + $message = sprintf('Directory already exists. Path: "%s"', $path); + } elseif (is_file($path)) { + $message = sprintf( + 'Directory was not created. File with the same name already exists. Path: "%s"', $path - ) - ); - } else { - \common_Logger::w(sprintf('Directory was not created. Path: \'%s\'', $path)); + ); + } else { + $message = sprintf('Directory was not created. Path: "%s"', $path); + } + \common_Logger::i($message); + + return; } - return false; + @mkdir($path, $mode, true); } /**