Merge pull request #14704 from owncloud/storage-wrapper-mount
pass mountpoint to storage wrapper callback
This commit is contained in:
commit
73874ca27f
|
@ -51,6 +51,13 @@ class Watcher {
|
|||
$this->watchPolicy = $policy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int either \OC\Files\Cache\Watcher::CHECK_NEVER, \OC\Files\Cache\Watcher::CHECK_ONCE, \OC\Files\Cache\Watcher::CHECK_ALWAYS
|
||||
*/
|
||||
public function getPolicy() {
|
||||
return $this->watchPolicy;
|
||||
}
|
||||
|
||||
/**
|
||||
* check $path for updates
|
||||
*
|
||||
|
|
|
@ -71,9 +71,10 @@ class MountPoint implements IMountPoint {
|
|||
}
|
||||
|
||||
$mountpoint = $this->formatPath($mountpoint);
|
||||
$this->mountPoint = $mountpoint;
|
||||
if ($storage instanceof Storage) {
|
||||
$this->class = get_class($storage);
|
||||
$this->storage = $this->loader->wrap($mountpoint, $storage);
|
||||
$this->storage = $this->loader->wrap($this, $storage);
|
||||
} else {
|
||||
// Update old classes to new namespace
|
||||
if (strpos($storage, 'OC_Filestorage_') !== false) {
|
||||
|
@ -82,7 +83,6 @@ class MountPoint implements IMountPoint {
|
|||
$this->class = $storage;
|
||||
$this->arguments = $arguments;
|
||||
}
|
||||
$this->mountPoint = $mountpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -113,7 +113,7 @@ class MountPoint implements IMountPoint {
|
|||
|
||||
if (class_exists($this->class)) {
|
||||
try {
|
||||
return $this->loader->getInstance($this->mountPoint, $this->class, $this->arguments);
|
||||
return $this->loader->getInstance($this, $this->class, $this->arguments);
|
||||
} catch (\Exception $exception) {
|
||||
$this->invalidStorage = true;
|
||||
if ($this->mountPoint === '/') {
|
||||
|
@ -195,7 +195,7 @@ class MountPoint implements IMountPoint {
|
|||
$storage = $this->getStorage();
|
||||
// storage can be null if it couldn't be initialized
|
||||
if ($storage != null) {
|
||||
$this->storage = $wrapper($this->mountPoint, $storage);
|
||||
$this->storage = $wrapper($this->mountPoint, $storage, $this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -209,4 +209,13 @@ class MountPoint implements IMountPoint {
|
|||
public function getOption($name, $default) {
|
||||
return isset($this->mountOptions[$name]) ? $this->mountOptions[$name] : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all options for the mount
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions() {
|
||||
return $this->mountOptions;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,8 @@ abstract class Common implements \OC\Files\Storage\Storage {
|
|||
protected $watcher;
|
||||
protected $storageCache;
|
||||
|
||||
protected $mountOptions = [];
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
|
@ -330,7 +332,8 @@ abstract class Common implements \OC\Files\Storage\Storage {
|
|||
}
|
||||
if (!isset($this->watcher)) {
|
||||
$this->watcher = new Watcher($storage);
|
||||
$this->watcher->setPolicy(\OC::$server->getConfig()->getSystemValue('filesystem_check_changes', Watcher::CHECK_ONCE));
|
||||
$globalPolicy = \OC::$server->getConfig()->getSystemValue('filesystem_check_changes', Watcher::CHECK_ONCE);
|
||||
$this->watcher->setPolicy($this->getMountOption('filesystem_check_changes', $globalPolicy));
|
||||
}
|
||||
return $this->watcher;
|
||||
}
|
||||
|
@ -517,4 +520,20 @@ abstract class Common implements \OC\Files\Storage\Storage {
|
|||
throw new InvalidCharacterInPathException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $options
|
||||
*/
|
||||
public function setMountOptions(array $options) {
|
||||
$this->mountOptions = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public function getMountOption($name, $default = null) {
|
||||
return isset($this->mountOptions[$name]) ? $this->mountOptions[$name] : $default;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
namespace OC\Files\Storage;
|
||||
|
||||
use OCP\Files\Mount\IMountPoint;
|
||||
use OCP\Files\Storage\IStorageFactory;
|
||||
|
||||
class StorageFactory implements IStorageFactory {
|
||||
|
@ -55,23 +56,23 @@ class StorageFactory implements IStorageFactory {
|
|||
/**
|
||||
* Create an instance of a storage and apply the registered storage wrappers
|
||||
*
|
||||
* @param string|boolean $mountPoint
|
||||
* @param \OCP\Files\Mount\IMountPoint $mountPoint
|
||||
* @param string $class
|
||||
* @param array $arguments
|
||||
* @return \OCP\Files\Storage
|
||||
*/
|
||||
public function getInstance($mountPoint, $class, $arguments) {
|
||||
public function getInstance(IMountPoint $mountPoint, $class, $arguments) {
|
||||
return $this->wrap($mountPoint, new $class($arguments));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|boolean $mountPoint
|
||||
* @param \OCP\Files\Mount\IMountPoint $mountPoint
|
||||
* @param \OCP\Files\Storage $storage
|
||||
* @return \OCP\Files\Storage
|
||||
*/
|
||||
public function wrap($mountPoint, $storage) {
|
||||
public function wrap(IMountPoint $mountPoint, $storage) {
|
||||
foreach ($this->storageWrappers as $wrapper) {
|
||||
$storage = $wrapper($mountPoint, $storage);
|
||||
$storage = $wrapper($mountPoint->getMountPoint(), $storage, $mountPoint);
|
||||
}
|
||||
return $storage;
|
||||
}
|
||||
|
|
|
@ -98,6 +98,14 @@ class OC_Util {
|
|||
return false;
|
||||
}
|
||||
|
||||
\OC\Files\Filesystem::addStorageWrapper('mount_options', function($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) {
|
||||
if($storage->instanceOfStorage('\OC\Files\Storage\Common')) {
|
||||
/** @var \OC\Files\Storage\Common $storage */
|
||||
$storage->setMountOptions($mount->getOptions());
|
||||
}
|
||||
return $storage;
|
||||
});
|
||||
|
||||
//if we aren't logged in, there is no use to set up the filesystem
|
||||
if ($user != "") {
|
||||
\OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) {
|
||||
|
|
|
@ -64,4 +64,11 @@ interface IMountPoint {
|
|||
* @return mixed
|
||||
*/
|
||||
public function getOption($name, $default);
|
||||
|
||||
/**
|
||||
* Get all options for the mount
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions();
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*/
|
||||
|
||||
namespace OCP\Files\Storage;
|
||||
use OCP\Files\Mount\IMountPoint;
|
||||
|
||||
/**
|
||||
* Creates storage instances and manages and applies storage wrappers
|
||||
|
@ -25,10 +26,10 @@ interface IStorageFactory {
|
|||
public function addStorageWrapper($wrapperName, $callback);
|
||||
|
||||
/**
|
||||
* @param string|boolean $mountPoint
|
||||
* @param \OCP\Files\Mount\IMountPoint $mountPoint
|
||||
* @param string $class
|
||||
* @param array $arguments
|
||||
* @return \OCP\Files\Storage
|
||||
*/
|
||||
public function getInstance($mountPoint, $class, $arguments);
|
||||
public function getInstance(IMountPoint $mountPoint, $class, $arguments);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright (c) 2015 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 Test\Files\Storage;
|
||||
|
||||
use OC\Files\Mount\MountPoint;
|
||||
use OCP\Files\Mount\IMountPoint;
|
||||
use OCP\Files\Storage as IStorage;
|
||||
use Test\TestCase;
|
||||
use OC\Files\Storage\Wrapper\Wrapper;
|
||||
|
||||
class DummyWrapper extends Wrapper {
|
||||
|
||||
}
|
||||
|
||||
class StorageFactory extends TestCase {
|
||||
public function testSimpleWrapper() {
|
||||
$instance = new \OC\Files\Storage\StorageFactory();
|
||||
$mount = new MountPoint('\OC\Files\Storage\Temporary', '/foo', [[]], $instance);
|
||||
$instance->addStorageWrapper('dummy', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
|
||||
$this->assertInstanceOf('\OC\Files\Storage\Temporary', $storage);
|
||||
$this->assertEquals('/foo/', $mount->getMountPoint());
|
||||
$this->assertEquals('/foo/', $mountPoint);
|
||||
return new DummyWrapper(['storage' => $storage]);
|
||||
});
|
||||
$wrapped = $mount->getStorage();
|
||||
$this->assertInstanceOf('\Test\Files\Storage\DummyWrapper', $wrapped);
|
||||
}
|
||||
|
||||
public function testRemoveWrapper() {
|
||||
$instance = new \OC\Files\Storage\StorageFactory();
|
||||
$mount = new MountPoint('\OC\Files\Storage\Temporary', '/foo', [[]], $instance);
|
||||
$instance->addStorageWrapper('dummy', function ($mountPoint, IStorage $storage) {
|
||||
return new DummyWrapper(['storage' => $storage]);
|
||||
});
|
||||
$instance->removeStorageWrapper('dummy');
|
||||
$wrapped = $mount->getStorage();
|
||||
$this->assertInstanceOf('\OC\Files\Storage\Temporary', $wrapped);
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@
|
|||
namespace Test\Files;
|
||||
|
||||
use OC\Files\Cache\Watcher;
|
||||
use OC\Files\Mount\MountPoint;
|
||||
use OC\Files\Storage\Temporary;
|
||||
|
||||
class TemporaryNoTouch extends \OC\Files\Storage\Temporary {
|
||||
|
@ -975,4 +976,21 @@ class View extends \Test\TestCase {
|
|||
$view = new \OC\Files\View('');
|
||||
$this->assertTrue($view->rename('/test/foo.txt', '/test/foo/bar.txt'));
|
||||
}
|
||||
|
||||
public function testSetMountOptionsInStorage() {
|
||||
$mount = new MountPoint('\OC\Files\Storage\Temporary', '/asd/', [[]], \OC\Files\Filesystem::getLoader(), ['foo' => 'bar']);
|
||||
\OC\Files\Filesystem::getMountManager()->addMount($mount);
|
||||
/** @var \OC\Files\Storage\Common $storage */
|
||||
$storage = $mount->getStorage();
|
||||
$this->assertEquals($storage->getMountOption('foo'), 'bar');
|
||||
}
|
||||
|
||||
public function testSetMountOptionsWatcherPolicy() {
|
||||
$mount = new MountPoint('\OC\Files\Storage\Temporary', '/asd/', [[]], \OC\Files\Filesystem::getLoader(), ['filesystem_check_changes' => Watcher::CHECK_NEVER]);
|
||||
\OC\Files\Filesystem::getMountManager()->addMount($mount);
|
||||
/** @var \OC\Files\Storage\Common $storage */
|
||||
$storage = $mount->getStorage();
|
||||
$watcher = $storage->getWatcher();
|
||||
$this->assertEquals(Watcher::CHECK_NEVER, $watcher->getPolicy());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue