]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add public api for mount configurations
authorRobin Appelman <icewind@owncloud.com>
Mon, 24 Nov 2014 14:54:42 +0000 (15:54 +0100)
committerRobin Appelman <icewind@owncloud.com>
Thu, 4 Dec 2014 15:47:27 +0000 (16:47 +0100)
24 files changed:
apps/files_sharing/lib/external/manager.php
apps/files_sharing/lib/external/mount.php
apps/files_sharing/lib/sharedmount.php
lib/private/files/config/mountprovidercollection.php [new file with mode: 0644]
lib/private/files/filesystem.php
lib/private/files/mount/manager.php
lib/private/files/mount/mount.php [deleted file]
lib/private/files/mount/mountpoint.php [new file with mode: 0644]
lib/private/files/node/folder.php
lib/private/files/node/root.php
lib/private/files/storage/loader.php [deleted file]
lib/private/files/storage/storagefactory.php [new file with mode: 0644]
lib/private/files/utils/scanner.php
lib/private/files/view.php
lib/private/server.php
lib/public/files/config/imountprovider.php [new file with mode: 0644]
lib/public/files/config/imountprovidercollection.php [new file with mode: 0644]
lib/public/files/mount/imountpoint.php [new file with mode: 0644]
lib/public/files/storage/istoragefactory.php [new file with mode: 0644]
lib/public/iservercontainer.php
tests/lib/files/mount/manager.php
tests/lib/files/mount/mount.php
tests/lib/files/node/folder.php
tests/lib/files/utils/scanner.php

index 8176302a86a25b5706af7f1a7242d583ab9da075..762fe31eb62d6ba88426dd9cc365878d2ee8f589 100644 (file)
@@ -24,7 +24,7 @@ class Manager {
        private $mountManager;
 
        /**
-        * @var \OC\Files\Storage\Loader
+        * @var \OC\Files\Storage\StorageFactory
         */
        private $storageLoader;
 
@@ -37,10 +37,10 @@ class Manager {
         * @param \OCP\IDBConnection $connection
         * @param \OC\Files\Mount\Manager $mountManager
         * @param \OC\User\Session $userSession
-        * @param \OC\Files\Storage\Loader $storageLoader
+        * @param \OC\Files\Storage\StorageFactory $storageLoader
         */
        public function __construct(\OCP\IDBConnection $connection, \OC\Files\Mount\Manager $mountManager,
-                                                               \OC\Files\Storage\Loader $storageLoader, \OC\User\Session $userSession) {
+                                                               \OC\Files\Storage\StorageFactory $storageLoader, \OC\User\Session $userSession) {
                $this->connection = $connection;
                $this->mountManager = $mountManager;
                $this->userSession = $userSession;
index e564dded69a00b0c120e832fcbb96a0e9e829295..6fd9882cb2a4bd3f986903eeb02f8c204ba57270 100644 (file)
@@ -8,9 +8,10 @@
 
 namespace OCA\Files_Sharing\External;
 
+use OC\Files\Mount\MountPoint;
 use OC\Files\Mount\MoveableMount;
 
-class Mount extends \OC\Files\Mount\Mount implements MoveableMount {
+class Mount extends MountPoint implements MoveableMount {
 
        /**
         * @var \OCA\Files_Sharing\External\Manager
@@ -22,7 +23,7 @@ class Mount extends \OC\Files\Mount\Mount implements MoveableMount {
         * @param string $mountpoint
         * @param array $options
         * @param \OCA\Files_Sharing\External\Manager $manager
-        * @param \OC\Files\Storage\Loader $loader
+        * @param \OC\Files\Storage\StorageFactory $loader
         */
        public function __construct($storage, $mountpoint, $options, $manager, $loader = null) {
                parent::__construct($storage, $mountpoint, $options, $loader);
index a93ecfb3b1b767375eac50715eb6145c5e2db2ee..d16dbf89ccf7c38e68ee390748f80810b730559c 100644 (file)
@@ -8,13 +8,13 @@
 
 namespace OCA\Files_Sharing;
 
-use OC\Files\Mount\Mount;
+use OC\Files\Mount\MountPoint;
 use OC\Files\Mount\MoveableMount;
 
 /**
  * Shared mount points can be moved by the user
  */
-class SharedMount extends Mount implements MoveableMount {
+class SharedMount extends MountPoint implements MoveableMount {
        /**
         * @var \OC\Files\Storage\Shared $storage
         */
diff --git a/lib/private/files/config/mountprovidercollection.php b/lib/private/files/config/mountprovidercollection.php
new file mode 100644 (file)
index 0000000..49d026f
--- /dev/null
@@ -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;
+       }
+}
index 6c8fa8c90baf37d30ffb2ca5ec372ff74f28be47..90643839e22befe993c71251b002c260135317e5 100644 (file)
@@ -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);
        }
 
index 0ccf42941decd4fbc133e49aaeda6f2d3f1cda71..8472ebc976a4ee94a99d71a8125fbd597734ea16 100644 (file)
@@ -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/mount.php
deleted file mode 100644 (file)
index 48c9d88..0000000
+++ /dev/null
@@ -1,172 +0,0 @@
-<?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 OC\Files\Mount;
-
-use \OC\Files\Filesystem;
-use OC\Files\Storage\Loader;
-use OC\Files\Storage\Storage;
-
-class Mount {
-       /**
-        * @var \OC\Files\Storage\Storage $storage
-        */
-       protected $storage = null;
-       protected $class;
-       protected $storageId;
-       protected $arguments = array();
-       protected $mountPoint;
-
-       /**
-        * @var \OC\Files\Storage\Loader $loader
-        */
-       private $loader;
-
-       /**
-        * @param string|\OC\Files\Storage\Storage $storage
-        * @param string $mountpoint
-        * @param array $arguments (optional)\
-        * @param \OC\Files\Storage\Loader $loader
-        */
-       public function __construct($storage, $mountpoint, $arguments = null, $loader = null) {
-               if (is_null($arguments)) {
-                       $arguments = array();
-               }
-               if (is_null($loader)) {
-                       $this->loader = new Loader();
-               } else {
-                       $this->loader = $loader;
-               }
-
-               $mountpoint = $this->formatPath($mountpoint);
-               if ($storage instanceof Storage) {
-                       $this->class = get_class($storage);
-                       $this->storage = $this->loader->wrap($mountpoint, $storage);
-               } else {
-                       // Update old classes to new namespace
-                       if (strpos($storage, 'OC_Filestorage_') !== false) {
-                               $storage = '\OC\Files\Storage\\' . substr($storage, 15);
-                       }
-                       $this->class = $storage;
-                       $this->arguments = $arguments;
-               }
-               $this->mountPoint = $mountpoint;
-       }
-
-       /**
-        * get complete path to the mount point, relative to data/
-        *
-        * @return string
-        */
-       public function getMountPoint() {
-               return $this->mountPoint;
-       }
-
-       /**
-        * 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) {
-               $this->mountPoint = $mountPoint;
-       }
-
-       /**
-        * create the storage that is mounted
-        *
-        * @return \OC\Files\Storage\Storage
-        */
-       private function createStorage() {
-               if (class_exists($this->class)) {
-                       try {
-                               return $this->loader->load($this->mountPoint, $this->class, $this->arguments);
-                       } catch (\Exception $exception) {
-                               if ($this->mountPoint === '/') {
-                                       // the root storage could not be initialized, show the user!
-                                       throw new \Exception('The root storage could not be initialized. Please contact your local administrator.', $exception->getCode(), $exception);
-                               } else {
-                                       \OC_Log::write('core', $exception->getMessage(), \OC_Log::ERROR);
-                               }
-                               return null;
-                       }
-               } else {
-                       \OC_Log::write('core', 'storage backend ' . $this->class . ' not found', \OC_Log::ERROR);
-                       return null;
-               }
-       }
-
-       /**
-        * @return \OC\Files\Storage\Storage
-        */
-       public function getStorage() {
-               if (is_null($this->storage)) {
-                       $this->storage = $this->createStorage();
-               }
-               return $this->storage;
-       }
-
-       /**
-        * @return string
-        */
-       public function getStorageId() {
-               if (!$this->storageId) {
-                       if (is_null($this->storage)) {
-                               $storage = $this->createStorage(); //FIXME: start using exceptions
-                               if (is_null($storage)) {
-                                       return null;
-                               }
-                               $this->storage = $storage;
-                       }
-                       $this->storageId = $this->storage->getId();
-                       if (strlen($this->storageId) > 64) {
-                               $this->storageId = md5($this->storageId);
-                       }
-               }
-               return $this->storageId;
-       }
-
-       /**
-        * @param string $path
-        * @return string
-        */
-       public function getInternalPath($path) {
-               if ($this->mountPoint === $path or $this->mountPoint . '/' === $path) {
-                       $internalPath = '';
-               } else {
-                       $internalPath = substr($path, strlen($this->mountPoint));
-               }
-               // substr returns false instead of an empty string, we always want a string
-               return (string)$internalPath;
-       }
-
-       /**
-        * @param string $path
-        * @return string
-        */
-       private function formatPath($path) {
-               $path = Filesystem::normalizePath($path);
-               if (strlen($path) > 1) {
-                       $path .= '/';
-               }
-               return $path;
-       }
-
-       /**
-        * @param callable $wrapper
-        */
-       public function wrapStorage($wrapper) {
-               $this->storage = $wrapper($this->mountPoint, $this->getStorage());
-       }
-}
diff --git a/lib/private/files/mount/mountpoint.php b/lib/private/files/mount/mountpoint.php
new file mode 100644 (file)
index 0000000..b2c50f9
--- /dev/null
@@ -0,0 +1,164 @@
+<?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 OC\Files\Mount;
+
+use \OC\Files\Filesystem;
+use OC\Files\Storage\StorageFactory;
+use OC\Files\Storage\Storage;
+use OCP\Files\Mount\IMountPoint;
+
+class MountPoint implements IMountPoint {
+       /**
+        * @var \OC\Files\Storage\Storage $storage
+        */
+       protected $storage = null;
+       protected $class;
+       protected $storageId;
+       protected $arguments = array();
+       protected $mountPoint;
+
+       /**
+        * @var \OC\Files\Storage\StorageFactory $loader
+        */
+       private $loader;
+
+       /**
+        * @param string|\OC\Files\Storage\Storage $storage
+        * @param string $mountpoint
+        * @param array $arguments (optional)\
+        * @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 StorageFactory();
+               } else {
+                       $this->loader = $loader;
+               }
+
+               $mountpoint = $this->formatPath($mountpoint);
+               if ($storage instanceof Storage) {
+                       $this->class = get_class($storage);
+                       $this->storage = $this->loader->wrap($mountpoint, $storage);
+               } else {
+                       // Update old classes to new namespace
+                       if (strpos($storage, 'OC_Filestorage_') !== false) {
+                               $storage = '\OC\Files\Storage\\' . substr($storage, 15);
+                       }
+                       $this->class = $storage;
+                       $this->arguments = $arguments;
+               }
+               $this->mountPoint = $mountpoint;
+       }
+
+       /**
+        * get complete path to the mount point, relative to data/
+        *
+        * @return string
+        */
+       public function getMountPoint() {
+               return $this->mountPoint;
+       }
+
+       /**
+        * @param string $mountPoint new mount point
+        */
+       public function setMountPoint($mountPoint) {
+               $this->mountPoint = $mountPoint;
+       }
+
+       /**
+        * create the storage that is mounted
+        *
+        * @return \OC\Files\Storage\Storage
+        */
+       private function createStorage() {
+               if (class_exists($this->class)) {
+                       try {
+                               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!
+                                       throw new \Exception('The root storage could not be initialized. Please contact your local administrator.', $exception->getCode(), $exception);
+                               } else {
+                                       \OC_Log::write('core', $exception->getMessage(), \OC_Log::ERROR);
+                               }
+                               return null;
+                       }
+               } else {
+                       \OC_Log::write('core', 'storage backend ' . $this->class . ' not found', \OC_Log::ERROR);
+                       return null;
+               }
+       }
+
+       /**
+        * @return \OC\Files\Storage\Storage
+        */
+       public function getStorage() {
+               if (is_null($this->storage)) {
+                       $this->storage = $this->createStorage();
+               }
+               return $this->storage;
+       }
+
+       /**
+        * @return string
+        */
+       public function getStorageId() {
+               if (!$this->storageId) {
+                       if (is_null($this->storage)) {
+                               $storage = $this->createStorage(); //FIXME: start using exceptions
+                               if (is_null($storage)) {
+                                       return null;
+                               }
+                               $this->storage = $storage;
+                       }
+                       $this->storageId = $this->storage->getId();
+                       if (strlen($this->storageId) > 64) {
+                               $this->storageId = md5($this->storageId);
+                       }
+               }
+               return $this->storageId;
+       }
+
+       /**
+        * @param string $path
+        * @return string
+        */
+       public function getInternalPath($path) {
+               if ($this->mountPoint === $path or $this->mountPoint . '/' === $path) {
+                       $internalPath = '';
+               } else {
+                       $internalPath = substr($path, strlen($this->mountPoint));
+               }
+               // substr returns false instead of an empty string, we always want a string
+               return (string)$internalPath;
+       }
+
+       /**
+        * @param string $path
+        * @return string
+        */
+       private function formatPath($path) {
+               $path = Filesystem::normalizePath($path);
+               if (strlen($path) > 1) {
+                       $path .= '/';
+               }
+               return $path;
+       }
+
+       /**
+        * @param callable $wrapper
+        */
+       public function wrapStorage($wrapper) {
+               $this->storage = $wrapper($this->mountPoint, $this->getStorage());
+       }
+}
index 54a699be532d9371bfcb95a0573316a53657d911..6fdcff13e1cbb9ccbf0ecd7334fd8b9121032e3d 100644 (file)
@@ -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();
index 1e8387dc5cbe2a2bfede0dff6d3bedb3cbc39b3f..35132f5458d51af5a9e54f8a3a33ab6c435be109 100644 (file)
@@ -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/loader.php
deleted file mode 100644 (file)
index c75a0a9..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-<?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 OC\Files\Storage;
-
-class Loader {
-       /**
-        * @var callable[] $storageWrappers
-        */
-       private $storageWrappers = array();
-
-       /**
-        * allow modifier storage behaviour by adding wrappers around storages
-        *
-        * $callback should be a function of type (string $mountPoint, Storage $storage) => Storage
-        *
-        * @param callable $callback
-        */
-       public function addStorageWrapper($wrapperName, $callback) {
-               $this->storageWrappers[$wrapperName] = $callback;
-       }
-
-       /**
-        * @param string|boolean $mountPoint
-        * @param string $class
-        */
-       public function load($mountPoint, $class, $arguments) {
-               return $this->wrap($mountPoint, new $class($arguments));
-       }
-
-       /**
-        * @param string|boolean $mountPoint
-        */
-       public function wrap($mountPoint, $storage) {
-               foreach ($this->storageWrappers as $wrapper) {
-                       $storage = $wrapper($mountPoint, $storage);
-               }
-               return $storage;
-       }
-}
diff --git a/lib/private/files/storage/storagefactory.php b/lib/private/files/storage/storagefactory.php
new file mode 100644 (file)
index 0000000..c9e8d42
--- /dev/null
@@ -0,0 +1,54 @@
+<?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 OC\Files\Storage;
+
+use OCP\Files\Storage\IStorageFactory;
+
+class StorageFactory implements IStorageFactory {
+       /**
+        * @var callable[] $storageWrappers
+        */
+       private $storageWrappers = array();
+
+       /**
+        * 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) {
+               $this->storageWrappers[$wrapperName] = $callback;
+       }
+
+       /**
+        * 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 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) {
+                       $storage = $wrapper($mountPoint, $storage);
+               }
+               return $storage;
+       }
+}
index adb66497be074d795e4f40704a0154bc71b8ae09..19a2ed38e1bb5c237e83d9c41aa79dc5b3bacae4 100644 (file)
@@ -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();
index 331ab9ba6cd5589316b6304e1bd4311784173123..4b3d167f8e9deab08524b89c5fbc5fcaef1b900c 100644 (file)
@@ -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();
index 7bd7f8ca45d9d0c8ba52f421080e4df87d0519db..971ffca943d1f97ef326537cf66d8a93297e0d2b 100644 (file)
@@ -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 (file)
index 0000000..5a39e6c
--- /dev/null
@@ -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 (file)
index 0000000..5279741
--- /dev/null
@@ -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 (file)
index 0000000..dac634b
--- /dev/null
@@ -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 (file)
index 0000000..769d701
--- /dev/null
@@ -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);
+}
index 301f47c68fac1479ea267423683b2a37b58fd81c..657c9be423bf4cd4ba02e5df5caffc74ffb96af2 100644 (file)
@@ -305,4 +305,9 @@ interface IServerContainer {
         * @return string
         */
        function getWebRoot();
+
+       /**
+        * @return \OCP\Files\Config\IMountProviderCollection
+        */
+       function getMountProviderCollection();
 }
index 051b76ccf2ea5a1e8b8c7a7909dc5b111b997ca7..78322b47d5017089044f04266c8970c33c1a7e46 100644 (file)
@@ -30,33 +30,33 @@ class Manager extends \Test\TestCase {
        public function testFind() {
                $this->assertNull($this->manager->find('/'));
 
-               $rootMount = new \OC\Files\Mount\Mount(new Temporary(array()), '/');
+               $rootMount = new \OC\Files\Mount\MountPoint(new Temporary(array()), '/');
                $this->manager->addMount($rootMount);
                $this->assertEquals($rootMount, $this->manager->find('/'));
                $this->assertEquals($rootMount, $this->manager->find('/foo/bar'));
 
                $storage = new Temporary(array());
-               $mount1 = new \OC\Files\Mount\Mount($storage, '/foo');
+               $mount1 = new \OC\Files\Mount\MountPoint($storage, '/foo');
                $this->manager->addMount($mount1);
                $this->assertEquals($rootMount, $this->manager->find('/'));
                $this->assertEquals($mount1, $this->manager->find('/foo/bar'));
 
                $this->assertEquals(1, count($this->manager->findIn('/')));
-               $mount2 = new \OC\Files\Mount\Mount(new Temporary(array()), '/bar');
+               $mount2 = new \OC\Files\Mount\MountPoint(new Temporary(array()), '/bar');
                $this->manager->addMount($mount2);
                $this->assertEquals(2, count($this->manager->findIn('/')));
 
                $id = $mount1->getStorageId();
                $this->assertEquals(array($mount1), $this->manager->findByStorageId($id));
 
-               $mount3 = new \OC\Files\Mount\Mount($storage, '/foo/bar');
+               $mount3 = new \OC\Files\Mount\MountPoint($storage, '/foo/bar');
                $this->manager->addMount($mount3);
                $this->assertEquals(array($mount1, $mount3), $this->manager->findByStorageId($id));
        }
 
        public function testLong() {
                $storage = new LongId(array());
-               $mount = new \OC\Files\Mount\Mount($storage, '/foo');
+               $mount = new \OC\Files\Mount\MountPoint($storage, '/foo');
                $this->manager->addMount($mount);
 
                $id = $mount->getStorageId();
index 5ee3d934e97b6bc4723edb3c2ad470853ae760c4..584766de8362984e9340609b691a5b80685931e1 100644 (file)
@@ -9,7 +9,7 @@
 namespace Test\Files\Mount;
 
 
-use OC\Files\Storage\Loader;
+use OC\Files\Storage\StorageFactory;
 use OC\Files\Storage\Wrapper\Wrapper;
 
 class Mount extends \Test\TestCase {
@@ -17,12 +17,12 @@ class Mount extends \Test\TestCase {
                $storage = $this->getMockBuilder('\OC\Files\Storage\Temporary')
                        ->disableOriginalConstructor()
                        ->getMock();
-               $mount = new \OC\Files\Mount\Mount($storage, '/foo');
+               $mount = new \OC\Files\Mount\MountPoint($storage, '/foo');
                $this->assertInstanceOf('\OC\Files\Storage\Temporary', $mount->getStorage());
        }
 
        public function testFromStorageClassname() {
-               $mount = new \OC\Files\Mount\Mount('\OC\Files\Storage\Temporary', '/foo');
+               $mount = new \OC\Files\Mount\MountPoint('\OC\Files\Storage\Temporary', '/foo');
                $this->assertInstanceOf('\OC\Files\Storage\Temporary', $mount->getStorage());
        }
 
@@ -34,13 +34,13 @@ class Mount extends \Test\TestCase {
                        return new Wrapper(array('storage' => $storage));
                };
 
-               $loader = new Loader();
+               $loader = new StorageFactory();
                $loader->addStorageWrapper('test_wrapper', $wrapper);
 
                $storage = $this->getMockBuilder('\OC\Files\Storage\Temporary')
                        ->disableOriginalConstructor()
                        ->getMock();
-               $mount = new \OC\Files\Mount\Mount($storage, '/foo', array(), $loader);
+               $mount = new \OC\Files\Mount\MountPoint($storage, '/foo', array(), $loader);
                $this->assertInstanceOf('\OC\Files\Storage\Wrapper\Wrapper', $mount->getStorage());
        }
 }
index 4aa57aa937393195e9b7b2f1b3704110fe487bd7..d8c047a2b757a35f99136a51116736346014a633 100644 (file)
@@ -10,7 +10,7 @@ namespace Test\Files\Node;
 
 use OC\Files\Cache\Cache;
 use OC\Files\FileInfo;
-use OC\Files\Mount\Mount;
+use OC\Files\Mount\MountPoint;
 use OC\Files\Node\Node;
 use OCP\Files\NotFoundException;
 use OCP\Files\NotPermittedException;
@@ -419,7 +419,7 @@ class Folder extends \Test\TestCase {
                $cache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
                $subCache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
                $subStorage = $this->getMock('\OC\Files\Storage\Storage');
-               $subMount = $this->getMock('\OC\Files\Mount\Mount', array(), array(null, ''));
+               $subMount = $this->getMock('\OC\Files\Mount\MountPoint', array(), array(null, ''));
 
                $subMount->expects($this->once())
                        ->method('getStorage')
@@ -487,7 +487,7 @@ class Folder extends \Test\TestCase {
                        ->method('getUser')
                        ->will($this->returnValue($this->user));
                $storage = $this->getMock('\OC\Files\Storage\Storage');
-               $mount = new Mount($storage, '/bar');
+               $mount = new MountPoint($storage, '/bar');
                $cache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
 
                $view->expects($this->once())
@@ -530,7 +530,7 @@ class Folder extends \Test\TestCase {
                        ->method('getUser')
                        ->will($this->returnValue($this->user));
                $storage = $this->getMock('\OC\Files\Storage\Storage');
-               $mount = new Mount($storage, '/bar');
+               $mount = new MountPoint($storage, '/bar');
                $cache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
 
                $storage->expects($this->once())
@@ -568,8 +568,8 @@ class Folder extends \Test\TestCase {
                        ->method('getUser')
                        ->will($this->returnValue($this->user));
                $storage = $this->getMock('\OC\Files\Storage\Storage');
-               $mount1 = new Mount($storage, '/bar');
-               $mount2 = new Mount($storage, '/bar/foo/asd');
+               $mount1 = new MountPoint($storage, '/bar');
+               $mount2 = new MountPoint($storage, '/bar/foo/asd');
                $cache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
 
                $view->expects($this->any())
index f729be81bd7d4f404785e177a24f15dc314910eb..65ddfe47514cca9a9880189644f86b1149c7f9d1 100644 (file)
@@ -9,17 +9,17 @@
 namespace Test\Files\Utils;
 
 use OC\Files\Filesystem;
-use OC\Files\Mount\Mount;
+use OC\Files\Mount\MountPoint;
 use OC\Files\Storage\Temporary;
 
 class TestScanner extends \OC\Files\Utils\Scanner {
        /**
-        * @var \OC\Files\Mount\Mount[] $mounts
+        * @var \OC\Files\Mount\MountPoint[] $mounts
         */
        private $mounts = array();
 
        /**
-        * @param \OC\Files\Mount\Mount $mount
+        * @param \OC\Files\Mount\MountPoint $mount
         */
        public function addMount($mount) {
                $this->mounts[] = $mount;
@@ -56,7 +56,7 @@ class Scanner extends \Test\TestCase {
 
        public function testReuseExistingRoot() {
                $storage = new Temporary(array());
-               $mount = new Mount($storage, '');
+               $mount = new MountPoint($storage, '');
                Filesystem::getMountManager()->addMount($mount);
                $cache = $storage->getCache();
 
@@ -78,7 +78,7 @@ class Scanner extends \Test\TestCase {
 
        public function testReuseExistingFile() {
                $storage = new Temporary(array());
-               $mount = new Mount($storage, '');
+               $mount = new MountPoint($storage, '');
                Filesystem::getMountManager()->addMount($mount);
                $cache = $storage->getCache();
 
@@ -105,7 +105,7 @@ class Scanner extends \Test\TestCase {
                $propagator = $this->getMock('\OC\Files\Cache\ChangePropagator', array('propagateChanges'), array(), '', false);
 
                $storage = new Temporary(array());
-               $mount = new Mount($storage, '/foo');
+               $mount = new MountPoint($storage, '/foo');
                Filesystem::getMountManager()->addMount($mount);
                $cache = $storage->getCache();