Use the movable mount system for external shares

This commit is contained in:
Robin Appelman 2014-06-12 16:14:43 +02:00 committed by Bjoern Schiessle
parent c61f759a8b
commit ce0aa7d4a8
3 changed files with 66 additions and 39 deletions

View 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));
}
}

View File

@ -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);
}
}

View 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);
}
}
}