Skip to content

Commit

Permalink
bugfix: check if dir exist before trying to create one (#1099) (#1101)
Browse files Browse the repository at this point in the history
* 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 2dc006c)
  • Loading branch information
Karol-Stelmaczonek authored Dec 21, 2023
1 parent 5dfcaa7 commit 08e2b43
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions common/persistence/class.PhpFileDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 08e2b43

Please sign in to comment.