diff options
author | Morris Jobke <hey@morrisjobke.de> | 2014-12-18 23:38:14 +0100 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2014-12-18 23:38:14 +0100 |
commit | 75e8b39826c9278288b8dc02dc19f0ca060080b6 (patch) | |
tree | dcb2081b7b8779333d11b3adbf03d6b2c0ea4c76 /lib | |
parent | 891474b0d6b8cc77a8480cd91f1e48ad3bc3e73b (diff) | |
parent | 2eab0f21211762869db74891c2e2611f96bfef15 (diff) | |
download | nextcloud-server-75e8b39826c9278288b8dc02dc19f0ca060080b6.tar.gz nextcloud-server-75e8b39826c9278288b8dc02dc19f0ca060080b6.zip |
Merge pull request #12879 from owncloud/mountconfig
Add mount specific options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/connector/sabre/directory.php | 2 | ||||
-rw-r--r-- | lib/private/connector/sabre/objecttree.php | 6 | ||||
-rw-r--r-- | lib/private/files/fileinfo.php | 21 | ||||
-rw-r--r-- | lib/private/files/mount/mountpoint.php | 33 | ||||
-rw-r--r-- | lib/private/files/node/node.php | 4 | ||||
-rw-r--r-- | lib/private/files/view.php | 43 | ||||
-rw-r--r-- | lib/private/preview.php | 5 | ||||
-rw-r--r-- | lib/public/files/fileinfo.php | 7 | ||||
-rw-r--r-- | lib/public/files/mount/imountpoint.php | 9 |
9 files changed, 111 insertions, 19 deletions
diff --git a/lib/private/connector/sabre/directory.php b/lib/private/connector/sabre/directory.php index ec5f82f9daa..bbe0f3452a7 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 14a55b5cada..d2759d7a3ba 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 8bab51f0737..e4a397dcca2 100644 --- a/lib/private/files/fileinfo.php +++ b/lib/private/files/fileinfo.php @@ -30,14 +30,23 @@ 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/mount/mountpoint.php b/lib/private/files/mount/mountpoint.php index b2c50f9d881..77a51a17020 100644 --- a/lib/private/files/mount/mountpoint.php +++ b/lib/private/files/mount/mountpoint.php @@ -20,10 +20,23 @@ class MountPoint implements IMountPoint { protected $storage = null; protected $class; protected $storageId; + + /** + * Configuration options for the storage backend + * + * @var array + */ protected $arguments = array(); protected $mountPoint; /** + * Mount specific options + * + * @var array + */ + protected $mountOptions = array(); + + /** * @var \OC\Files\Storage\StorageFactory $loader */ private $loader; @@ -31,10 +44,11 @@ class MountPoint implements IMountPoint { /** * @param string|\OC\Files\Storage\Storage $storage * @param string $mountpoint - * @param array $arguments (optional)\ + * @param array $arguments (optional) configuration for the storage backend * @param \OCP\Files\Storage\IStorageFactory $loader + * @param array $mountOptions mount specific options */ - public function __construct($storage, $mountpoint, $arguments = null, $loader = null) { + public function __construct($storage, $mountpoint, $arguments = null, $loader = null, $mountOptions = null) { if (is_null($arguments)) { $arguments = array(); } @@ -44,6 +58,10 @@ class MountPoint implements IMountPoint { $this->loader = $loader; } + if (!is_null($mountOptions)) { + $this->mountOptions = $mountOptions; + } + $mountpoint = $this->formatPath($mountpoint); if ($storage instanceof Storage) { $this->class = get_class($storage); @@ -161,4 +179,15 @@ class MountPoint implements IMountPoint { public function wrapStorage($wrapper) { $this->storage = $wrapper($this->mountPoint, $this->getStorage()); } + + /** + * Get a mount option + * + * @param string $name Name of the mount option to get + * @param mixed $default Default value for the mount option + * @return mixed + */ + public function getOption($name, $default) { + return isset($this->mountOptions[$name]) ? $this->mountOptions[$name] : $default; + } } diff --git a/lib/private/files/node/node.php b/lib/private/files/node/node.php index 87d4a4b9156..17907a53044 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 c21ec88ae0c..f1c15e197d9 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -113,6 +113,19 @@ class View { } /** + * 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 * * @param string $path @@ -943,7 +956,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); } /** @@ -960,8 +973,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(); @@ -995,7 +1010,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 @@ -1003,7 +1018,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(''); @@ -1049,7 +1064,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); } } } @@ -1159,8 +1174,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(''); @@ -1170,13 +1186,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(''); @@ -1187,7 +1204,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/private/preview.php b/lib/private/preview.php index 7305bf1cc0e..a586c94fd11 100644 --- a/lib/private/preview.php +++ b/lib/private/preview.php @@ -922,6 +922,11 @@ class Preview { return false; } + $mount = $file->getMountPoint(); + if ($mount and !$mount->getOption('previews', true)){ + return false; + } + //check if there are preview backends if (empty(self::$providers)) { self::initProviders(); diff --git a/lib/public/files/fileinfo.php b/lib/public/files/fileinfo.php index 3a407ed67ca..ec68ed475c5 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/lib/public/files/mount/imountpoint.php b/lib/public/files/mount/imountpoint.php index dac634bae4c..af7819ae160 100644 --- a/lib/public/files/mount/imountpoint.php +++ b/lib/public/files/mount/imountpoint.php @@ -55,4 +55,13 @@ interface IMountPoint { * @param callable $wrapper */ public function wrapStorage($wrapper); + + /** + * Get a mount option + * + * @param string $name Name of the mount option to get + * @param mixed $default Default value for the mount option + * @return mixed + */ + public function getOption($name, $default); } |