summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2014-11-24 15:54:42 +0100
committerRobin Appelman <icewind@owncloud.com>2014-12-04 16:47:27 +0100
commitf4701d7721453b8356a5be401bb5063d22f851c6 (patch)
treeb27f76b8c02e658ac5e4b599a0ee4e4839b5de19 /lib
parentf3213571bb2609a7f279fd5254f872083b3ea91a (diff)
downloadnextcloud-server-f4701d7721453b8356a5be401bb5063d22f851c6.tar.gz
nextcloud-server-f4701d7721453b8356a5be401bb5063d22f851c6.zip
Add public api for mount configurations
Diffstat (limited to 'lib')
-rw-r--r--lib/private/files/config/mountprovidercollection.php55
-rw-r--r--lib/private/files/filesystem.php17
-rw-r--r--lib/private/files/mount/manager.php16
-rw-r--r--lib/private/files/mount/mountpoint.php (renamed from lib/private/files/mount/mount.php)22
-rw-r--r--lib/private/files/node/folder.php2
-rw-r--r--lib/private/files/node/root.php14
-rw-r--r--lib/private/files/storage/storagefactory.php (renamed from lib/private/files/storage/loader.php)13
-rw-r--r--lib/private/files/utils/scanner.php4
-rw-r--r--lib/private/files/view.php4
-rw-r--r--lib/private/server.php12
-rw-r--r--lib/public/files/config/imountprovider.php26
-rw-r--r--lib/public/files/config/imountprovidercollection.php31
-rw-r--r--lib/public/files/mount/imountpoint.php58
-rw-r--r--lib/public/files/storage/istoragefactory.php32
-rw-r--r--lib/public/iservercontainer.php5
15 files changed, 268 insertions, 43 deletions
diff --git a/lib/private/files/config/mountprovidercollection.php b/lib/private/files/config/mountprovidercollection.php
new file mode 100644
index 00000000000..49d026f1bda
--- /dev/null
+++ b/lib/private/files/config/mountprovidercollection.php
@@ -0,0 +1,55 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Files\Config;
+
+use OCP\Files\Config\IMountProviderCollection;
+use OCP\Files\Config\IMountProvider;
+use OCP\Files\Storage\IStorageFactory;
+use OCP\IUser;
+
+class MountProviderCollection implements IMountProviderCollection {
+ /**
+ * @var \OCP\Files\Config\IMountProvider[]
+ */
+ private $providers = array();
+
+ /**
+ * @var \OCP\Files\Storage\IStorageFactory
+ */
+ private $loader;
+
+ /**
+ * @param \OCP\Files\Storage\IStorageFactory $loader
+ */
+ public function __construct(IStorageFactory $loader) {
+ $this->loader = $loader;
+ }
+
+ /**
+ * Get all configured mount points for the user
+ *
+ * @param \OCP\IUser $user
+ * @return \OCP\Files\Mount\IMountPoint[]
+ */
+ public function getMountsForUser(IUser $user) {
+ $loader = $this->loader;
+ return array_reduce($this->providers, function ($mounts, IMountProvider $provider) use ($user, $loader) {
+ return array_merge($mounts, $provider->getMountsForUser($user, $loader));
+ }, array());
+ }
+
+ /**
+ * Add a provider for mount points
+ *
+ * @param \OCP\Files\Config\IMountProvider $provider
+ */
+ public function registerProvider(IMountProvider $provider) {
+ $this->providers[] = $provider;
+ }
+}
diff --git a/lib/private/files/filesystem.php b/lib/private/files/filesystem.php
index 6c8fa8c90ba..90643839e22 100644
--- a/lib/private/files/filesystem.php
+++ b/lib/private/files/filesystem.php
@@ -30,7 +30,7 @@
namespace OC\Files;
-use OC\Files\Storage\Loader;
+use OC\Files\Storage\StorageFactory;
class Filesystem {
@@ -165,7 +165,7 @@ class Filesystem {
const signal_param_users = 'users';
/**
- * @var \OC\Files\Storage\Loader $loader
+ * @var \OC\Files\Storage\StorageFactory $loader
*/
private static $loader;
@@ -183,7 +183,7 @@ class Filesystem {
public static function getLoader() {
if (!self::$loader) {
- self::$loader = new Loader();
+ self::$loader = new StorageFactory();
}
return self::$loader;
}
@@ -250,7 +250,7 @@ class Filesystem {
/**
* @param string $id
- * @return Mount\Mount[]
+ * @return Mount\MountPoint[]
*/
public static function getMountByStorageId($id) {
if (!self::$mounts) {
@@ -261,7 +261,7 @@ class Filesystem {
/**
* @param int $id
- * @return Mount\Mount[]
+ * @return Mount\MountPoint[]
*/
public static function getMountByNumericId($id) {
if (!self::$mounts) {
@@ -370,6 +370,11 @@ class Filesystem {
self::mountCacheDir($user);
// Chance to mount for other storages
+ if($userObject) {
+ $mountConfigManager = \OC::$server->getMountProviderCollection();
+ $mounts = $mountConfigManager->getMountsForUser($userObject);
+ array_walk($mounts, array(self::$mounts, 'addMount'));
+ }
\OC_Hook::emit('OC_Filesystem', 'post_initMountPoints', array('user' => $user, 'user_dir' => $root));
}
@@ -447,7 +452,7 @@ class Filesystem {
if (!self::$mounts) {
\OC_Util::setupFS();
}
- $mount = new Mount\Mount($class, $mountpoint, $arguments, self::getLoader());
+ $mount = new Mount\MountPoint($class, $mountpoint, $arguments, self::getLoader());
self::$mounts->addMount($mount);
}
diff --git a/lib/private/files/mount/manager.php b/lib/private/files/mount/manager.php
index 0ccf42941de..8472ebc976a 100644
--- a/lib/private/files/mount/manager.php
+++ b/lib/private/files/mount/manager.php
@@ -12,14 +12,14 @@ use \OC\Files\Filesystem;
class Manager {
/**
- * @var Mount[]
+ * @var MountPoint[]
*/
private $mounts = array();
/**
- * @param Mount $mount
+ * @param MountPoint $mount
*/
- public function addMount(Mount $mount) {
+ public function addMount(MountPoint $mount) {
$this->mounts[$mount->getMountPoint()] = $mount;
}
@@ -47,7 +47,7 @@ class Manager {
* Find the mount for $path
*
* @param string $path
- * @return Mount
+ * @return MountPoint
*/
public function find($path) {
\OC_Util::setupFS();
@@ -75,7 +75,7 @@ class Manager {
* Find all mounts in $path
*
* @param string $path
- * @return Mount[]
+ * @return MountPoint[]
*/
public function findIn($path) {
\OC_Util::setupFS();
@@ -99,7 +99,7 @@ class Manager {
* Find mounts by storage id
*
* @param string $id
- * @return Mount[]
+ * @return MountPoint[]
*/
public function findByStorageId($id) {
\OC_Util::setupFS();
@@ -116,7 +116,7 @@ class Manager {
}
/**
- * @return Mount[]
+ * @return MountPoint[]
*/
public function getAll() {
return $this->mounts;
@@ -126,7 +126,7 @@ class Manager {
* Find mounts by numeric storage id
*
* @param int $id
- * @return Mount[]
+ * @return MountPoint[]
*/
public function findByNumericId($id) {
$storageId = \OC\Files\Cache\Storage::getStorageId($id);
diff --git a/lib/private/files/mount/mount.php b/lib/private/files/mount/mountpoint.php
index 48c9d88c23c..b2c50f9d881 100644
--- a/lib/private/files/mount/mount.php
+++ b/lib/private/files/mount/mountpoint.php
@@ -9,10 +9,11 @@
namespace OC\Files\Mount;
use \OC\Files\Filesystem;
-use OC\Files\Storage\Loader;
+use OC\Files\Storage\StorageFactory;
use OC\Files\Storage\Storage;
+use OCP\Files\Mount\IMountPoint;
-class Mount {
+class MountPoint implements IMountPoint {
/**
* @var \OC\Files\Storage\Storage $storage
*/
@@ -23,7 +24,7 @@ class Mount {
protected $mountPoint;
/**
- * @var \OC\Files\Storage\Loader $loader
+ * @var \OC\Files\Storage\StorageFactory $loader
*/
private $loader;
@@ -31,14 +32,14 @@ class Mount {
* @param string|\OC\Files\Storage\Storage $storage
* @param string $mountpoint
* @param array $arguments (optional)\
- * @param \OC\Files\Storage\Loader $loader
+ * @param \OCP\Files\Storage\IStorageFactory $loader
*/
public function __construct($storage, $mountpoint, $arguments = null, $loader = null) {
if (is_null($arguments)) {
$arguments = array();
}
if (is_null($loader)) {
- $this->loader = new Loader();
+ $this->loader = new StorageFactory();
} else {
$this->loader = $loader;
}
@@ -68,15 +69,6 @@ class Mount {
}
/**
- * get name of the mount point
- *
- * @return string
- */
- public function getMountPointName() {
- return basename(rtrim($this->mountPoint, '/'));
- }
-
- /**
* @param string $mountPoint new mount point
*/
public function setMountPoint($mountPoint) {
@@ -91,7 +83,7 @@ class Mount {
private function createStorage() {
if (class_exists($this->class)) {
try {
- return $this->loader->load($this->mountPoint, $this->class, $this->arguments);
+ return $this->loader->getInstance($this->mountPoint, $this->class, $this->arguments);
} catch (\Exception $exception) {
if ($this->mountPoint === '/') {
// the root storage could not be initialized, show the user!
diff --git a/lib/private/files/node/folder.php b/lib/private/files/node/folder.php
index 54a699be532..6fdcff13e1c 100644
--- a/lib/private/files/node/folder.php
+++ b/lib/private/files/node/folder.php
@@ -301,7 +301,7 @@ class Folder extends Node implements \OCP\Files\Folder {
$nodes = array();
foreach ($mounts as $mount) {
/**
- * @var \OC\Files\Mount\Mount $mount
+ * @var \OC\Files\Mount\MountPoint $mount
*/
if ($mount->getStorage()) {
$cache = $mount->getStorage()->getCache();
diff --git a/lib/private/files/node/root.php b/lib/private/files/node/root.php
index 1e8387dc5cb..35132f5458d 100644
--- a/lib/private/files/node/root.php
+++ b/lib/private/files/node/root.php
@@ -10,7 +10,7 @@ namespace OC\Files\Node;
use OC\Files\Cache\Cache;
use OC\Files\Mount\Manager;
-use OC\Files\Mount\Mount;
+use OC\Files\Mount\MountPoint;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OC\Hooks\Emitter;
@@ -106,13 +106,13 @@ class Root extends Folder implements Emitter {
* @param array $arguments
*/
public function mount($storage, $mountPoint, $arguments = array()) {
- $mount = new Mount($storage, $mountPoint, $arguments);
+ $mount = new MountPoint($storage, $mountPoint, $arguments);
$this->mountManager->addMount($mount);
}
/**
* @param string $mountPoint
- * @return \OC\Files\Mount\Mount
+ * @return \OC\Files\Mount\MountPoint
*/
public function getMount($mountPoint) {
return $this->mountManager->find($mountPoint);
@@ -120,7 +120,7 @@ class Root extends Folder implements Emitter {
/**
* @param string $mountPoint
- * @return \OC\Files\Mount\Mount[]
+ * @return \OC\Files\Mount\MountPoint[]
*/
public function getMountsIn($mountPoint) {
return $this->mountManager->findIn($mountPoint);
@@ -128,7 +128,7 @@ class Root extends Folder implements Emitter {
/**
* @param string $storageId
- * @return \OC\Files\Mount\Mount[]
+ * @return \OC\Files\Mount\MountPoint[]
*/
public function getMountByStorageId($storageId) {
return $this->mountManager->findByStorageId($storageId);
@@ -136,14 +136,14 @@ class Root extends Folder implements Emitter {
/**
* @param int $numericId
- * @return Mount[]
+ * @return MountPoint[]
*/
public function getMountByNumericStorageId($numericId) {
return $this->mountManager->findByNumericId($numericId);
}
/**
- * @param \OC\Files\Mount\Mount $mount
+ * @param \OC\Files\Mount\MountPoint $mount
*/
public function unMount($mount) {
$this->mountManager->remove($mount);
diff --git a/lib/private/files/storage/loader.php b/lib/private/files/storage/storagefactory.php
index c75a0a976a7..c9e8d422f9d 100644
--- a/lib/private/files/storage/loader.php
+++ b/lib/private/files/storage/storagefactory.php
@@ -8,7 +8,9 @@
namespace OC\Files\Storage;
-class Loader {
+use OCP\Files\Storage\IStorageFactory;
+
+class StorageFactory implements IStorageFactory {
/**
* @var callable[] $storageWrappers
*/
@@ -19,6 +21,7 @@ class Loader {
*
* $callback should be a function of type (string $mountPoint, Storage $storage) => Storage
*
+ * @param string $wrapperName
* @param callable $callback
*/
public function addStorageWrapper($wrapperName, $callback) {
@@ -26,15 +29,21 @@ class Loader {
}
/**
+ * Create an instance of a storage and apply the registered storage wrappers
+ *
* @param string|boolean $mountPoint
* @param string $class
+ * @param array $arguments
+ * @return \OCP\Files\Storage
*/
- public function load($mountPoint, $class, $arguments) {
+ public function getInstance($mountPoint, $class, $arguments) {
return $this->wrap($mountPoint, new $class($arguments));
}
/**
* @param string|boolean $mountPoint
+ * @param \OCP\Files\Storage $storage
+ * @return \OCP\Files\Storage
*/
public function wrap($mountPoint, $storage) {
foreach ($this->storageWrappers as $wrapper) {
diff --git a/lib/private/files/utils/scanner.php b/lib/private/files/utils/scanner.php
index adb66497be0..19a2ed38e1b 100644
--- a/lib/private/files/utils/scanner.php
+++ b/lib/private/files/utils/scanner.php
@@ -53,7 +53,7 @@ class Scanner extends PublicEmitter {
* get all storages for $dir
*
* @param string $dir
- * @return \OC\Files\Mount\Mount[]
+ * @return \OC\Files\Mount\MountPoint[]
*/
protected function getMounts($dir) {
//TODO: move to the node based fileapi once that's done
@@ -72,7 +72,7 @@ class Scanner extends PublicEmitter {
/**
* attach listeners to the scanner
*
- * @param \OC\Files\Mount\Mount $mount
+ * @param \OC\Files\Mount\MountPoint $mount
*/
protected function attachListener($mount) {
$scanner = $mount->getStorage()->getScanner();
diff --git a/lib/private/files/view.php b/lib/private/files/view.php
index 331ab9ba6cd..4b3d167f8e9 100644
--- a/lib/private/files/view.php
+++ b/lib/private/files/view.php
@@ -465,7 +465,7 @@ class View {
if ($internalPath1 === '' and $mount instanceof MoveableMount) {
if ($this->isTargetAllowed($absolutePath2)) {
/**
- * @var \OC\Files\Mount\Mount | \OC\Files\Mount\MoveableMount $mount
+ * @var \OC\Files\Mount\MountPoint | \OC\Files\Mount\MoveableMount $mount
*/
$sourceMountPoint = $mount->getMountPoint();
$result = $mount->moveMount($absolutePath2);
@@ -1227,7 +1227,7 @@ class View {
$mounts = array_reverse($mounts);
foreach ($mounts as $mount) {
/**
- * @var \OC\Files\Mount\Mount $mount
+ * @var \OC\Files\Mount\MountPoint $mount
*/
if ($mount->getStorage()) {
$cache = $mount->getStorage()->getCache();
diff --git a/lib/private/server.php b/lib/private/server.php
index 7bd7f8ca45d..971ffca943d 100644
--- a/lib/private/server.php
+++ b/lib/private/server.php
@@ -9,6 +9,7 @@ use OC\Cache\UserCache;
use OC\Diagnostics\NullQueryLogger;
use OC\Diagnostics\EventLogger;
use OC\Diagnostics\QueryLogger;
+use OC\Files\Config\StorageManager;
use OC\Security\CertificateManager;
use OC\DB\ConnectionWrapper;
use OC\Files\Node\Root;
@@ -250,6 +251,10 @@ class Server extends SimpleContainer implements IServerContainer {
$groupManager = $c->getGroupManager();
return new \OC\App\AppManager($userSession, $appConfig, $groupManager);
});
+ $this->registerService('MountConfigManager', function () {
+ $loader = \OC\Files\Filesystem::getLoader();
+ return new \OC\Files\Config\MountProviderCollection($loader);
+ });
}
/**
@@ -647,4 +652,11 @@ class Server extends SimpleContainer implements IServerContainer {
function getWebRoot() {
return $this->webRoot;
}
+
+ /**
+ * @return \OCP\Files\Config\IMountProviderCollection
+ */
+ function getMountProviderCollection(){
+ return $this->query('MountConfigManager');
+ }
}
diff --git a/lib/public/files/config/imountprovider.php b/lib/public/files/config/imountprovider.php
new file mode 100644
index 00000000000..5a39e6c8948
--- /dev/null
+++ b/lib/public/files/config/imountprovider.php
@@ -0,0 +1,26 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OCP\Files\Config;
+
+use OCP\Files\Storage\IStorageFactory;
+use OCP\IUser;
+
+/**
+ * Provides
+ */
+interface IMountProvider {
+ /**
+ * Get all mountpoints applicable for the user
+ *
+ * @param \OCP\IUser $user
+ * @param \OCP\Files\Storage\IStorageFactory $loader
+ * @return \OCP\Files\Mount\IMountPoint[]
+ */
+ public function getMountsForUser(IUser $user, IStorageFactory $loader);
+}
diff --git a/lib/public/files/config/imountprovidercollection.php b/lib/public/files/config/imountprovidercollection.php
new file mode 100644
index 00000000000..52797414ab9
--- /dev/null
+++ b/lib/public/files/config/imountprovidercollection.php
@@ -0,0 +1,31 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OCP\Files\Config;
+
+use OCP\IUser;
+
+/**
+ * Manages the different mount providers
+ */
+interface IMountProviderCollection {
+ /**
+ * Get all configured mount points for the user
+ *
+ * @param \OCP\IUser $user
+ * @return \OCP\Files\Mount\IMountPoint[]
+ */
+ public function getMountsForUser(IUser $user);
+
+ /**
+ * Add a provider for mount points
+ *
+ * @param \OCP\Files\Config\IMountProvider $provider
+ */
+ public function registerProvider(IMountProvider $provider);
+}
diff --git a/lib/public/files/mount/imountpoint.php b/lib/public/files/mount/imountpoint.php
new file mode 100644
index 00000000000..dac634bae4c
--- /dev/null
+++ b/lib/public/files/mount/imountpoint.php
@@ -0,0 +1,58 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OCP\Files\Mount;
+
+/**
+ * A storage mounted to folder on the filesystem
+ */
+interface IMountPoint {
+
+ /**
+ * get complete path to the mount point
+ *
+ * @return string
+ */
+ public function getMountPoint();
+
+ /**
+ * Set the mountpoint
+ *
+ * @param string $mountPoint new mount point
+ */
+ public function setMountPoint($mountPoint);
+
+ /**
+ * Get the storage that is mounted
+ *
+ * @return \OC\Files\Storage\Storage
+ */
+ public function getStorage();
+
+ /**
+ * Get the id of the storages
+ *
+ * @return string
+ */
+ public function getStorageId();
+
+ /**
+ * Get the path relative to the mountpoint
+ *
+ * @param string $path absolute path to a file or folder
+ * @return string
+ */
+ public function getInternalPath($path);
+
+ /**
+ * Apply a storage wrapper to the mounted storage
+ *
+ * @param callable $wrapper
+ */
+ public function wrapStorage($wrapper);
+}
diff --git a/lib/public/files/storage/istoragefactory.php b/lib/public/files/storage/istoragefactory.php
new file mode 100644
index 00000000000..769d7011de4
--- /dev/null
+++ b/lib/public/files/storage/istoragefactory.php
@@ -0,0 +1,32 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OCP\Files\Storage;
+
+/**
+ * Creates storage instances and manages and applies storage wrappers
+ */
+interface IStorageFactory {
+ /**
+ * allow modifier storage behaviour by adding wrappers around storages
+ *
+ * $callback should be a function of type (string $mountPoint, Storage $storage) => Storage
+ *
+ * @param string $wrapperName
+ * @param callable $callback
+ */
+ public function addStorageWrapper($wrapperName, $callback);
+
+ /**
+ * @param string|boolean $mountPoint
+ * @param string $class
+ * @param array $arguments
+ * @return \OCP\Files\Storage
+ */
+ public function getInstance($mountPoint, $class, $arguments);
+}
diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php
index 301f47c68fa..657c9be423b 100644
--- a/lib/public/iservercontainer.php
+++ b/lib/public/iservercontainer.php
@@ -305,4 +305,9 @@ interface IServerContainer {
* @return string
*/
function getWebRoot();
+
+ /**
+ * @return \OCP\Files\Config\IMountProviderCollection
+ */
+ function getMountProviderCollection();
}