]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add getMountPoint to FileInfo
authorRobin Appelman <icewind@owncloud.com>
Tue, 16 Dec 2014 13:24:48 +0000 (14:24 +0100)
committerRobin Appelman <icewind@owncloud.com>
Wed, 17 Dec 2014 13:03:50 +0000 (14:03 +0100)
15 files changed:
apps/files/tests/ajax_rename.php
apps/files/tests/helper.php
apps/files_trashbin/lib/helper.php
lib/private/connector/sabre/directory.php
lib/private/connector/sabre/objecttree.php
lib/private/files/fileinfo.php
lib/private/files/node/node.php
lib/private/files/view.php
lib/public/files/fileinfo.php
tests/lib/connector/sabre/file.php
tests/lib/connector/sabre/objecttree.php
tests/lib/files/node/file.php
tests/lib/files/node/folder.php
tests/lib/files/node/node.php
tests/lib/files/node/root.php

index 48aed05823b45b17a012540f46fa513a755e4a78..1cfecf9e58c43b8a5fbd9a8a7991d09f78da3efd 100644 (file)
@@ -107,7 +107,7 @@ class Test_OC_Files_App_Rename extends \Test\TestCase {
                                'etag' => 'abcdef',
                                'directory' => '/',
                                'name' => 'new_name',
-                       ))));
+                       ), null)));
 
                $result = $this->files->rename($dir, $oldname, $newname);
 
index 1b7c8eef43ae6ea8a9b1e27c6c7590a9bda68887..ea96e41d1d1699606a78ced2fc9582da0e2198cf 100644 (file)
@@ -24,7 +24,8 @@ class Test_Files_Helper extends \Test\TestCase {
                                'mtime' => $mtime,
                                'type' => $isDir ? 'dir' : 'file',
                                'mimetype' => $isDir ? 'httpd/unix-directory' : 'application/octet-stream'
-                       )       
+                       ),
+                       null
                );
        }
 
index c99662480df5c8f7e761be598a7e5166fdbe9aba..d9e69b71aa0bf36734f676a81c3c6b0c516bf995 100644 (file)
@@ -31,8 +31,10 @@ class Helper
                        return $result;
                }
 
-               list($storage, $internalPath) = $view->resolvePath($dir);
+               $mount = $view->getMount($dir);
+               $storage = $mount->getStorage();
                $absoluteDir = $view->getAbsolutePath($dir);
+               $internalPath = $mount->getInternalPath($absoluteDir);
 
                if (is_resource($dirContent)) {
                        $originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user);
@@ -65,7 +67,7 @@ class Helper
                                        if ($originalPath) {
                                                $i['extraData'] = $originalPath.'/'.$id;
                                        }
-                                       $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i);
+                                       $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount);
                                }
                        }
                        closedir($dirContent);
index ec5f82f9daa832d032983a8b44b0b817e407bcb0..bbe0f3452a732945238b85177b463f5c33967c4f 100644 (file)
@@ -72,7 +72,7 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node
 
                        $path = $this->fileView->getAbsolutePath($this->path) . '/' . $name;
                        // using a dummy FileInfo is acceptable here since it will be refreshed after the put is complete
-                       $info = new \OC\Files\FileInfo($path, null, null, array());
+                       $info = new \OC\Files\FileInfo($path, null, null, array(), null);
                        $node = new OC_Connector_Sabre_File($this->fileView, $info);
                        return $node->put($data);
                } catch (\OCP\Files\StorageNotAvailableException $e) {
index 14a55b5cada42bf626a6415be8cf5908d1e61d9c..d2759d7a3bafc56b430465346a7325e7ab094f76 100644 (file)
@@ -71,7 +71,9 @@ class ObjectTree extends \Sabre\DAV\ObjectTree {
                if (pathinfo($path, PATHINFO_EXTENSION) === 'part') {
                        // read from storage
                        $absPath = $this->fileView->getAbsolutePath($path);
-                       list($storage, $internalPath) = Filesystem::resolvePath('/' . $absPath);
+                       $mount = $this->fileView->getMount($path);
+                       $storage = $mount->getStorage();
+                       $internalPath = $mount->getInternalPath($absPath);
                        if ($storage) {
                                /**
                                 * @var \OC\Files\Storage\Storage $storage
@@ -79,7 +81,7 @@ class ObjectTree extends \Sabre\DAV\ObjectTree {
                                $scanner = $storage->getScanner($internalPath);
                                // get data directly
                                $data = $scanner->getData($internalPath);
-                               $info = new FileInfo($absPath, $storage, $internalPath, $data);
+                               $info = new FileInfo($absPath, $storage, $internalPath, $data, $mount);
                        } else {
                                $info = null;
                        }
index 8bab51f07378292d3304b7bd19896934ea9548e2..e4a397dcca287cae45a1e80ee94879a2bc3ab21d 100644 (file)
@@ -29,15 +29,24 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {
         */
        private $internalPath;
 
+       /**
+        * @var \OCP\Files\Mount\IMountPoint
+        */
+       private $mount;
+
        /**
         * @param string|boolean $path
         * @param Storage\Storage $storage
+        * @param string $internalPath
+        * @param array $data
+        * @param \OCP\Files\Mount\IMountPoint $mount
         */
-       public function __construct($path, $storage, $internalPath, $data) {
+       public function __construct($path, $storage, $internalPath, $data, $mount) {
                $this->path = $path;
                $this->storage = $storage;
                $this->internalPath = $internalPath;
                $this->data = $data;
+               $this->mount = $mount;
        }
 
        public function offsetSet($offset, $value) {
@@ -208,6 +217,7 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {
 
        /**
         * Check if a file or folder is shared
+        *
         * @return bool
         */
        public function isShared() {
@@ -229,4 +239,13 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {
 
                return false;
        }
+
+       /**
+        * Get the mountpoint the file belongs to
+        *
+        * @return \OCP\Files\Mount\IMountPoint
+        */
+       public function getMountPoint() {
+               return $this->mount;
+       }
 }
index 87d4a4b91569119fc481ddb7583b4485b8915a5a..17907a53044e0d6f302b6c0b3aff6b4266dba0da 100644 (file)
@@ -288,4 +288,8 @@ class Node implements \OCP\Files\Node, FileInfo {
        public function isEncrypted() {
                return $this->getFileInfo()->isEncrypted();
        }
+
+       public function getMountPoint() {
+               return $this->getFileInfo()->getMountPoint();
+       }
 }
index c01763cdad3b260fc07249776dfcd687e0220ede..40789621df798338c9fa026b22380f7b7db9609a 100644 (file)
@@ -112,6 +112,19 @@ class View {
                return Filesystem::getMountPoint($this->getAbsolutePath($path));
        }
 
+       /**
+        * get the mountpoint of the storage object for a path
+        * ( note: because a storage is not always mounted inside the fakeroot, the
+        * returned mountpoint is relative to the absolute root of the filesystem
+        * and doesn't take the chroot into account )
+        *
+        * @param string $path
+        * @return \OCP\Files\Mount\IMountPoint
+        */
+       public function getMount($path) {
+               return Filesystem::getMountManager()->find($this->getAbsolutePath($path));
+       }
+
        /**
         * resolve a path to a storage and internal path
         *
@@ -938,7 +951,7 @@ class View {
 
                $data = \OC_FileProxy::runPostProxies('getFileInfo', $path, $data);
 
-               return new FileInfo($path, $storage, $internalPath, $data);
+               return new FileInfo($path, $storage, $internalPath, $data, $mount);
        }
 
        /**
@@ -955,8 +968,10 @@ class View {
                        return $result;
                }
                $path = $this->getAbsolutePath($directory);
-               /** @var \OC\Files\Storage\Storage $storage */
-               list($storage, $internalPath) = $this->resolvePath($directory);
+               $path = Filesystem::normalizePath($path);
+               $mount = $this->getMount($directory);
+               $storage = $mount->getStorage();
+               $internalPath = $mount->getInternalPath($path);
                if ($storage) {
                        $cache = $storage->getCache($internalPath);
                        $user = \OC_User::getUser();
@@ -990,7 +1005,7 @@ class View {
                                if (\OCP\Util::isSharingDisabledForUser()) {
                                        $content['permissions'] = $content['permissions'] & ~\OCP\Constants::PERMISSION_SHARE;
                                }
-                               $files[] = new FileInfo($path . '/' . $content['name'], $storage, $content['path'], $content);
+                               $files[] = new FileInfo($path . '/' . $content['name'], $storage, $content['path'], $content, $mount);
                        }
 
                        //add a folder for any mountpoint in this directory and add the sizes of other mountpoints to the folders
@@ -998,7 +1013,7 @@ class View {
                        $dirLength = strlen($path);
                        foreach ($mounts as $mount) {
                                $mountPoint = $mount->getMountPoint();
-                               $subStorage = Filesystem::getStorage($mountPoint);
+                               $subStorage = $mount->getStorage();
                                if ($subStorage) {
                                        $subCache = $subStorage->getCache('');
 
@@ -1044,7 +1059,7 @@ class View {
                                                                $content['permissions'] = $content['permissions'] & ~\OCP\Constants::PERMISSION_SHARE;
                                                        }
 
-                                                       $files[] = new FileInfo($path . '/' . $rootEntry['name'], $subStorage, '', $rootEntry);
+                                                       $files[] = new FileInfo($path . '/' . $rootEntry['name'], $subStorage, '', $rootEntry, $mount);
                                                }
                                        }
                                }
@@ -1154,8 +1169,9 @@ class View {
                $files = array();
                $rootLength = strlen($this->fakeRoot);
 
-               $mountPoint = Filesystem::getMountPoint($this->fakeRoot);
-               $storage = Filesystem::getStorage($mountPoint);
+               $mount = $this->getMount('');
+               $mountPoint = $mount->getMountPoint();
+               $storage = $mount->getStorage();
                if ($storage) {
                        $cache = $storage->getCache('');
 
@@ -1165,13 +1181,14 @@ class View {
                                        $internalPath = $result['path'];
                                        $path = $mountPoint . $result['path'];
                                        $result['path'] = substr($mountPoint . $result['path'], $rootLength);
-                                       $files[] = new FileInfo($path, $storage, $internalPath, $result);
+                                       $files[] = new FileInfo($path, $storage, $internalPath, $result, $mount);
                                }
                        }
 
-                       $mountPoints = Filesystem::getMountPoints($this->fakeRoot);
-                       foreach ($mountPoints as $mountPoint) {
-                               $storage = Filesystem::getStorage($mountPoint);
+                       $mounts = Filesystem::getMountManager()->findIn($this->fakeRoot);
+                       foreach ($mounts as $mount) {
+                               $mountPoint = $mount->getMountPoint();
+                               $storage = $mount->getStorage();
                                if ($storage) {
                                        $cache = $storage->getCache('');
 
@@ -1182,7 +1199,7 @@ class View {
                                                        $internalPath = $result['path'];
                                                        $result['path'] = rtrim($relativeMountPoint . $result['path'], '/');
                                                        $path = rtrim($mountPoint . $internalPath, '/');
-                                                       $files[] = new FileInfo($path, $storage, $internalPath, $result);
+                                                       $files[] = new FileInfo($path, $storage, $internalPath, $result, $mount);
                                                }
                                        }
                                }
index 3a407ed67ca226b95b2613b1ae9f508c23795630..ec68ed475c51545fb5e486655cc71ef66b54dd17 100644 (file)
@@ -169,4 +169,11 @@ interface FileInfo {
         * @return bool
         */
        public function isMounted();
+
+       /**
+        * Get the mountpoint the file belongs to
+        *
+        * @return \OCP\Files\Mount\IMountPoint
+        */
+       public function getMountPoint();
 }
index b4fdd91f512fc6637c65113a503b94d6b04b7199..6bb1b4e75d1c115c9bddc7be184290fccb89e0ce 100644 (file)
@@ -24,7 +24,7 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase {
 
                $info = new \OC\Files\FileInfo('/test.txt', null, null, array(
                        'permissions'=>\OCP\Constants::PERMISSION_ALL
-               ));
+               ), null);
 
                $file = new OC_Connector_Sabre_File($view, $info);
 
@@ -59,7 +59,7 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase {
 
                $info = new \OC\Files\FileInfo('/test.txt', null, null, array(
                        'permissions' => \OCP\Constants::PERMISSION_ALL
-               ));
+               ), null);
 
                $file = new OC_Connector_Sabre_File($view, $info);
 
@@ -83,7 +83,7 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase {
 
                $info = new \OC\Files\FileInfo('/super*star.txt', null, null, array(
                        'permissions' => \OCP\Constants::PERMISSION_ALL
-               ));
+               ), null);
                $file = new OC_Connector_Sabre_File($view, $info);
 
                // action
@@ -104,7 +104,7 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase {
 
                $info = new \OC\Files\FileInfo('/super*star.txt', null, null, array(
                        'permissions' => \OCP\Constants::PERMISSION_ALL
-               ));
+               ), null);
                $file = new OC_Connector_Sabre_File($view, $info);
                $file->setName('/super*star.txt');
        }
@@ -136,7 +136,7 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase {
 
                $info = new \OC\Files\FileInfo('/test.txt', null, null, array(
                        'permissions' => \OCP\Constants::PERMISSION_ALL
-               ));
+               ), null);
 
                $file = new OC_Connector_Sabre_File($view, $info);
 
@@ -158,7 +158,7 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase {
 
                $info = new \OC\Files\FileInfo('/test.txt', null, null, array(
                        'permissions' => \OCP\Constants::PERMISSION_ALL
-               ));
+               ), null);
 
                $file = new OC_Connector_Sabre_File($view, $info);
 
@@ -176,7 +176,7 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase {
 
                $info = new \OC\Files\FileInfo('/test.txt', null, null, array(
                        'permissions' => 0
-               ));
+               ), null);
 
                $file = new OC_Connector_Sabre_File($view, $info);
 
@@ -199,7 +199,7 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase {
 
                $info = new \OC\Files\FileInfo('/test.txt', null, null, array(
                        'permissions' => \OCP\Constants::PERMISSION_ALL
-               ));
+               ), null);
 
                $file = new OC_Connector_Sabre_File($view, $info);
 
index d1de46d2ee78b459dab093679ba810c0e5ec9f48..2548066214b5440879ca742508c0473db1dad76d 100644 (file)
@@ -101,7 +101,7 @@ class ObjectTree extends \Test\TestCase {
        private function moveTest($source, $dest, $updatables, $deletables) {
                $view = new TestDoubleFileView($updatables, $deletables);
 
-               $info = new FileInfo('', null, null, array());
+               $info = new FileInfo('', null, null, array(), null);
 
                $rootDir = new OC_Connector_Sabre_Directory($view, $info);
                $objectTree = $this->getMock('\OC\Connector\Sabre\ObjectTree',
index a1d2266edf7856be2b3b6d88c571e9765c46c453..e3b8019b4cada22ebdaf1c7a98ebfe1521530cce 100644 (file)
@@ -22,7 +22,7 @@ class File extends \Test\TestCase {
        }
 
        protected function getFileInfo($data) {
-               return new FileInfo('', null, '', $data);
+               return new FileInfo('', null, '', $data, null);
        }
 
        public function testDelete() {
index e69a277697918549048e81a747d53d818c1285f5..bcd9cc93b5e87147fa989c40c0f367bd5136225a 100644 (file)
@@ -25,7 +25,7 @@ class Folder extends \Test\TestCase {
        }
 
        protected function getFileInfo($data) {
-               return new FileInfo('', null, '', $data);
+               return new FileInfo('', null, '', $data, null);
        }
 
        public function testDelete() {
index 4697479ba95af0801a40221da1dfd9ed41a96b32..49a2006c767aa2d5272a003b61169887c8f9a685 100644 (file)
@@ -19,7 +19,7 @@ class Node extends \Test\TestCase {
        }
 
        protected function getFileInfo($data) {
-               return new FileInfo('', null, '', $data);
+               return new FileInfo('', null, '', $data, null);
        }
 
        public function testStat() {
index 35bd462157ebc26e2df6617c94a64aaf2f89e65d..a763428209c02114086d6aa868697179c266076b 100644 (file)
@@ -21,7 +21,7 @@ class Root extends \Test\TestCase {
        }
 
        protected function getFileInfo($data) {
-               return new FileInfo('', null, '', $data);
+               return new FileInfo('', null, '', $data, null);
        }
 
        public function testGet() {