Skip to content

Commit

Permalink
store mountprovider for each mount in the mounts table
Browse files Browse the repository at this point in the history
this enabled more fine grained filesystem setup

Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Feb 3, 2022
1 parent d635d58 commit 22d0a74
Show file tree
Hide file tree
Showing 21 changed files with 151 additions and 26 deletions.
2 changes: 1 addition & 1 deletion apps/files_external/lib/Config/ExternalMountPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ExternalMountPoint extends MountPoint {

public function __construct(StorageConfig $storageConfig, $storage, $mountpoint, $arguments = null, $loader = null, $mountOptions = null, $mountId = null) {
$this->storageConfig = $storageConfig;
parent::__construct($storage, $mountpoint, $arguments, $loader, $mountOptions, $mountId);
parent::__construct($storage, $mountpoint, $arguments, $loader, $mountOptions, $mountId, ConfigAdapter::class);
}

public function getMountType() {
Expand Down
2 changes: 1 addition & 1 deletion apps/files_sharing/lib/External/Mount.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Mount extends MountPoint implements MoveableMount {
* @param \OC\Files\Storage\StorageFactory $loader
*/
public function __construct($storage, $mountpoint, $options, $manager, $loader = null) {
parent::__construct($storage, $mountpoint, $options, $loader);
parent::__construct($storage, $mountpoint, $options, $loader, null, null, MountProvider::class);
$this->manager = $manager;
}

Expand Down
2 changes: 1 addition & 1 deletion apps/files_sharing/lib/SharedMount.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function __construct($storage, array $mountpoints, $arguments, IStorageFa

$newMountPoint = $this->verifyMountPoint($this->superShare, $mountpoints, $folderExistCache);
$absMountPoint = '/' . $this->user . '/files' . $newMountPoint;
parent::__construct($storage, $absMountPoint, $arguments, $loader);
parent::__construct($storage, $absMountPoint, $arguments, $loader, null, null, MountProvider::class);
}

/**
Expand Down
37 changes: 37 additions & 0 deletions core/Migrations/Version240000Date20220202150027.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace OC\Core\Migrations;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

/**
* Auto-generated migration step: Please modify to your needs!
*/
class Version240000Date20220202150027 extends SimpleMigrationStep {
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

$table = $schema->getTable('mounts');
if (!$table->hasColumn('mount_provider')) {
$table->addColumn('mount_provider', Types::STRING, [
'notnull' => false,
'length' => 128,
]);
return $schema;
}
return null;
}
}
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,7 @@
'OC\\Core\\Migrations\\Version23000Date20210930122352' => $baseDir . '/core/Migrations/Version23000Date20210930122352.php',
'OC\\Core\\Migrations\\Version23000Date20211203110726' => $baseDir . '/core/Migrations/Version23000Date20211203110726.php',
'OC\\Core\\Migrations\\Version23000Date20211213203940' => $baseDir . '/core/Migrations/Version23000Date20211213203940.php',
'OC\\Core\\Migrations\\Version240000Date20220202150027' => $baseDir . '/core/Migrations/Version240000Date20220202150027.php',
'OC\\Core\\Migrations\\Version24000Date20211210141942' => $baseDir . '/core/Migrations/Version24000Date20211210141942.php',
'OC\\Core\\Migrations\\Version24000Date20211222112246' => $baseDir . '/core/Migrations/Version24000Date20211222112246.php',
'OC\\Core\\Migrations\\Version24000Date20211230140012' => $baseDir . '/core/Migrations/Version24000Date20211230140012.php',
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Core\\Migrations\\Version23000Date20210930122352' => __DIR__ . '/../../..' . '/core/Migrations/Version23000Date20210930122352.php',
'OC\\Core\\Migrations\\Version23000Date20211203110726' => __DIR__ . '/../../..' . '/core/Migrations/Version23000Date20211203110726.php',
'OC\\Core\\Migrations\\Version23000Date20211213203940' => __DIR__ . '/../../..' . '/core/Migrations/Version23000Date20211213203940.php',
'OC\\Core\\Migrations\\Version240000Date20220202150027' => __DIR__ . '/../../..' . '/core/Migrations/Version240000Date20220202150027.php',
'OC\\Core\\Migrations\\Version24000Date20211210141942' => __DIR__ . '/../../..' . '/core/Migrations/Version24000Date20211210141942.php',
'OC\\Core\\Migrations\\Version24000Date20211222112246' => __DIR__ . '/../../..' . '/core/Migrations/Version24000Date20211222112246.php',
'OC\\Core\\Migrations\\Version24000Date20211230140012' => __DIR__ . '/../../..' . '/core/Migrations/Version24000Date20211230140012.php',
Expand Down
17 changes: 13 additions & 4 deletions lib/private/Files/Config/CachedMountFileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,29 @@ class CachedMountFileInfo extends CachedMountInfo implements ICachedMountFileInf
/** @var string */
private $internalPath;

public function __construct(IUser $user, $storageId, $rootId, $mountPoint, $mountId, $rootInternalPath, $internalPath) {
parent::__construct($user, $storageId, $rootId, $mountPoint, $mountId, $rootInternalPath);
public function __construct(
IUser $user,
int $storageId,
int $rootId,
string $mountPoint,
$mountId,
string $mountProvider,
string $rootInternalPath,
string $internalPath
) {
parent::__construct($user, $storageId, $rootId, $mountPoint, $mountProvider, $mountId, $rootInternalPath);
$this->internalPath = $internalPath;
}

public function getInternalPath() {
public function getInternalPath(): string {
if ($this->getRootInternalPath()) {
return substr($this->internalPath, strlen($this->getRootInternalPath()) + 1);
} else {
return $this->internalPath;
}
}

public function getPath() {
public function getPath(): string {
return $this->getMountPoint() . $this->getInternalPath();
}
}
18 changes: 17 additions & 1 deletion lib/private/Files/Config/CachedMountInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class CachedMountInfo implements ICachedMountInfo {
*/
protected $rootInternalPath;

/** @var string */
protected $mountProvider;

/**
* CachedMountInfo constructor.
*
Expand All @@ -68,13 +71,22 @@ class CachedMountInfo implements ICachedMountInfo {
* @param int|null $mountId
* @param string $rootInternalPath
*/
public function __construct(IUser $user, $storageId, $rootId, $mountPoint, $mountId = null, $rootInternalPath = '') {
public function __construct(
IUser $user,
int $storageId,
int $rootId,
string $mountPoint,
string $mountProvider,
int $mountId = null,
string $rootInternalPath = ''
) {
$this->user = $user;
$this->storageId = $storageId;
$this->rootId = $rootId;
$this->mountPoint = $mountPoint;
$this->mountId = $mountId;
$this->rootInternalPath = $rootInternalPath;
$this->mountProvider = $mountProvider;
}

/**
Expand Down Expand Up @@ -138,4 +150,8 @@ public function getMountId() {
public function getRootInternalPath() {
return $this->rootInternalPath;
}

public function getMountProvider(): string {
return $this->mountProvider;
}
}
4 changes: 4 additions & 0 deletions lib/private/Files/Config/LazyStorageMountInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,8 @@ public function getMountId() {
public function getRootInternalPath() {
return $this->mount->getInternalPath($this->mount->getMountPoint());
}

public function getMountProvider(): string {
return $this->mount->getMountProvider();
}
}
18 changes: 15 additions & 3 deletions lib/private/Files/Config/UserMountCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ private function findChangedMounts(array $newMounts, array $cachedMounts) {
if (
$newMount->getMountPoint() !== $cachedMount->getMountPoint() ||
$newMount->getStorageId() !== $cachedMount->getStorageId() ||
$newMount->getMountId() !== $cachedMount->getMountId()
$newMount->getMountId() !== $cachedMount->getMountId() ||
$newMount->getMountProvider() !== $cachedMount->getMountProvider()
) {
$changed[] = $newMount;
}
Expand All @@ -180,7 +181,8 @@ private function addToCache(ICachedMountInfo $mount) {
'root_id' => $mount->getRootId(),
'user_id' => $mount->getUser()->getUID(),
'mount_point' => $mount->getMountPoint(),
'mount_id' => $mount->getMountId()
'mount_id' => $mount->getMountId(),
'mount_provider' => $mount->getMountProvider(),
], ['root_id', 'user_id']);
} else {
// in some cases this is legitimate, like orphaned shares
Expand All @@ -195,6 +197,7 @@ private function updateCachedMount(ICachedMountInfo $mount) {
->set('storage_id', $builder->createNamedParameter($mount->getStorageId()))
->set('mount_point', $builder->createNamedParameter($mount->getMountPoint()))
->set('mount_id', $builder->createNamedParameter($mount->getMountId(), IQueryBuilder::PARAM_INT))
->set('mount_provider', $builder->createNamedParameter($mount->getMountProvider()))
->where($builder->expr()->eq('user_id', $builder->createNamedParameter($mount->getUser()->getUID())))
->andWhere($builder->expr()->eq('root_id', $builder->createNamedParameter($mount->getRootId(), IQueryBuilder::PARAM_INT)));

Expand All @@ -219,7 +222,15 @@ private function dbRowToMountInfo(array $row) {
if (!is_null($mount_id)) {
$mount_id = (int)$mount_id;
}
return new CachedMountInfo($user, (int)$row['storage_id'], (int)$row['root_id'], $row['mount_point'], $mount_id, isset($row['path']) ? $row['path'] : '');
return new CachedMountInfo(
$user,
(int)$row['storage_id'],
(int)$row['root_id'],
$row['mount_point'],
$row['mount_provider'] ?? '',
$mount_id,
isset($row['path']) ? $row['path'] : '',
);
}

/**
Expand Down Expand Up @@ -356,6 +367,7 @@ public function getMountsForFileId($fileId, $user = null) {
$mount->getRootId(),
$mount->getMountPoint(),
$mount->getMountId(),
$mount->getMountProvider(),
$mount->getRootInternalPath(),
$internalPath
);
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Files/Mount/CacheMountProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
}

return [
new MountPoint('\OC\Files\Storage\Local', '/' . $user->getUID() . '/cache', ['datadir' => $cacheDir, $loader]),
new MountPoint('\OC\Files\Storage\Local', '/' . $user->getUID() . '/uploads', ['datadir' => $cacheDir . '/uploads', $loader])
new MountPoint('\OC\Files\Storage\Local', '/' . $user->getUID() . '/cache', ['datadir' => $cacheDir], $loader, null, null, self::class),
new MountPoint('\OC\Files\Storage\Local', '/' . $user->getUID() . '/uploads', ['datadir' => $cacheDir . '/uploads'], $loader, null, null, self::class)
];
} else {
return [];
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Mount/LocalHomeMountProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ class LocalHomeMountProvider implements IHomeMountProvider {
*/
public function getHomeMountForUser(IUser $user, IStorageFactory $loader) {
$arguments = ['user' => $user];
return new MountPoint('\OC\Files\Storage\Home', '/' . $user->getUID(), $arguments, $loader);
return new MountPoint('\OC\Files\Storage\Home', '/' . $user->getUID(), $arguments, $loader, null, null, self::class);
}
}
20 changes: 19 additions & 1 deletion lib/private/Files/Mount/MountPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use OC\Files\Storage\Storage;
use OC\Files\Storage\StorageFactory;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Storage\IStorageFactory;
use OCP\ILogger;

class MountPoint implements IMountPoint {
Expand Down Expand Up @@ -76,16 +77,28 @@ class MountPoint implements IMountPoint {
/** @var int|null */
protected $mountId;

/** @var string */
protected $mountProvider;

/**
* @param string|\OC\Files\Storage\Storage $storage
* @param string $mountpoint
* @param array $arguments (optional) configuration for the storage backend
* @param \OCP\Files\Storage\IStorageFactory $loader
* @param array $mountOptions mount specific options
* @param int|null $mountId
* @param string|null $mountProvider
* @throws \Exception
*/
public function __construct($storage, $mountpoint, $arguments = null, $loader = null, $mountOptions = null, $mountId = null) {
public function __construct(
$storage,
string $mountpoint,
array $arguments = null,
IStorageFactory $loader = null,
array $mountOptions = null,
int $mountId = null,
string $mountProvider = null
) {
if (is_null($arguments)) {
$arguments = [];
}
Expand Down Expand Up @@ -113,6 +126,7 @@ public function __construct($storage, $mountpoint, $arguments = null, $loader =
$this->class = $storage;
$this->arguments = $arguments;
}
$this->mountProvider = $mountProvider ?? '';
}

/**
Expand Down Expand Up @@ -286,4 +300,8 @@ public function getMountId() {
public function getMountType() {
return '';
}

public function getMountProvider(): string {
return $this->mountProvider;
}
}
2 changes: 1 addition & 1 deletion lib/private/Files/Mount/ObjectHomeMountProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function getHomeMountForUser(IUser $user, IStorageFactory $loader) {
return null;
}

return new MountPoint('\OC\Files\ObjectStore\HomeObjectStoreStorage', '/' . $user->getUID(), $config['arguments'], $loader);
return new MountPoint('\OC\Files\ObjectStore\HomeObjectStoreStorage', '/' . $user->getUID(), $config['arguments'], $loader, null, null, self::class);
}

/**
Expand Down
10 changes: 8 additions & 2 deletions lib/private/Files/Mount/ObjectStorePreviewCacheMountProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ public function getRootMounts(IStorageFactory $loader): array {
AppdataPreviewObjectStoreStorage::class,
'/appdata_' . $instanceId . '/preview/' . $parent . '/' . $child,
$this->getMultiBucketObjectStore($i),
$loader
$loader,
null,
null,
self::class
);
$i++;
}
Expand All @@ -87,7 +90,10 @@ public function getRootMounts(IStorageFactory $loader): array {
$fakeRootStorageJail,
'/appdata_' . $instanceId . '/preview/old-multibucket',
null,
$loader
$loader,
null,
null,
self::class
);

return $mountPoints;
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Node/LazyFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class LazyFolder implements \OCP\Files\Folder {
private $folderClosure;

/** @var LazyFolder | null */
private $folder = null;
protected $folder = null;

/**
* LazyFolder constructor.
Expand Down
13 changes: 7 additions & 6 deletions lib/private/Files/Node/Root.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

namespace OC\Files\Node;

use OC\Cache\CappedMemoryCache;
Expand Down Expand Up @@ -87,8 +88,8 @@ class Root extends Folder implements IRootFolder {
* @param IUserManager $userManager
*/
public function __construct($manager,
$view,
$user,
$view,
$user,
IUserMountCache $userMountCache,
ILogger $logger,
IUserManager $userManager) {
Expand Down Expand Up @@ -189,9 +190,9 @@ public function unMount($mount) {

/**
* @param string $path
* @throws \OCP\Files\NotFoundException
* @throws \OCP\Files\NotPermittedException
* @return Node
* @throws \OCP\Files\NotPermittedException
* @throws \OCP\Files\NotFoundException
*/
public function get($path) {
$path = $this->normalizePath($path);
Expand All @@ -212,8 +213,8 @@ public function get($path) {

/**
* @param string $targetPath
* @throws \OCP\Files\NotPermittedException
* @return \OC\Files\Node\Node
* @throws \OCP\Files\NotPermittedException
*/
public function rename($targetPath) {
throw new NotPermittedException();
Expand All @@ -225,8 +226,8 @@ public function delete() {

/**
* @param string $targetPath
* @throws \OCP\Files\NotPermittedException
* @return \OC\Files\Node\Node
* @throws \OCP\Files\NotPermittedException
*/
public function copy($targetPath) {
throw new NotPermittedException();
Expand Down
8 changes: 8 additions & 0 deletions lib/public/Files/Config/ICachedMountInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,12 @@ public function getMountId();
* @since 11.0.0
*/
public function getRootInternalPath();

/**
* Get the class of the mount provider that this mount originates from
*
* @return string
* @since 24.0.0
*/
public function getMountProvider(): string;
}
Loading

0 comments on commit 22d0a74

Please sign in to comment.