Apply review suggestions

This commit is contained in:
MGatner 2021-05-21 14:27:42 +00:00
parent c0a7f22aa7
commit e0005cb4b4
No known key found for this signature in database
GPG Key ID: 9CA44105713F5A12
2 changed files with 16 additions and 7 deletions

View File

@ -91,20 +91,16 @@ if (! function_exists('directory_mirror'))
*/ */
function directory_mirror(string $originDir, string $targetDir, bool $overwrite = true): void function directory_mirror(string $originDir, string $targetDir, bool $overwrite = true): void
{ {
$originDir = rtrim($originDir, '\\/'); if (! is_dir($originDir = rtrim($originDir, '\\/')))
$targetDir = rtrim($targetDir, '\\/');
if (! is_dir($originDir))
{ {
throw new InvalidArgumentException(sprintf('The origin directory "%s" was not found.', $originDir)); throw new InvalidArgumentException(sprintf('The origin directory "%s" was not found.', $originDir));
} }
if (! is_dir($targetDir)) if (! is_dir($targetDir = rtrim($targetDir, '\\/')))
{ {
@mkdir($targetDir, 0755, true); @mkdir($targetDir, 0755, true);
} }
$dirLen = strlen($originDir); $dirLen = strlen($originDir);
/** @var SplFileInfo $file */ /** @var SplFileInfo $file */
@ -120,7 +116,7 @@ if (! function_exists('directory_mirror'))
{ {
mkdir($target, 0755); mkdir($target, 0755);
} }
elseif (! file_exists($target) || ($overwrite && is_file($target))) elseif (! is_file($target) || ($overwrite && is_file($target)))
{ {
copy($origin, $target); copy($origin, $target);
} }

View File

@ -239,6 +239,19 @@ The following functions are available:
echo octal_permissions(fileperms('./index.php')); // 644 echo octal_permissions(fileperms('./index.php')); // 644
.. php:function:: same_file($file1, $file2)
:param string $file1: Path to the first file
:param string $file2: Path to the second file
:returns: Whether both files exist with identical hashes
:rtype: boolean
Compares two files to see if they are the same (based on their MD5 hash).
::
echo same_file($newFile, $oldFile) ? 'Same!' : 'Different!';
.. php:function:: set_realpath($path[, $check_existence = FALSE]) .. php:function:: set_realpath($path[, $check_existence = FALSE])
:param string $path: Path :param string $path: Path