[Pkg-owncloud-commits] [owncloud] 122/223: Use the movable mount system for external shares

David Prévot taffit at moszumanska.debian.org
Sun Jun 22 01:54:14 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud.

commit ce0aa7d4a895849a90e1ec5ea97bd699a8a4ad3f
Author: Robin Appelman <icewind at owncloud.com>
Date:   Thu Jun 12 16:14:43 2014 +0200

    Use the movable mount system for external shares
---
 apps/files_sharing/lib/external/manager.php | 19 ++++++-----
 apps/files_sharing/lib/external/mount.php   | 53 +++++++++++++++++++++++++++++
 apps/files_sharing/lib/external/storage.php | 33 ++----------------
 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 75edf73..a1a9712 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 0000000..a42a12f
--- /dev/null
+++ b/apps/files_sharing/lib/external/mount.php
@@ -0,0 +1,53 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind at 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 741e219..89d2f5e 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);
-		}
-	}
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list