From: Vincent Vanwaelscappel Date: Tue, 23 Aug 2022 20:59:12 +0000 (+0200) Subject: wip #5412 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=693c5f20d5819ab838f15bff94256558cc85f928;p=cubist_util.git wip #5412 --- diff --git a/src/Files/Files.php b/src/Files/Files.php index 2ec9904..626b0c1 100644 --- a/src/Files/Files.php +++ b/src/Files/Files.php @@ -135,29 +135,34 @@ class Files return hash('sha256', $path . '/$$' . filesize($path) . '///' . filemtime($path)); } - public static function copyFile($from, $to, $hashAlgo = false) + public static function copyFile($from, $to, $hashAlgo = false, $touch = true) { $do = true; $frommtime = filemtime($from); if (file_exists($to) && $frommtime === filemtime($to) && filesize($from) === filesize($to)) { if ($hashAlgo) { - $do = hash_file($hashAlgo, $from) !== hash_file($hashAlgo, $from); + $do = hash_file($hashAlgo, $from) !== hash_file($hashAlgo, $to); } else { $do = false; } } + if (!$do) { return false; } + copy($from, $to); - touch($to, $frommtime); + + if ($touch) { + touch($to, $frommtime); + } + return true; } public static function copy($from, $to, $context = null) { - if (!file_exists($to)) { mkdir($to, 0777, true); } @@ -293,17 +298,17 @@ class Files public static function recursiveReplaceStringInDir($path, $replace = []) { - $files=self::getRecursiveDirectoryIterator($path); + $files = self::getRecursiveDirectoryIterator($path); foreach ($files as $file) { /** @var $file \SplFileInfo */ - if($file->isDir()){ + if ($file->isDir()) { continue; } - $c=file_get_contents($file->getPathname()); - foreach ($replace as $k=>$v) { - $c=str_replace($k,$v,$c); + $c = file_get_contents($file->getPathname()); + foreach ($replace as $k => $v) { + $c = str_replace($k, $v, $c); } - file_put_contents($file->getPathname(),$c); + file_put_contents($file->getPathname(), $c); } }