]> source.dussan.org Git - nextcloud-server.git/commitdiff
Use the movable mount system for external shares
authorRobin Appelman <icewind@owncloud.com>
Thu, 12 Jun 2014 14:14:43 +0000 (16:14 +0200)
committerBjoern Schiessle <schiessle@owncloud.com>
Sat, 14 Jun 2014 08:14:08 +0000 (10:14 +0200)
apps/files_sharing/lib/external/manager.php
apps/files_sharing/lib/external/mount.php [new file with mode: 0644]
apps/files_sharing/lib/external/storage.php

index 75edf73059ca17d32929365b03819649df0ecf62..a1a971265063703f2852fb6528b97ca57f58d446 100644 (file)
@@ -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 (file)
index 0000000..a42a12f
--- /dev/null
@@ -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);
+       }
+}
index 741e219eff7fb19119a69025a492284a758309af..89d2f5e66697e906959fe7622917604d3f605c39 100644 (file)
@@ -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);
-               }
-       }
 }