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

index 764b07b269e670e4c6126d1206b889a75962a75a..1807805ea7adfb15b839a561bcc21d8181acd1dd 100644 (file)
@@ -24,11 +24,16 @@ class Files
 
     public static function mkdir($path, $mode = 0777, $recursive = true)
     {
-        if (file_exists($path)) {
-            return;
+        if (!file_exists($path)) {
+            try {
+                if (!mkdir($path, $mode, $recursive) && !is_dir($path)) {
+                    throw new \RuntimeException(sprintf('Directory "%s" was not created', $path));
+                }
+            } catch (\Exception $e) {
+                throw new \RuntimeException(sprintf('Directory "%s" was not created. %s', $path, $e->getMessage()));
+            }
         }
-        mkdir($path, $mode, $recursive);
-        return realpath($path);
+        return realpath($path).'/';
     }
 
     public static function humanReadableSize($size, $precision = 2)
index ac312e48efa6696ae8b00a75c3b63ccc951ae007..f686fdc41987ea62f616e3db82ae30448db7191e 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 
 namespace Cubist\Util\Files;
+
 use SplFileInfo;
 
 class VirtualDirectory
@@ -44,10 +45,14 @@ class VirtualDirectory
         return $this;
     }
 
+    /**
+     * @throws \Exception
+     */
     public function sync($delete = false)
     {
         $existing = array();
 
+
         foreach ($this->_directories as $to => $from) {
             $this->_addDirectory($from, $to);
         }
@@ -73,7 +78,11 @@ class VirtualDirectory
                 $existing[$to] = true;
             }
             if (!file_exists($to) || filesize($from) != filesize($to) || filemtime($from) > filemtime($to)) {
-                copy($from, $to);
+                try {
+                    copy($from, $to);
+                } catch (\Exception $e) {
+                    throw new \Exception(sprintf('Failed to copy %s to %s', $from, $to));
+                }
             }
         }