]> _ Git - cubist_util.git/commitdiff
wip #4666 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 14 Sep 2021 13:59:13 +0000 (15:59 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 14 Sep 2021 13:59:13 +0000 (15:59 +0200)
src/Files/VirtualDirectory.php

index f686fdc41987ea62f616e3db82ae30448db7191e..aaea168a0a30fe0ce0a8269b831807e2d9b434df 100644 (file)
@@ -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);