]> source.dussan.org Git - nextcloud-server.git/commitdiff
added createMissingDirectories() method
authorBjoern Schiessle <schiessle@owncloud.com>
Sat, 17 Aug 2013 11:28:35 +0000 (13:28 +0200)
committerBjoern Schiessle <schiessle@owncloud.com>
Sat, 17 Aug 2013 15:35:59 +0000 (17:35 +0200)
apps/files_versions/lib/versions.php

index 5e2414f2dceaa1c14ba3cbf3da5e47e000998037..a9b1d220145b16fb74fee873b31dedeb0fac8396 100644 (file)
@@ -109,15 +109,7 @@ class Storage {
                        }
 
                        // create all parent folders
-                       $dirname=  \OC_Filesystem::normalizePath(pathinfo($filename, PATHINFO_DIRNAME));
-                       $dirParts = explode('/', $dirname);
-                       $dir = "/files_versions";
-                       foreach ($dirParts as $part) {
-                               $dir = $dir.'/'.$part;
-                               if(!$users_view->file_exists($dir)) {
-                                       $users_view->mkdir($dir);
-                               }
-                       }
+                       self::createMissingDirectories($filename, $users_view);
 
                        $versionsSize = self::getVersionsSize($uid);
                        if (  $versionsSize === false || $versionsSize < 0 ) {
@@ -190,15 +182,8 @@ class Storage {
                        $versions_view->rename($oldpath, $newpath);
                } else  if ( ($versions = Storage::getVersions($uid, $oldpath)) ) {
                        // create missing dirs if necessary
-                       $dirname = \OC_Filesystem::normalizePath(pathinfo($newpath, PATHINFO_DIRNAME));
-                       $dirParts = explode('/', $dirname);
-                       $dir = "/files_versions";
-                       foreach ($dirParts as $part) {
-                               $dir = $dir.'/'.$part;
-                               if(!$users_view->file_exists($dir)) {
-                                       $users_view->mkdir($dir);
-                               }
-                       }
+                       self::createMissingDirectories($newpath, new \OC\Files\View('/'. $uidn));
+                       
                        foreach ($versions as $v) {
                                $versions_view->rename($oldpath.'.v'.$v['version'], $newpath.'.v'.$v['version']);
                        }
@@ -557,4 +542,20 @@ class Storage {
                return $size;
        }
 
+       /**
+        * @brief create recursively missing directories
+        * @param string $filename $path to a file
+        */
+       private static function createMissingDirectories($filename, $view) {
+               $dirname = \OC_Filesystem::normalizePath(pathinfo($filename, PATHINFO_DIRNAME));
+               $dirParts = explode('/', $dirname);
+               $dir = "/files_versions";
+               foreach ($dirParts as $part) {
+                       $dir = $dir . '/' . $part;
+                       if (!$view->file_exists($dir)) {
+                               $view->mkdir($dir);
+                       }
+               }
+       }
+
 }