aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2014-06-12 16:14:43 +0200
committerBjoern Schiessle <schiessle@owncloud.com>2014-06-14 10:14:08 +0200
commitce0aa7d4a895849a90e1ec5ea97bd699a8a4ad3f (patch)
tree22879a2be5b7b07b3a3e1eb832a098a57911ca6e /apps
parentc61f759a8b4f0091a978eb4e8da1354809d77f5e (diff)
downloadnextcloud-server-ce0aa7d4a895849a90e1ec5ea97bd699a8a4ad3f.tar.gz
nextcloud-server-ce0aa7d4a895849a90e1ec5ea97bd699a8a4ad3f.zip
Use the movable mount system for external shares
Diffstat (limited to 'apps')
-rw-r--r--apps/files_sharing/lib/external/manager.php19
-rw-r--r--apps/files_sharing/lib/external/mount.php53
-rw-r--r--apps/files_sharing/lib/external/storage.php33
3 files changed, 66 insertions, 39 deletions
diff --git a/apps/files_sharing/lib/external/manager.php b/apps/files_sharing/lib/external/manager.php
index 75edf73059c..a1a97126506 100644
--- a/apps/files_sharing/lib/external/manager.php
+++ b/apps/files_sharing/lib/external/manager.php
@@ -9,7 +9,6 @@
namespace OCA\Files_Sharing\External;
use OC\Files\Filesystem;
-use OC\Files\Mount\Mount;
class Manager {
const STORAGE = '\OCA\Files_Sharing\External\Storage';
@@ -83,13 +82,18 @@ class Manager {
}
}
+ protected function stripPath($path) {
+ $prefix = '/' . $this->userSession->getUser()->getUID() . '/files';
+ return rtrim(substr($path, strlen($prefix)), '/');
+ }
+
/**
* @param array $data
* @return Mount
*/
protected function mountShare($data) {
$mountPoint = '/' . $this->userSession->getUser()->getUID() . '/files' . $data['mountpoint'];
- $mount = new Mount(self::STORAGE, $mountPoint, $data, $this->storageLoader);
+ $mount = new Mount(self::STORAGE, $mountPoint, $data, $this, $this->storageLoader);
$this->mountManager->addMount($mount);
return $mount;
}
@@ -107,22 +111,21 @@ class Manager {
* @return bool
*/
public function setMountPoint($source, $target) {
+ $source = $this->stripPath($source);
+ $target = $this->stripPath($target);
$sourceHash = md5($source);
$targetHash = md5($target);
$query = $this->connection->prepare('UPDATE *PREFIX*share_external SET
`mountpoint` = ?, `mountpoint_hash` = ? WHERE `mountpoint_hash` = ?');
- $query->execute(array($target, $targetHash, $sourceHash));
+ $result = (bool)$query->execute(array($target, $targetHash, $sourceHash));
- $mount = $this->mountManager->find($source);
- $mount->setMountPoint($target . '/');
- $this->mountManager->addMount($mount);
- $this->mountManager->removeMount($source . '/');
+ return $result;
}
public function removeShare($mountPoint) {
$hash = md5($mountPoint);
$query = $this->connection->prepare('DELETE FROM *PREFIX*share_external WHERE `mountpoint_hash` = ?');
- $query->execute(array($hash));
+ return (bool)$query->execute(array($hash));
}
}
diff --git a/apps/files_sharing/lib/external/mount.php b/apps/files_sharing/lib/external/mount.php
new file mode 100644
index 00000000000..a42a12f9b9a
--- /dev/null
+++ b/apps/files_sharing/lib/external/mount.php
@@ -0,0 +1,53 @@
+<?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 OCA\Files_Sharing\External;
+
+use OC\Files\Mount\MoveableMount;
+
+class Mount extends \OC\Files\Mount\Mount implements MoveableMount {
+
+ /**
+ * @var \OCA\Files_Sharing\External\Manager
+ */
+ protected $manager;
+
+ /**
+ * @param string|\OC\Files\Storage\Storage $storage
+ * @param string $mountpoint
+ * @param array $options
+ * @param \OCA\Files_Sharing\External\Manager $manager
+ * @param \OC\Files\Storage\Loader $loader
+ */
+ public function __construct($storage, $mountpoint, $options, $manager, $loader = null) {
+ parent::__construct($storage, $mountpoint, $options, $loader);
+ $this->manager = $manager;
+ }
+
+ /**
+ * Move the mount point to $target
+ *
+ * @param string $target the target mount point
+ * @return bool
+ */
+ public function moveMount($target) {
+ $result = $this->manager->setMountPoint($this->mountPoint, $target);
+ $this->setMountPoint($target);
+ return $result;
+ }
+
+ /**
+ * Remove the mount points
+ *
+ * @return mixed
+ * @return bool
+ */
+ public function removeMount() {
+ return $this->manager->removeShare($this->mountPoint);
+ }
+}
diff --git a/apps/files_sharing/lib/external/storage.php b/apps/files_sharing/lib/external/storage.php
index 741e219eff7..89d2f5e6669 100644
--- a/apps/files_sharing/lib/external/storage.php
+++ b/apps/files_sharing/lib/external/storage.php
@@ -9,9 +9,10 @@
namespace OCA\Files_Sharing\External;
use OC\Files\Filesystem;
+use OC\Files\Storage\DAV;
use OCA\Files_Sharing\ISharedStorage;
-class Storage extends \OC\Files\Storage\DAV implements ISharedStorage {
+class Storage extends DAV implements ISharedStorage {
/**
* @var string
*/
@@ -101,34 +102,4 @@ class Storage extends \OC\Files\Storage\DAV implements ISharedStorage {
}
return $this->scanner;
}
-
- public function rename($path1, $path2) {
- // if we renamed the mount point we need to adjust the mountpoint in the database
- if (Filesystem::normalizePath($this->mountPoint) === Filesystem::normalizePath($path1)) {
- $this->manager->setMountPoint($path1, $path2);
- $this->mountPoint = $path2;
- return true;
- } else {
- // read only shares
- return false;
- }
- }
-
- public function unlink($path) {
- if ($path === '' || $path === false) {
- $this->manager->removeShare($this->mountPoint);
- return true;
- } else {
- return parent::unlink($path);
- }
- }
-
- public function rmdir($path) {
- if ($path === '' || $path === false) {
- $this->manager->removeShare($this->mountPoint);
- return true;
- } else {
- return parent::rmdir($path);
- }
- }
}