diff options
author | Joas Schilling <nickvergessen@owncloud.com> | 2015-06-02 12:27:30 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@owncloud.com> | 2015-06-02 12:29:06 +0200 |
commit | 9a4040c7ca2c0e4fc3f213ba3f6144e80f687754 (patch) | |
tree | 9fc19fd59b76d251b932f1001549219cc2761bda /lib | |
parent | d2f3710ede1fa72658a4c12264a90a1936faf9ca (diff) | |
download | nextcloud-server-9a4040c7ca2c0e4fc3f213ba3f6144e80f687754.tar.gz nextcloud-server-9a4040c7ca2c0e4fc3f213ba3f6144e80f687754.zip |
Move the storage wrapping into a testable method
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/encryption/manager.php | 53 | ||||
-rw-r--r-- | lib/private/encryption/util.php | 49 |
2 files changed, 59 insertions, 43 deletions
diff --git a/lib/private/encryption/manager.php b/lib/private/encryption/manager.php index ecbb86993ec..eeddea26b1a 100644 --- a/lib/private/encryption/manager.php +++ b/lib/private/encryption/manager.php @@ -208,49 +208,16 @@ class Manager implements IManager { return $this->config->getAppValue('core', 'default_encryption_module'); } + /** + * Add storage wrapper + */ public static function setupStorage() { - \OC\Files\Filesystem::addStorageWrapper('oc_encryption', function ($mountPoint, $storage, IMountPoint $mount) { - $parameters = [ - 'storage' => $storage, - 'mountPoint' => $mountPoint, - 'mount' => $mount]; - - if (!($storage instanceof Shared)) { - $manager = \OC::$server->getEncryptionManager(); - $util = new Util( - new View(), - \OC::$server->getUserManager(), - \OC::$server->getGroupManager(), - \OC::$server->getConfig() - ); - $user = \OC::$server->getUserSession()->getUser(); - $logger = \OC::$server->getLogger(); - $mountManager = Filesystem::getMountManager(); - $uid = $user ? $user->getUID() : null; - $fileHelper = \OC::$server->getEncryptionFilesHelper(); - $keyStorage = \OC::$server->getEncryptionKeyStorage(); - $update = new Update( - new View(), - $util, - Filesystem::getMountManager(), - $manager, - $fileHelper, - $uid - ); - return new Encryption( - $parameters, - $manager, - $util, - $logger, - $fileHelper, - $uid, - $keyStorage, - $update, - $mountManager - ); - } else { - return $storage; - } - }, 2); + $util = new Util( + new View(), + \OC::$server->getUserManager(), + \OC::$server->getGroupManager(), + \OC::$server->getConfig() + ); + \OC\Files\Filesystem::addStorageWrapper('oc_encryption', array($util, 'wrapStorage'), 2); } } diff --git a/lib/private/encryption/util.php b/lib/private/encryption/util.php index b77672d2f6b..d233b715f88 100644 --- a/lib/private/encryption/util.php +++ b/lib/private/encryption/util.php @@ -26,8 +26,12 @@ use OC\Encryption\Exceptions\EncryptionHeaderKeyExistsException; use OC\Encryption\Exceptions\EncryptionHeaderToLargeException; use OC\Encryption\Exceptions\ModuleDoesNotExistsException; use OC\Files\Filesystem; +use OC\Files\Storage\Shared; +use OC\Files\Storage\Wrapper\Encryption; use OC\Files\View; use OCP\Encryption\IEncryptionModule; +use OCP\Files\Mount\IMountPoint; +use OCP\Files\Storage; use OCP\IConfig; class Util { @@ -386,4 +390,49 @@ class Util { return ($enabled === '1') ? true : false; } + /** + * Wraps the given storage when it is not a shared storage + * + * @param string $mountPoint + * @param Storage $storage + * @param IMountPoint $mount + * @return Encryption|Storage + */ + public function wrapStorage($mountPoint, Storage $storage, IMountPoint $mount) { + $parameters = [ + 'storage' => $storage, + 'mountPoint' => $mountPoint, + 'mount' => $mount]; + + if (!($storage instanceof Shared)) { + $manager = \OC::$server->getEncryptionManager(); + $user = \OC::$server->getUserSession()->getUser(); + $logger = \OC::$server->getLogger(); + $mountManager = Filesystem::getMountManager(); + $uid = $user ? $user->getUID() : null; + $fileHelper = \OC::$server->getEncryptionFilesHelper(); + $keyStorage = \OC::$server->getEncryptionKeyStorage(); + $update = new Update( + new View(), + $this, + Filesystem::getMountManager(), + $manager, + $fileHelper, + $uid + ); + return new Encryption( + $parameters, + $manager, + $this, + $logger, + $fileHelper, + $uid, + $keyStorage, + $update, + $mountManager + ); + } else { + return $storage; + } + } } |