Skip to content

Commit 08e2b43

Browse files
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 2dc006c)
1 parent 5dfcaa7 commit 08e2b43

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

common/persistence/class.PhpFileDriver.php

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -260,30 +260,28 @@ private function writeFile($id, $value, $preWriteValueProcessor = null)
260260

261261
/**
262262
* Create directory and suppress warning message
263-
* @param $path
263+
* @param string $path
264264
* @param int $mode
265-
* @return bool
266265
*/
267-
private function makeDirectory(string $path, int $mode)
266+
private function makeDirectory(string $path, int $mode): void
268267
{
269-
if (is_dir($path) || @mkdir($path, $mode, true)) {
270-
return true;
271-
}
272-
273-
if (is_dir($path)) {
274-
\common_Logger::w(sprintf('Directory already exists. Path: \'%s\'', $path));
275-
} elseif (is_file($path)) {
276-
\common_Logger::w(
277-
sprintf(
278-
'Directory was not created. File with the same name already exists. Path: \'%s\'',
268+
if (file_exists($path)) {
269+
if (is_dir($path)) {
270+
$message = sprintf('Directory already exists. Path: "%s"', $path);
271+
} elseif (is_file($path)) {
272+
$message = sprintf(
273+
'Directory was not created. File with the same name already exists. Path: "%s"',
279274
$path
280-
)
281-
);
282-
} else {
283-
\common_Logger::w(sprintf('Directory was not created. Path: \'%s\'', $path));
275+
);
276+
} else {
277+
$message = sprintf('Directory was not created. Path: "%s"', $path);
278+
}
279+
\common_Logger::i($message);
280+
281+
return;
284282
}
285283

286-
return false;
284+
@mkdir($path, $mode, true);
287285
}
288286

289287
/**

0 commit comments

Comments
 (0)