Add a system for (re)movable mount points
This commit is contained in:
parent
79b65269c9
commit
60a659c87e
|
@ -30,6 +30,15 @@ class Manager {
|
||||||
unset($this->mounts[$mountPoint]);
|
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
|
* Find the mount for $path
|
||||||
*
|
*
|
||||||
|
|
|
@ -16,11 +16,11 @@ class Mount {
|
||||||
/**
|
/**
|
||||||
* @var \OC\Files\Storage\Storage $storage
|
* @var \OC\Files\Storage\Storage $storage
|
||||||
*/
|
*/
|
||||||
private $storage = null;
|
protected $storage = null;
|
||||||
private $class;
|
protected $class;
|
||||||
private $storageId;
|
protected $storageId;
|
||||||
private $arguments = array();
|
protected $arguments = array();
|
||||||
private $mountPoint;
|
protected $mountPoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \OC\Files\Storage\Loader $loader
|
* @var \OC\Files\Storage\Loader $loader
|
||||||
|
@ -142,7 +142,7 @@ class Mount {
|
||||||
} else {
|
} else {
|
||||||
$internalPath = substr($path, strlen($this->mountPoint));
|
$internalPath = substr($path, strlen($this->mountPoint));
|
||||||
}
|
}
|
||||||
return $internalPath;
|
return (string)$internalPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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;
|
namespace OC\Files;
|
||||||
|
|
||||||
use OC\Files\Cache\Updater;
|
use OC\Files\Cache\Updater;
|
||||||
|
use OC\Files\Mount\MoveableMount;
|
||||||
|
|
||||||
class View {
|
class View {
|
||||||
private $fakeRoot = '';
|
private $fakeRoot = '';
|
||||||
|
@ -357,10 +358,8 @@ class View {
|
||||||
}
|
}
|
||||||
$postFix = (substr($path, -1, 1) === '/') ? '/' : '';
|
$postFix = (substr($path, -1, 1) === '/') ? '/' : '';
|
||||||
$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
|
$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
|
||||||
list($storage, $internalPath) = Filesystem::resolvePath($absolutePath . $postFix);
|
$mount = Filesystem::getMountManager()->find($absolutePath . $postFix);
|
||||||
if (!($storage instanceof \OC\Files\Storage\Shared) &&
|
if (!($mount instanceof MoveableMount) && $mount->getInternalPath($absolutePath) === '') {
|
||||||
(!$internalPath || $internalPath === '' || $internalPath === '/')
|
|
||||||
) {
|
|
||||||
// do not allow deleting the storage's root / the mount point
|
// do not allow deleting the storage's root / the mount point
|
||||||
// because for some storages it might delete the whole contents
|
// because for some storages it might delete the whole contents
|
||||||
// but isn't supposed to work that way
|
// but isn't supposed to work that way
|
||||||
|
@ -411,18 +410,19 @@ class View {
|
||||||
if ($run) {
|
if ($run) {
|
||||||
$mp1 = $this->getMountPoint($path1 . $postFix1);
|
$mp1 = $this->getMountPoint($path1 . $postFix1);
|
||||||
$mp2 = $this->getMountPoint($path2 . $postFix2);
|
$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);
|
list(, $internalPath2) = Filesystem::resolvePath($absolutePath2 . $postFix2);
|
||||||
// if source and target are on the same storage we can call the rename operation from the
|
if ($internalPath1 == '' and $mount instanceof MoveableMount) {
|
||||||
// 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
|
* @var \OC\Files\Mount\Mount | \OC\Files\Mount\MoveableMount $mount
|
||||||
if ($storage1 instanceof \OC\Files\Storage\Shared) {
|
*/
|
||||||
if ($storage1) {
|
$sourceMountPoint = $mount->getMountPoint();
|
||||||
$result = $storage1->rename($absolutePath1, $absolutePath2);
|
$result = $mount->moveMount($absolutePath2);
|
||||||
|
$manager->moveMount($sourceMountPoint, $mount->getMountPoint());
|
||||||
\OC_FileProxy::runPostProxies('rename', $absolutePath1, $absolutePath2);
|
\OC_FileProxy::runPostProxies('rename', $absolutePath1, $absolutePath2);
|
||||||
} else {
|
|
||||||
$result = false;
|
|
||||||
}
|
|
||||||
} elseif ($mp1 == $mp2) {
|
} elseif ($mp1 == $mp2) {
|
||||||
if ($storage1) {
|
if ($storage1) {
|
||||||
$result = $storage1->rename($internalPath1, $internalPath2);
|
$result = $storage1->rename($internalPath1, $internalPath2);
|
||||||
|
@ -888,10 +888,6 @@ class View {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
$path = Filesystem::normalizePath($this->fakeRoot . '/' . $directory);
|
$path = Filesystem::normalizePath($this->fakeRoot . '/' . $directory);
|
||||||
/**
|
|
||||||
* @var \OC\Files\Storage\Storage $storage
|
|
||||||
* @var string $internalPath
|
|
||||||
*/
|
|
||||||
list($storage, $internalPath) = Filesystem::resolvePath($path);
|
list($storage, $internalPath) = Filesystem::resolvePath($path);
|
||||||
if ($storage) {
|
if ($storage) {
|
||||||
$cache = $storage->getCache($internalPath);
|
$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
|
//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);
|
$dirLength = strlen($path);
|
||||||
foreach ($mountPoints as $mountPoint) {
|
foreach ($mounts as $mount) {
|
||||||
|
$mountPoint = $mount->getMountPoint();
|
||||||
$subStorage = Filesystem::getStorage($mountPoint);
|
$subStorage = Filesystem::getStorage($mountPoint);
|
||||||
if ($subStorage) {
|
if ($subStorage) {
|
||||||
$subCache = $subStorage->getCache('');
|
$subCache = $subStorage->getCache('');
|
||||||
|
@ -953,7 +950,7 @@ class View {
|
||||||
$permissions = $rootEntry['permissions'];
|
$permissions = $rootEntry['permissions'];
|
||||||
// do not allow renaming/deleting the mount point if they are not shared files/folders
|
// 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
|
// 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;
|
$rootEntry['permissions'] = $permissions;
|
||||||
} else {
|
} else {
|
||||||
$rootEntry['permissions'] = $permissions & (\OCP\PERMISSION_ALL - (\OCP\PERMISSION_UPDATE | \OCP\PERMISSION_DELETE));
|
$rootEntry['permissions'] = $permissions & (\OCP\PERMISSION_ALL - (\OCP\PERMISSION_UPDATE | \OCP\PERMISSION_DELETE));
|
||||||
|
|
Loading…
Reference in New Issue