Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
refactor: remove more assumptions around groupfolder storage layout
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Aug 28, 2025
commit ce45a3d85616d6e83ec3a0547f92462c8783d998
27 changes: 2 additions & 25 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace OCA\GroupFolders\AppInfo;

use OC\Files\Node\LazyFolder;
use OCA\Circles\Events\CircleDestroyedEvent;
use OCA\DAV\Connector\Sabre\Principal;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
Expand Down Expand Up @@ -45,10 +44,8 @@
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IMountProviderCollection;
use OCP\Files\Events\Node\NodeRenamedEvent;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountManager;
use OCP\Files\NotFoundException;
use OCP\Files\Storage\IStorageFactory;
use OCP\Group\Events\GroupDeletedEvent;
use OCP\IAppConfig;
Expand Down Expand Up @@ -82,34 +79,14 @@ public function register(IRegistrationContext $context): void {
$context->registerEventListener(CircleDestroyedEvent::class, CircleDestroyedEventListener::class);
$context->registerEventListener(NodeRenamedEvent::class, NodeRenamedListener::class);

$context->registerService('GroupAppFolder', function (ContainerInterface $c): Folder {
/** @var IRootFolder $rootFolder */
$rootFolder = $c->get(IRootFolder::class);

return new LazyFolder($rootFolder, function () use ($rootFolder): Folder {
try {
/** @var Folder $folder */
$folder = $rootFolder->get('__groupfolders');

return $folder;
} catch (NotFoundException) {
return $rootFolder->newFolder('__groupfolders');
}
}, [
'path' => '/__groupfolders'
]);
});

$context->registerService(MountProvider::class, function (ContainerInterface $c): MountProvider {
$rootProvider = fn (): Folder => $c->get('GroupAppFolder');
/** @var IAppConfig $config */
$config = $c->get(IAppConfig::class);
$allowRootShare = $config->getValueString('groupfolders', 'allow_root_share', 'true') === 'true';
$enableEncryption = $config->getValueString('groupfolders', 'enable_encryption', 'false') === 'true';
$allowRootShare = $config->getValueBool('groupfolders', 'allow_root_share', true);
$enableEncryption = $config->getValueBool('groupfolders', 'enable_encryption');

return new MountProvider(
$c->get(FolderManager::class),
$rootProvider,
$c->get(ACLManagerFactory::class),
$c->get(IUserSession::class),
$c->get(IRequest::class),
Expand Down
16 changes: 7 additions & 9 deletions lib/CacheListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
*/
namespace OCA\GroupFolders;

use OC\Files\Storage\Wrapper\Jail;
use OCA\GroupFolders\Mount\GroupFolderStorage;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Cache\CacheEntryInsertedEvent;
use OCP\Files\Cache\CacheEntryUpdatedEvent;
use OCP\Files\Cache\ICacheEvent;
use RuntimeException;

class CacheListener {
public function __construct(
Expand All @@ -26,17 +26,15 @@ public function listen(): void {
}

public function onCacheEvent(ICacheEvent $event): void {
if (!$event->getStorage()->instanceOfStorage(GroupFolderStorage::class)) {
$storage = $event->getStorage();
if (!$storage->instanceOfStorage(GroupFolderStorage::class)) {
return;
}

$jailedPath = preg_replace('/^__groupfolders\/\d+\//', '', $event->getPath());
if ($jailedPath === null) {
throw new RuntimeException('Failed to build jailed path');
if (!$storage->instanceOfStorage(Jail::class)) {
return;
}

if ($jailedPath !== $event->getPath()) {
$event->setPath($jailedPath);
if ($path = $storage->getJailedPath($event->getPath())) {
$event->setPath($path);
}
}
}
13 changes: 6 additions & 7 deletions lib/Command/ACL.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
use OCA\GroupFolders\ACL\Rule;
use OCA\GroupFolders\ACL\RuleManager;
use OCA\GroupFolders\ACL\UserMapping\UserMapping;
use OCA\GroupFolders\Folder\FolderDefinition;
use OCA\GroupFolders\Folder\FolderDefinitionWithPermissions;
use OCA\GroupFolders\Folder\FolderManager;
use OCA\GroupFolders\Folder\FolderWithMappingsAndCache;
use OCA\GroupFolders\Mount\FolderStorageManager;
use OCA\GroupFolders\Mount\MountProvider;
use OCP\Constants;
Expand Down Expand Up @@ -77,13 +77,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return -1;
}

$jailPath = $this->mountProvider->getJailPath($folder->id);
$path = $input->getArgument('path');
$aclManager = $this->aclManagerFactory->getACLManager($user);
if ($this->folderManager->getFolderPermissionsForUser($user, $folder->id) === 0) {
$permissions = 0;
} else {
$permissions = $aclManager->getACLPermissionsForPath($folder->storageId, $jailPath . rtrim('/' . $path, '/'));
$permissions = $aclManager->getACLPermissionsForPath($folder->storageId, $folder->rootCacheEntry->getPath() . rtrim('/' . $path, '/'));
}
$permissionString = Rule::formatRulePermissions(Constants::PERMISSION_ALL, $permissions);
$output->writeln($permissionString);
Expand Down Expand Up @@ -188,13 +187,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 0;
}

private function printPermissions(InputInterface $input, OutputInterface $output, FolderDefinition $folder): void {
$jailPath = $this->mountProvider->getJailPath($folder->id);
private function printPermissions(InputInterface $input, OutputInterface $output, FolderWithMappingsAndCache $folder): void {
$rootPath = $folder->rootCacheEntry->getPath();
$rules = $this->ruleManager->getAllRulesForPrefix(
$this->rootFolder->getMountPoint()->getNumericStorageId(),
$jailPath
$rootPath
);
$jailPathLength = strlen($jailPath) + 1;
$jailPathLength = strlen($rootPath) + 1;
$outputFormat = $input->getOption('output');

switch ($outputFormat) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Mount/CacheRootPermissionsMask.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ class CacheRootPermissionsMask extends CacheWrapper {
public function __construct(
ICache $cache,
private readonly int $mask,
private readonly int $rootId,
) {
parent::__construct($cache);
}

protected function formatCacheEntry($entry): ICacheEntry|false {
$path = $entry->getPath();
$isRoot = $path === '' || (str_starts_with($path, '__groupfolders') && count(explode('/', $path)) === 2);
$isRoot = $entry->getId() === $this->rootId;
if (isset($entry['permissions']) && $isRoot) {
$entry['scan_permissions'] = $entry['permissions'];
$entry['permissions'] &= $this->mask;
Expand Down
10 changes: 8 additions & 2 deletions lib/Mount/GroupMountPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use OC\Files\Mount\MountPoint;
use OC\Files\Storage\Storage;
use OC\Files\Storage\Wrapper\Jail;
use OCA\GroupFolders\Folder\FolderDefinition;
use OCP\Files\Mount\IShareOwnerlessMount;
use OCP\Files\Mount\ISystemMountPoint;
Expand Down Expand Up @@ -45,7 +46,12 @@ public function getFolder(): FolderDefinition {
}

public function getSourcePath(): string {
// todo
return '/__groupfolders/' . $this->getFolderId();
$storage = $this->storage;
if ($storage && $storage->instanceOfStorage(Jail::class)) {
/** @var Jail $storage */
return $storage->getUnJailedPath('');
} else {
return '';
}
}
}
30 changes: 8 additions & 22 deletions lib/Mount/MountProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class MountProvider implements IMountProvider {

public function __construct(
private readonly FolderManager $folderManager,
private readonly \Closure $rootProvider,
private readonly ACLManagerFactory $aclManagerFactory,
private readonly IUserSession $userSession,
private readonly IRequest $request,
Expand Down Expand Up @@ -110,7 +109,7 @@ private function getCurrentUID(): ?string {

$user = $this->userSession->getUser();

return $user ? $user->getUID() : null;
return $user?->getUID();
}

public function getMount(
Expand All @@ -123,14 +122,8 @@ public function getMount(
): ?IMountPoint {
$cacheEntry = $folder->rootCacheEntry;

$storage = $this->getRootFolder()->getStorage();

$storage->setOwner($user?->getUID());

$rootPath = $this->getJailPath($folder->id);

if ($aclManager && $folder->acl && $user) {
$aclRootPermissions = $aclManager->getPermissionsForPathFromRules($rootPath, $rootRules);
$aclRootPermissions = $aclManager->getPermissionsForPathFromRules($cacheEntry->getPath(), $rootRules);
$cacheEntry['permissions'] &= $aclRootPermissions;
}

Expand All @@ -145,6 +138,7 @@ public function getMount(
$maskedStore = new RootPermissionsMask([
'storage' => $maskedStore,
'mask' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE,
'folder' => $folder,
]);
}

Expand Down Expand Up @@ -231,6 +225,11 @@ public function getGroupFolderStorage(
} else {
$baseStorage = $this->folderStorageManager->getBaseStorageForFolder($folder->id, $folder, null, false, $type);
}

if ($user) {
$baseStorage->setOwner($user->getUID());
}

if ($this->enableEncryption) {
$quotaStorage = new GroupFolderStorage([
'storage' => $baseStorage,
Expand All @@ -254,19 +253,6 @@ public function getGroupFolderStorage(
return $quotaStorage;
}

public function getJailPath(int $folderId): string {
return $this->getRootFolder()->getInternalPath() . '/' . $folderId;
}

private function getRootFolder(): Folder {
if (is_null($this->root)) {
$rootProvider = $this->rootProvider;
$this->root = $rootProvider();
}

return $this->root;
}

/**
* @param string[] $mountPoints
* @return string[] An array of paths.
Expand Down
5 changes: 4 additions & 1 deletion lib/Mount/RootPermissionsMask.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace OCA\GroupFolders\Mount;

use OC\Files\Storage\Wrapper\Wrapper;
use OCA\GroupFolders\Folder\FolderDefinition;
use OCP\Constants;
use OCP\Files\Cache\ICache;
use OCP\Files\Storage\IStorage;
Expand All @@ -21,6 +22,7 @@ class RootPermissionsMask extends Wrapper {
* the permissions bits we want to keep
*/
private readonly int $mask;
private readonly FolderDefinition $folder;

/**
* @param array $arguments ['storage' => $storage, 'mask' => $mask]
Expand All @@ -31,6 +33,7 @@ class RootPermissionsMask extends Wrapper {
public function __construct($arguments) {
parent::__construct($arguments);
$this->mask = $arguments['mask'];
$this->folder = $arguments['folder'];
}

private function checkMask(int $permissions): bool {
Expand Down Expand Up @@ -95,6 +98,6 @@ public function getCache(string $path = '', ?IStorage $storage = null): ICache {

$sourceCache = parent::getCache($path, $storage);

return new CacheRootPermissionsMask($sourceCache, $this->mask);
return new CacheRootPermissionsMask($sourceCache, $this->mask, $this->folder->rootId);
}
}
Loading