diff options
author | Robin Appelman <icewind@owncloud.com> | 2014-05-22 01:40:42 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2014-06-06 09:55:59 +0200 |
commit | cabe2873c47004798eadd39d9f1ad811e7227137 (patch) | |
tree | 8544acc6421569a9660f8dbdff7f0862938f7b1b /apps/files_external | |
parent | 8abe1c3f1a5f5da36ab6ac8d1c39b966991387ce (diff) | |
download | nextcloud-server-cabe2873c47004798eadd39d9f1ad811e7227137.tar.gz nextcloud-server-cabe2873c47004798eadd39d9f1ad811e7227137.zip |
Make personal external mount points (re)movable from the files app
Diffstat (limited to 'apps/files_external')
-rwxr-xr-x | apps/files_external/lib/config.php | 35 | ||||
-rw-r--r-- | apps/files_external/lib/personalmount.php | 38 |
2 files changed, 72 insertions, 1 deletions
diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index 28e28ffcde6..46c4f94eec6 100755 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -104,8 +104,15 @@ class OC_Mount_Config { */ public static function initMountPointsHook($data) { $mountPoints = self::getAbsoluteMountPoints($data['user']); + $loader = \OC\Files\Filesystem::getLoader(); + $manager = \OC\Files\Filesystem::getMountManager(); foreach ($mountPoints as $mountPoint => $options) { - \OC\Files\Filesystem::mount($options['class'], $options['options'], $mountPoint); + if ($options['personal']){ + $mount = new \OCA\Files_External\PersonalMount($options['class'], $mountPoint, $options['options'], $loader); + } else{ + $mount = new \OC\Files\Mount\Mount($options['class'], $mountPoint, $options['options'], $loader); + } + $manager->addMount($mount); } } @@ -135,6 +142,7 @@ class OC_Mount_Config { // Global mount points (is this redundant?) if (isset($mountConfig[self::MOUNT_TYPE_GLOBAL])) { foreach ($mountConfig[self::MOUNT_TYPE_GLOBAL] as $mountPoint => $options) { + $options['personal'] = false; $options['options'] = self::decryptPasswords($options['options']); if (!isset($options['priority'])) { $options['priority'] = $backends[$options['class']]['priority']; @@ -178,6 +186,7 @@ class OC_Mount_Config { foreach ($options as &$option) { $option = self::setUserVars($user, $option); } + $options['personal'] = false; $options['options'] = self::decryptPasswords($options['options']); if (!isset($options['priority'])) { $options['priority'] = $backends[$options['class']]['priority']; @@ -203,6 +212,7 @@ class OC_Mount_Config { foreach ($options as &$option) { $option = self::setUserVars($user, $option); } + $options['personal'] = false; $options['options'] = self::decryptPasswords($options['options']); if (!isset($options['priority'])) { $options['priority'] = $backends[$options['class']]['priority']; @@ -224,6 +234,7 @@ class OC_Mount_Config { $mountConfig = self::readData($user); if (isset($mountConfig[self::MOUNT_TYPE_USER][$user])) { foreach ($mountConfig[self::MOUNT_TYPE_USER][$user] as $mountPoint => $options) { + $options['personal'] = true; $options['options'] = self::decryptPasswords($options['options']); // Always override previous config @@ -521,6 +532,28 @@ class OC_Mount_Config { } /** + * + * @param string $mountPoint Mount point + * @param string $target The new mount point + * @param string $mountType MOUNT_TYPE_GROUP | MOUNT_TYPE_USER + * @return bool + */ + public static function movePersonalMountPoint($mountPoint, $target, $mountType) { + $mountPoint = rtrim($mountPoint, '/'); + $user = OCP\User::getUser(); + $mountPoints = self::readData($user); + if (!isset($mountPoints[$mountType][$user][$mountPoint])) { + return false; + } + $mountPoints[$mountType][$user][$target] = $mountPoints[$mountType][$user][$mountPoint]; + // Remove old mount point + unset($mountPoints[$mountType][$user][$mountPoint]); + + self::writeData($user, $mountPoints); + return true; + } + + /** * Read the mount points in the config file into an array * @param string|null $user If not null, personal for $user, otherwise system * @return array diff --git a/apps/files_external/lib/personalmount.php b/apps/files_external/lib/personalmount.php new file mode 100644 index 00000000000..c3e97092520 --- /dev/null +++ b/apps/files_external/lib/personalmount.php @@ -0,0 +1,38 @@ +<?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 OCA\Files_External; + +use OC\Files\Mount\Mount; +use OC\Files\Mount\MoveableMount; + +/** + * Person mount points can be moved by the user + */ +class PersonalMount extends Mount implements MoveableMount { + /** + * Move the mount point to $target + * + * @param string $target the target mount point + * @return bool + */ + public function moveMount($target) { + $result = \OC_Mount_Config::movePersonalMountPoint($this->getMountPoint(), $target, \OC_Mount_Config::MOUNT_TYPE_USER); + $this->setMountPoint($target); + return $result; + } + + /** + * Remove the mount points + * + * @return bool + */ + public function removeMount() { + return \OC_Mount_Config::removeMountPoint($this->mountPoint, \OC_Mount_Config::MOUNT_TYPE_USER, \OCP\User::getUser(), true); + } +} |