]> _ Git - cubist_util.git/commitdiff
wip #5412
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 23 Aug 2022 20:59:12 +0000 (22:59 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 23 Aug 2022 20:59:12 +0000 (22:59 +0200)
src/Files/Files.php

index 2ec990410ab3db39d4e79b1ed1304355d0d09d0a..626b0c12728860a167ea546e07c4b96819894f61 100644 (file)
@@ -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);
         }
     }