From a74e1936749296173ac75d73a5f45ed82eab09d6 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 14 Sep 2021 15:59:13 +0200 Subject: [PATCH] wip #4666 @0.5 --- src/Files/VirtualDirectory.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Files/VirtualDirectory.php b/src/Files/VirtualDirectory.php index f686fdc..aaea168 100644 --- a/src/Files/VirtualDirectory.php +++ b/src/Files/VirtualDirectory.php @@ -25,6 +25,9 @@ class VirtualDirectory public function copy($from, $to) { + if (!file_exists($from)) { + throw new \Exception(sprintf('File %s doen\'t exist', $from)); + } $realto = $this->path($to); if (!$realto) { return $this; @@ -35,6 +38,9 @@ class VirtualDirectory public function copyDirectory($from, $to) { + if (!file_exists($from)) { + throw new \Exception(sprintf('Directory %s doen\'t exist', $from)); + } $this->_directories[$this->path($to)] = $from; return $this; } @@ -70,6 +76,8 @@ class VirtualDirectory file_put_contents($to, $data); } + //dd($this->_copy); + foreach ($this->_copy as $to => $from) { if (!file_exists($from)) { continue; @@ -77,7 +85,12 @@ class VirtualDirectory if ($delete) { $existing[$to] = true; } - if (!file_exists($to) || filesize($from) != filesize($to) || filemtime($from) > filemtime($to)) { + + if (!file_exists($from)) { + throw new \Exception(sprintf('Failed to copy %s to %s. Source doesn\'t exist', $from, $to)); + } + + if (!file_exists($to) || filesize($from) !== filesize($to) || filemtime($from) > filemtime($to)) { try { copy($from, $to); } catch (\Exception $e) { @@ -92,12 +105,11 @@ class VirtualDirectory $this->cleanTemp(); } + /** + * @throws \Exception + */ protected function _addDirectory($from, $to) { - if (!file_exists($from)) { - return; - } - $from = realpath($from); $files = Files::getRecursiveDirectoryIterator($from); -- 2.39.5