Copy mount options to the storage

This commit is contained in:
Robin Appelman 2015-03-05 17:22:48 +01:00
parent 4f0f175f8b
commit 7adda88786
4 changed files with 37 additions and 1 deletions

View File

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

View File

@ -34,6 +34,8 @@ abstract class Common implements \OC\Files\Storage\Storage {
protected $watcher;
protected $storageCache;
protected $mountOptions = [];
/**
* @var string[]
*/
@ -512,4 +514,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;
}
}

View File

@ -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) {

View File

@ -8,6 +8,8 @@
namespace Test\Files;
use OC\Files\Cache\Watcher;
use OC\Files\Filesystem;
use OC\Files\Mount\MountPoint;
use OC\Files\Storage\Temporary;
class TemporaryNoTouch extends \OC\Files\Storage\Temporary {
@ -975,4 +977,12 @@ 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/', [[]], Filesystem::getLoader(), ['foo' => 'bar']);
Filesystem::getMountManager()->addMount($mount);
/** @var \OC\Files\Storage\Common $storage */
$storage = $mount->getStorage();
$this->assertEquals($storage->getMountOption('foo'), 'bar');
}
}