mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
Apply review suggestions
This commit is contained in:
parent
c0a7f22aa7
commit
e0005cb4b4
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user