[Pkg-owncloud-commits] [owncloud] 46/103: Correctly get the unique mountpoint name when mounting the share

David Prévot taffit at moszumanska.debian.org
Sun May 31 12:32:36 UTC 2015


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

taffit pushed a commit to annotated tag v8.0.4RC1
in repository owncloud.

commit 6a6acd2a465e6d5f4c831a0a8107b89f3acc91e8
Author: Joas Schilling <nickvergessen at owncloud.com>
Date:   Fri Feb 27 16:04:17 2015 +0100

    Correctly get the unique mountpoint name when mounting the share
    
    Previously the mount name was checked for uniqueness prior to inserting the
    share. This caused problems, when two shares with the same name where done
    or folder, mount point, local share with the same name was done, between
    sending and accepting of the remote share
---
 apps/files_sharing/ajax/external.php        |  2 --
 apps/files_sharing/api/server2server.php    |  2 --
 apps/files_sharing/lib/external/manager.php | 41 +++++++++++++++++++++++++----
 3 files changed, 36 insertions(+), 9 deletions(-)

diff --git a/apps/files_sharing/ajax/external.php b/apps/files_sharing/ajax/external.php
index 30c1f38..153285e 100644
--- a/apps/files_sharing/ajax/external.php
+++ b/apps/files_sharing/ajax/external.php
@@ -38,8 +38,6 @@ $externalManager = new \OCA\Files_Sharing\External\Manager(
 		\OC::$server->getUserSession()->getUser()->getUID()
 );
 
-$name = OCP\Files::buildNotExistingFileName('/', $name);
-
 // check for ssl cert
 if (substr($remote, 0, 5) === 'https' and !OC_Util::getUrlContent($remote)) {
 	\OCP\JSON::error(array('data' => array('message' => $l->t('Invalid or untrusted SSL certificate'))));
diff --git a/apps/files_sharing/api/server2server.php b/apps/files_sharing/api/server2server.php
index f2f7561..89a0262 100644
--- a/apps/files_sharing/api/server2server.php
+++ b/apps/files_sharing/api/server2server.php
@@ -64,8 +64,6 @@ class Server2Server {
 					$shareWith
 				);
 
-			$name = \OCP\Files::buildNotExistingFileName('/', $name);
-
 			try {
 				$externalManager->addShare($remote, $token, '', $name, $owner, false, $shareWith, $remoteId);
 
diff --git a/apps/files_sharing/lib/external/manager.php b/apps/files_sharing/lib/external/manager.php
index 490e5e5..eb03065 100644
--- a/apps/files_sharing/lib/external/manager.php
+++ b/apps/files_sharing/lib/external/manager.php
@@ -9,6 +9,7 @@
 namespace OCA\Files_Sharing\External;
 
 use OC\Files\Filesystem;
+use OCP\Files;
 
 class Manager {
 	const STORAGE = '\OCA\Files_Sharing\External\Storage';
@@ -71,15 +72,39 @@ class Manager {
 
 		$user = $user ? $user : $this->uid;
 		$accepted = $accepted ? 1 : 0;
+		$name = Filesystem::normalizePath('/' . $name);
 
-		$mountPoint = Filesystem::normalizePath('/' . $name);
+		if ($accepted) {
+			$mountPoint = Files::buildNotExistingFileName('/', $name);
+			$mountPoint = Filesystem::normalizePath('/' . $mountPoint);
+			$hash = md5($mountPoint);
+		} else {
+			// To avoid conflicts with the mount point generation later,
+			// we only use a temporary mount point name here. The real
+			// mount point name will be generated when accepting the share,
+			// using the original share item name.
+			$tmpMountPointName = Filesystem::normalizePath('/TemporaryMountPointName-' . $name);
+			$mountPoint = $tmpMountPointName;
+			$hash = md5($tmpMountPointName);
+
+			$query = $this->connection->prepare('SELECT `id` FROM `*PREFIX*share_external` WHERE `user` = ? AND `mountpoint_hash` = ?', 1);
+			$query->execute([$user, $hash]);
+
+			$i = 1;
+			while ($query->fetch()) {
+				// The external share already exists for the user
+				$mountPoint = $tmpMountPointName . '-' . $i;
+				$hash = md5($mountPoint);
+				$query->execute([$user, $hash]);
+				$i++;
+			}
+		}
 
 		$query = $this->connection->prepare('
 				INSERT INTO `*PREFIX*share_external`
 					(`remote`, `share_token`, `password`, `name`, `owner`, `user`, `mountpoint`, `mountpoint_hash`, `accepted`, `remote_id`)
 				VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
 			');
-		$hash = md5($mountPoint);
 		$query->execute(array($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId));
 
 		if ($accepted) {
@@ -124,7 +149,7 @@ class Manager {
 	 */
 	private function getShare($id) {
 		$getShare = $this->connection->prepare('
-			SELECT `remote`, `share_token`
+			SELECT `remote`, `share_token`, `name`
 			FROM  `*PREFIX*share_external`
 			WHERE `id` = ? AND `user` = ?');
 		$result = $getShare->execute(array($id, $this->uid));
@@ -142,11 +167,17 @@ class Manager {
 		$share = $this->getShare($id);
 
 		if ($share) {
+			$mountPoint = Files::buildNotExistingFileName('/', $share['name']);
+			$mountPoint = Filesystem::normalizePath('/' . $mountPoint);
+			$hash = md5($mountPoint);
+
 			$acceptShare = $this->connection->prepare('
 				UPDATE `*PREFIX*share_external`
-				SET `accepted` = ?
+				SET `accepted` = ?,
+					`mountpoint` = ?,
+					`mountpoint_hash` = ?
 				WHERE `id` = ? AND `user` = ?');
-			$acceptShare->execute(array(1, $id, $this->uid));
+			$acceptShare->execute(array(1, $mountPoint, $hash, $id, $this->uid));
 			$this->sendFeedbackToRemote($share['remote'], $share['share_token'], $id, 'accept');
 		}
 	}

-- 
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