From: Vincent Vanwaelscappel Date: Wed, 23 Nov 2022 13:54:09 +0000 (+0100) Subject: wip #5603 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=2bbfb1c11b1027d3c7dc4e1d86d013d3aebf2ac2;p=cubist_util.git wip #5603 @1 --- diff --git a/src/Files/Files.php b/src/Files/Files.php index 616ece0..03f066f 100644 --- a/src/Files/Files.php +++ b/src/Files/Files.php @@ -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;