From fd854247423de0d74b05b44bf16572d2be943819 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 16 Dec 2014 14:24:48 +0100 Subject: [PATCH] Add getMountPoint to FileInfo --- apps/files/tests/ajax_rename.php | 2 +- apps/files/tests/helper.php | 3 +- apps/files_trashbin/lib/helper.php | 6 ++- lib/private/connector/sabre/directory.php | 2 +- lib/private/connector/sabre/objecttree.php | 6 ++- lib/private/files/fileinfo.php | 21 ++++++++++- lib/private/files/node/node.php | 4 ++ lib/private/files/view.php | 43 +++++++++++++++------- lib/public/files/fileinfo.php | 7 ++++ tests/lib/connector/sabre/file.php | 16 ++++---- tests/lib/connector/sabre/objecttree.php | 2 +- tests/lib/files/node/file.php | 2 +- tests/lib/files/node/folder.php | 2 +- tests/lib/files/node/node.php | 2 +- tests/lib/files/node/root.php | 2 +- 15 files changed, 86 insertions(+), 34 deletions(-) diff --git a/apps/files/tests/ajax_rename.php b/apps/files/tests/ajax_rename.php index 48aed05823..1cfecf9e58 100644 --- a/apps/files/tests/ajax_rename.php +++ b/apps/files/tests/ajax_rename.php @@ -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); diff --git a/apps/files/tests/helper.php b/apps/files/tests/helper.php index 1b7c8eef43..ea96e41d1d 100644 --- a/apps/files/tests/helper.php +++ b/apps/files/tests/helper.php @@ -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 ); } diff --git a/apps/files_trashbin/lib/helper.php b/apps/files_trashbin/lib/helper.php index c99662480d..d9e69b71aa 100644 --- a/apps/files_trashbin/lib/helper.php +++ b/apps/files_trashbin/lib/helper.php @@ -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); diff --git a/lib/private/connector/sabre/directory.php b/lib/private/connector/sabre/directory.php index ec5f82f9da..bbe0f3452a 100644 --- a/lib/private/connector/sabre/directory.php +++ b/lib/private/connector/sabre/directory.php @@ -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) { diff --git a/lib/private/connector/sabre/objecttree.php b/lib/private/connector/sabre/objecttree.php index 14a55b5cad..d2759d7a3b 100644 --- a/lib/private/connector/sabre/objecttree.php +++ b/lib/private/connector/sabre/objecttree.php @@ -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; } diff --git a/lib/private/files/fileinfo.php b/lib/private/files/fileinfo.php index 8bab51f073..e4a397dcca 100644 --- a/lib/private/files/fileinfo.php +++ b/lib/private/files/fileinfo.php @@ -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; + } } diff --git a/lib/private/files/node/node.php b/lib/private/files/node/node.php index 87d4a4b915..17907a5304 100644 --- a/lib/private/files/node/node.php +++ b/lib/private/files/node/node.php @@ -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(); + } } diff --git a/lib/private/files/view.php b/lib/private/files/view.php index c01763cdad..40789621df 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -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); } } } diff --git a/lib/public/files/fileinfo.php b/lib/public/files/fileinfo.php index 3a407ed67c..ec68ed475c 100644 --- a/lib/public/files/fileinfo.php +++ b/lib/public/files/fileinfo.php @@ -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(); } diff --git a/tests/lib/connector/sabre/file.php b/tests/lib/connector/sabre/file.php index b4fdd91f51..6bb1b4e75d 100644 --- a/tests/lib/connector/sabre/file.php +++ b/tests/lib/connector/sabre/file.php @@ -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); diff --git a/tests/lib/connector/sabre/objecttree.php b/tests/lib/connector/sabre/objecttree.php index d1de46d2ee..2548066214 100644 --- a/tests/lib/connector/sabre/objecttree.php +++ b/tests/lib/connector/sabre/objecttree.php @@ -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', diff --git a/tests/lib/files/node/file.php b/tests/lib/files/node/file.php index a1d2266edf..e3b8019b4c 100644 --- a/tests/lib/files/node/file.php +++ b/tests/lib/files/node/file.php @@ -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() { diff --git a/tests/lib/files/node/folder.php b/tests/lib/files/node/folder.php index e69a277697..bcd9cc93b5 100644 --- a/tests/lib/files/node/folder.php +++ b/tests/lib/files/node/folder.php @@ -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() { diff --git a/tests/lib/files/node/node.php b/tests/lib/files/node/node.php index 4697479ba9..49a2006c76 100644 --- a/tests/lib/files/node/node.php +++ b/tests/lib/files/node/node.php @@ -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() { diff --git a/tests/lib/files/node/root.php b/tests/lib/files/node/root.php index 35bd462157..a763428209 100644 --- a/tests/lib/files/node/root.php +++ b/tests/lib/files/node/root.php @@ -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() {