summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2014-05-22 01:39:24 +0200
committerRobin Appelman <icewind@owncloud.com>2014-06-06 09:55:58 +0200
commit60a659c87e1a3cb2c65dc330cb64c3414fd4b648 (patch)
tree36fc571a0d5d4ad30780f1b86cbdcbdd7555b276 /lib
parent79b65269c9e1dd1cd01dc2fd28a979105650fc91 (diff)
downloadnextcloud-server-60a659c87e1a3cb2c65dc330cb64c3414fd4b648.tar.gz
nextcloud-server-60a659c87e1a3cb2c65dc330cb64c3414fd4b648.zip
Add a system for (re)movable mount points
Diffstat (limited to 'lib')
-rw-r--r--lib/private/files/mount/manager.php9
-rw-r--r--lib/private/files/mount/mount.php12
-rw-r--r--lib/private/files/mount/moveablemount.php30
-rw-r--r--lib/private/files/view.php41
4 files changed, 64 insertions, 28 deletions
diff --git a/lib/private/files/mount/manager.php b/lib/private/files/mount/manager.php
index db1f4600c74..45a9f339fba 100644
--- a/lib/private/files/mount/manager.php
+++ b/lib/private/files/mount/manager.php
@@ -31,6 +31,15 @@ class Manager {
}
/**
+ * @param string $mountPoint
+ * @param string $target
+ */
+ public function moveMount($mountPoint, $target){
+ $this->mounts[$target] = $this->mounts[$mountPoint];
+ unset($this->mounts[$mountPoint]);
+ }
+
+ /**
* Find the mount for $path
*
* @param string $path
diff --git a/lib/private/files/mount/mount.php b/lib/private/files/mount/mount.php
index 7c40853ac95..7561cd7311b 100644
--- a/lib/private/files/mount/mount.php
+++ b/lib/private/files/mount/mount.php
@@ -16,11 +16,11 @@ class Mount {
/**
* @var \OC\Files\Storage\Storage $storage
*/
- private $storage = null;
- private $class;
- private $storageId;
- private $arguments = array();
- private $mountPoint;
+ protected $storage = null;
+ protected $class;
+ protected $storageId;
+ protected $arguments = array();
+ protected $mountPoint;
/**
* @var \OC\Files\Storage\Loader $loader
@@ -142,7 +142,7 @@ class Mount {
} else {
$internalPath = substr($path, strlen($this->mountPoint));
}
- return $internalPath;
+ return (string)$internalPath;
}
/**
diff --git a/lib/private/files/mount/moveablemount.php b/lib/private/files/mount/moveablemount.php
new file mode 100644
index 00000000000..117649339e9
--- /dev/null
+++ b/lib/private/files/mount/moveablemount.php
@@ -0,0 +1,30 @@
+<?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;
+
+/**
+ * Defines the mount point to be (re)moved by the user
+ */
+interface MoveableMount {
+ /**
+ * Move the mount point to $target
+ *
+ * @param string $target the target mount point
+ * @return bool
+ */
+ public function moveMount($target);
+
+ /**
+ * Remove the mount points
+ *
+ * @return mixed
+ * @return bool
+ */
+ public function removeMount();
+}
diff --git a/lib/private/files/view.php b/lib/private/files/view.php
index 1dc6c405bcf..a2188f393fa 100644
--- a/lib/private/files/view.php
+++ b/lib/private/files/view.php
@@ -26,6 +26,7 @@
namespace OC\Files;
use OC\Files\Cache\Updater;
+use OC\Files\Mount\MoveableMount;
class View {
private $fakeRoot = '';
@@ -357,10 +358,8 @@ class View {
}
$postFix = (substr($path, -1, 1) === '/') ? '/' : '';
$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
- list($storage, $internalPath) = Filesystem::resolvePath($absolutePath . $postFix);
- if (!($storage instanceof \OC\Files\Storage\Shared) &&
- (!$internalPath || $internalPath === '' || $internalPath === '/')
- ) {
+ $mount = Filesystem::getMountManager()->find($absolutePath . $postFix);
+ if (!($mount instanceof MoveableMount) && $mount->getInternalPath($absolutePath) === '') {
// do not allow deleting the storage's root / the mount point
// because for some storages it might delete the whole contents
// but isn't supposed to work that way
@@ -411,18 +410,19 @@ class View {
if ($run) {
$mp1 = $this->getMountPoint($path1 . $postFix1);
$mp2 = $this->getMountPoint($path2 . $postFix2);
- list($storage1, $internalPath1) = Filesystem::resolvePath($absolutePath1 . $postFix1);
+ $manager = Filesystem::getMountManager();
+ $mount = $manager->find($absolutePath1 . $postFix1);
+ $storage1 = $mount->getStorage();
+ $internalPath1 = $mount->getInternalPath($absolutePath1 . $postFix1);
list(, $internalPath2) = Filesystem::resolvePath($absolutePath2 . $postFix2);
- // if source and target are on the same storage we can call the rename operation from the
- // storage. If it is a "Shared" file/folder we call always the rename operation of the
- // shared storage to handle mount point renaming, etc correctly
- if ($storage1 instanceof \OC\Files\Storage\Shared) {
- if ($storage1) {
- $result = $storage1->rename($absolutePath1, $absolutePath2);
- \OC_FileProxy::runPostProxies('rename', $absolutePath1, $absolutePath2);
- } else {
- $result = false;
- }
+ if ($internalPath1 == '' and $mount instanceof MoveableMount) {
+ /**
+ * @var \OC\Files\Mount\Mount | \OC\Files\Mount\MoveableMount $mount
+ */
+ $sourceMountPoint = $mount->getMountPoint();
+ $result = $mount->moveMount($absolutePath2);
+ $manager->moveMount($sourceMountPoint, $mount->getMountPoint());
+ \OC_FileProxy::runPostProxies('rename', $absolutePath1, $absolutePath2);
} elseif ($mp1 == $mp2) {
if ($storage1) {
$result = $storage1->rename($internalPath1, $internalPath2);
@@ -888,10 +888,6 @@ class View {
return $result;
}
$path = Filesystem::normalizePath($this->fakeRoot . '/' . $directory);
- /**
- * @var \OC\Files\Storage\Storage $storage
- * @var string $internalPath
- */
list($storage, $internalPath) = Filesystem::resolvePath($path);
if ($storage) {
$cache = $storage->getCache($internalPath);
@@ -924,9 +920,10 @@ class View {
}
//add a folder for any mountpoint in this directory and add the sizes of other mountpoints to the folders
- $mountPoints = Filesystem::getMountPoints($path);
+ $mounts = Filesystem::getMountManager()->findIn($path);
$dirLength = strlen($path);
- foreach ($mountPoints as $mountPoint) {
+ foreach ($mounts as $mount) {
+ $mountPoint = $mount->getMountPoint();
$subStorage = Filesystem::getStorage($mountPoint);
if ($subStorage) {
$subCache = $subStorage->getCache('');
@@ -953,7 +950,7 @@ class View {
$permissions = $rootEntry['permissions'];
// do not allow renaming/deleting the mount point if they are not shared files/folders
// for shared files/folders we use the permissions given by the owner
- if ($subStorage instanceof \OC\Files\Storage\Shared) {
+ if ($mount instanceof MoveableMount) {
$rootEntry['permissions'] = $permissions;
} else {
$rootEntry['permissions'] = $permissions & (\OCP\PERMISSION_ALL - (\OCP\PERMISSION_UPDATE | \OCP\PERMISSION_DELETE));