]> _ Git - cubist_util.git/commitdiff
wip #5603 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 23 Nov 2022 13:54:09 +0000 (14:54 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 23 Nov 2022 13:54:09 +0000 (14:54 +0100)
src/Files/Files.php

index 616ece063064f3067ec1124102666ca2c06a6659..03f066f7b0098a7e8acd4ed20fe56fc20cca8ac3 100644 (file)
@@ -144,10 +144,17 @@ class Files
         return hash('sha256', $path . '/$$' . filesize($path) . '///' . filemtime($path));
     }
 
-    public static function copyFile($from, $to, $hashAlgo = false, $touch = true)
+    public static function copyFile($from, $to, $hashAlgo = false, $touch = true, $throwExceptionIfSourceNotExists = true)
     {
         $do = true;
 
+        if (!file_exists($from)) {
+            if ($throwExceptionIfSourceNotExists) {
+                throw new \Exception('File ' . $from . ' not found');
+            }
+            return false;
+        }
+
         $frommtime = filemtime($from);
         if (file_exists($to) && $frommtime === filemtime($to) && filesize($from) === filesize($to)) {
             if ($hashAlgo) {
@@ -164,7 +171,7 @@ class Files
         copy($from, $to);
 
         if ($touch) {
-            touch($to, $frommtime);
+            @touch($to, $frommtime);
         }
 
         return true;