From 2bbfb1c11b1027d3c7dc4e1d86d013d3aebf2ac2 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 23 Nov 2022 14:54:09 +0100 Subject: [PATCH] wip #5603 @1 --- src/Files/Files.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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; -- 2.39.5