Skip to content

Commit e0005cb

Browse files
committed
Apply review suggestions
1 parent c0a7f22 commit e0005cb

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

system/Helpers/filesystem_helper.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,16 @@ function directory_map(string $sourceDir, int $directoryDepth = 0, bool $hidden
9191
*/
9292
function directory_mirror(string $originDir, string $targetDir, bool $overwrite = true): void
9393
{
94-
$originDir = rtrim($originDir, '\\/');
95-
$targetDir = rtrim($targetDir, '\\/');
96-
97-
if (! is_dir($originDir))
94+
if (! is_dir($originDir = rtrim($originDir, '\\/')))
9895
{
9996
throw new InvalidArgumentException(sprintf('The origin directory "%s" was not found.', $originDir));
10097
}
10198

102-
if (! is_dir($targetDir))
99+
if (! is_dir($targetDir = rtrim($targetDir, '\\/')))
103100
{
104101
@mkdir($targetDir, 0755, true);
105102
}
106103

107-
108104
$dirLen = strlen($originDir);
109105

110106
/** @var SplFileInfo $file */
@@ -120,7 +116,7 @@ function directory_mirror(string $originDir, string $targetDir, bool $overwrite
120116
{
121117
mkdir($target, 0755);
122118
}
123-
elseif (! file_exists($target) || ($overwrite && is_file($target)))
119+
elseif (! is_file($target) || ($overwrite && is_file($target)))
124120
{
125121
copy($origin, $target);
126122
}

user_guide_src/source/helpers/filesystem_helper.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,19 @@ The following functions are available:
239239

240240
echo octal_permissions(fileperms('./index.php')); // 644
241241

242+
.. php:function:: same_file($file1, $file2)
243+
244+
:param string $file1: Path to the first file
245+
:param string $file2: Path to the second file
246+
:returns: Whether both files exist with identical hashes
247+
:rtype: boolean
248+
249+
Compares two files to see if they are the same (based on their MD5 hash).
250+
251+
::
252+
253+
echo same_file($newFile, $oldFile) ? 'Same!' : 'Different!';
254+
242255
.. php:function:: set_realpath($path[, $check_existence = FALSE])
243256
244257
:param string $path: Path

0 commit comments

Comments
 (0)