Add a system for (re)movable mount points
This commit is contained in:
parent
79b65269c9
commit
60a659c87e
4 changed files with 64 additions and 28 deletions
|
@ -30,6 +30,15 @@ class Manager {
|
|||
unset($this->mounts[$mountPoint]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $mountPoint
|
||||
* @param string $target
|
||||
*/
|
||||
public function moveMount($mountPoint, $target){
|
||||
$this->mounts[$target] = $this->mounts[$mountPoint];
|
||||
unset($this->mounts[$mountPoint]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the mount for $path
|
||||
*
|
||||
|
|
|
@ -16,11 +16,11 @@ class Mount {
|
|||
/**
|
||||
* @var \OC\Files\Storage\Storage $storage
|
||||
*/
|
||||
private $storage = null;
|
||||
private $class;
|
||||
private $storageId;
|
||||
private $arguments = array();
|
||||
private $mountPoint;
|
||||
protected $storage = null;
|
||||
protected $class;
|
||||
protected $storageId;
|
||||
protected $arguments = array();
|
||||
protected $mountPoint;
|
||||
|
||||
/**
|
||||
* @var \OC\Files\Storage\Loader $loader
|
||||
|
@ -142,7 +142,7 @@ class Mount {
|
|||
} else {
|
||||
$internalPath = substr($path, strlen($this->mountPoint));
|
||||
}
|
||||
return $internalPath;
|
||||
return (string)$internalPath;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
30
lib/private/files/mount/moveablemount.php
Normal file
30
lib/private/files/mount/moveablemount.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright (c) 2012 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 OC\Files\Mount;
|
||||
|
||||
/**
|
||||
* Defines the mount point to be (re)moved by the user
|
||||
*/
|
||||
interface MoveableMount {
|
||||
/**
|
||||
* Move the mount point to $target
|
||||
*
|
||||
* @param string $target the target mount point
|
||||
* @return bool
|
||||
*/
|
||||
public function moveMount($target);
|
||||
|
||||
/**
|
||||
* Remove the mount points
|
||||
*
|
||||
* @return mixed
|
||||
* @return bool
|
||||
*/
|
||||
public function removeMount();
|
||||
}
|
|
@ -26,6 +26,7 @@
|
|||
namespace OC\Files;
|
||||
|
||||
use OC\Files\Cache\Updater;
|
||||
use OC\Files\Mount\MoveableMount;
|
||||
|
||||
class View {
|
||||
private $fakeRoot = '';
|
||||
|
@ -357,10 +358,8 @@ class View {
|
|||
}
|
||||
$postFix = (substr($path, -1, 1) === '/') ? '/' : '';
|
||||
$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
|
||||
list($storage, $internalPath) = Filesystem::resolvePath($absolutePath . $postFix);
|
||||
if (!($storage instanceof \OC\Files\Storage\Shared) &&
|
||||
(!$internalPath || $internalPath === '' || $internalPath === '/')
|
||||
) {
|
||||
$mount = Filesystem::getMountManager()->find($absolutePath . $postFix);
|
||||
if (!($mount instanceof MoveableMount) && $mount->getInternalPath($absolutePath) === '') {
|
||||
// do not allow deleting the storage's root / the mount point
|
||||
// because for some storages it might delete the whole contents
|
||||
// but isn't supposed to work that way
|
||||
|
@ -411,18 +410,19 @@ class View {
|
|||
if ($run) {
|
||||
$mp1 = $this->getMountPoint($path1 . $postFix1);
|
||||
$mp2 = $this->getMountPoint($path2 . $postFix2);
|
||||
list($storage1, $internalPath1) = Filesystem::resolvePath($absolutePath1 . $postFix1);
|
||||
$manager = Filesystem::getMountManager();
|
||||
$mount = $manager->find($absolutePath1 . $postFix1);
|
||||
$storage1 = $mount->getStorage();
|
||||
$internalPath1 = $mount->getInternalPath($absolutePath1 . $postFix1);
|
||||
list(, $internalPath2) = Filesystem::resolvePath($absolutePath2 . $postFix2);
|
||||
// if source and target are on the same storage we can call the rename operation from the
|
||||
// storage. If it is a "Shared" file/folder we call always the rename operation of the
|
||||
// shared storage to handle mount point renaming, etc correctly
|
||||
if ($storage1 instanceof \OC\Files\Storage\Shared) {
|
||||
if ($storage1) {
|
||||
$result = $storage1->rename($absolutePath1, $absolutePath2);
|
||||
\OC_FileProxy::runPostProxies('rename', $absolutePath1, $absolutePath2);
|
||||
} else {
|
||||
$result = false;
|
||||
}
|
||||
if ($internalPath1 == '' and $mount instanceof MoveableMount) {
|
||||
/**
|
||||
* @var \OC\Files\Mount\Mount | \OC\Files\Mount\MoveableMount $mount
|
||||
*/
|
||||
$sourceMountPoint = $mount->getMountPoint();
|
||||
$result = $mount->moveMount($absolutePath2);
|
||||
$manager->moveMount($sourceMountPoint, $mount->getMountPoint());
|
||||
\OC_FileProxy::runPostProxies('rename', $absolutePath1, $absolutePath2);
|
||||
} elseif ($mp1 == $mp2) {
|
||||
if ($storage1) {
|
||||
$result = $storage1->rename($internalPath1, $internalPath2);
|
||||
|
@ -888,10 +888,6 @@ class View {
|
|||
return $result;
|
||||
}
|
||||
$path = Filesystem::normalizePath($this->fakeRoot . '/' . $directory);
|
||||
/**
|
||||
* @var \OC\Files\Storage\Storage $storage
|
||||
* @var string $internalPath
|
||||
*/
|
||||
list($storage, $internalPath) = Filesystem::resolvePath($path);
|
||||
if ($storage) {
|
||||
$cache = $storage->getCache($internalPath);
|
||||
|
@ -924,9 +920,10 @@ class View {
|
|||
}
|
||||
|
||||
//add a folder for any mountpoint in this directory and add the sizes of other mountpoints to the folders
|
||||
$mountPoints = Filesystem::getMountPoints($path);
|
||||
$mounts = Filesystem::getMountManager()->findIn($path);
|
||||
$dirLength = strlen($path);
|
||||
foreach ($mountPoints as $mountPoint) {
|
||||
foreach ($mounts as $mount) {
|
||||
$mountPoint = $mount->getMountPoint();
|
||||
$subStorage = Filesystem::getStorage($mountPoint);
|
||||
if ($subStorage) {
|
||||
$subCache = $subStorage->getCache('');
|
||||
|
@ -953,7 +950,7 @@ class View {
|
|||
$permissions = $rootEntry['permissions'];
|
||||
// do not allow renaming/deleting the mount point if they are not shared files/folders
|
||||
// for shared files/folders we use the permissions given by the owner
|
||||
if ($subStorage instanceof \OC\Files\Storage\Shared) {
|
||||
if ($mount instanceof MoveableMount) {
|
||||
$rootEntry['permissions'] = $permissions;
|
||||
} else {
|
||||
$rootEntry['permissions'] = $permissions & (\OCP\PERMISSION_ALL - (\OCP\PERMISSION_UPDATE | \OCP\PERMISSION_DELETE));
|
||||
|
|
Loading…
Reference in a new issue