Skip to content
Open
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
26 changes: 26 additions & 0 deletions lib/Db/CoreQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,32 @@ public function leftJoinMountpoint(string $aliasMount, IFederatedUser $federated
}


/**
* @param list<string> $paths
*/
public function limitToMountpoints(string $aliasMount, array $paths, bool $forChildren = false): void {
if (count($paths) === 0) {
return;
}

$expr = $this->expr();
$orX = $expr->orX();
Comment thread
cristianscheid marked this conversation as resolved.

if ($forChildren) {
foreach ($paths as $path) {
$orX->add($expr->like($aliasMount . '.mountpoint', $this->createNamedParameter($path . '/_%')));
}
} else {
$pathChunks = array_chunk($paths, 1000);
foreach ($pathChunks as $pathChunk) {
$orX->add($expr->in($aliasMount . '.mountpoint', $this->createNamedParameter($pathChunk, IQueryBuilder::PARAM_STR_ARRAY)));
}
}

$this->andWhere($orX);
}


/**
* @param string $alias
* @param array $default
Expand Down
5 changes: 3 additions & 2 deletions lib/Db/MountRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,18 @@ public function delete(string $token): void {


/**
* @param IFederatedUser $federatedUser
* @param list<string> $paths
*
* @return Mount[]
* @throws RequestBuilderException
*/
public function getForUser(IFederatedUser $federatedUser): array {
public function getForUser(IFederatedUser $federatedUser, array $paths = [], bool $forChildren = false): array {
$qb = $this->getMountSelectSql();
$qb->setOptions([CoreQueryBuilder::MOUNT], ['getData' => true]);
$qb->leftJoinMember(CoreQueryBuilder::MOUNT);
$qb->leftJoinMountpoint(CoreQueryBuilder::MOUNT, $federatedUser);
$qb->limitToInitiator(CoreQueryBuilder::MOUNT, $federatedUser, 'circle_id');
$qb->limitToMountpoints(CoreQueryBuilder::MOUNT, $paths, $forChildren);

return $this->getItemsFromRequest($qb);

Expand Down
53 changes: 52 additions & 1 deletion lib/MountManager/CircleMountProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,19 @@
use OCP\DB\Exception;
use OCP\Federation\ICloudIdManager;
use OCP\Files\Config\IMountProvider;
use OCP\Files\Config\IPartialMountProvider;
use OCP\Files\Config\MountProviderArgs;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\NotFoundException;
use OCP\Files\Storage\IStorageFactory;
use OCP\Http\Client\IClientService;
use OCP\IUser;
use Override;
use Psr\Log\LoggerInterface;

class CircleMountProvider implements IMountProvider {
class CircleMountProvider implements IMountProvider, IPartialMountProvider {
use TArrayTools;

/** @var class-string<ExternalStorage> */
Expand Down Expand Up @@ -169,4 +172,52 @@ private function generateIncrementedMountpoint(Folder $fs, Mount $mount, IFedera
$n++;
}
}

#[Override]
public function getMountsForPath(string $setupPathHint, bool $forChildren, array $mountProviderArgs, IStorageFactory $loader): array {
/** @var array<string, array{federatedUser: IFederatedUser, paths: string[]}> $userMountRequests */
$userMountRequests = [];
/** @var array<string, IMountPoint> $mounts */
$mounts = [];

/** @var MountProviderArgs $mountProviderArg */
foreach ($mountProviderArgs as $mountProviderArg) {
$user = $mountProviderArg->mountInfo->getUser();

$parts = explode('/', $mountProviderArg->mountInfo->getMountPoint());
if ($parts[1] !== $user->getUID() || $parts[2] !== 'files') {
continue;
}

$userMountRequests[$user->getUID()] ??= [
'federatedUser' => $this->federatedUserService->getLocalFederatedUser($user->getUID()),
'paths' => [],
];

$userMountRequests[$user->getUID()]['paths'][] = '/' . implode('/', array_slice($parts, 3));
Comment thread
cristianscheid marked this conversation as resolved.
}

foreach ($userMountRequests as $uid => $userMountRequest) {
$userItems = $this->mountRequest->getForUser(
$userMountRequest['federatedUser'],
$userMountRequest['paths'],
$forChildren
);

foreach ($userItems as $item) {
$mountPoint = '/' . $uid . '/files' . $item->getMountPoint();
if (isset($mounts[$mountPoint])) {
continue;
}
try {
$this->fixDuplicateFile($uid, $item);
$mounts[$mountPoint] = $this->generateCircleMount($item, $loader);
} catch (\Exception $e) {
$this->logger->error('Failed to create Teams mount', ['exception' => $e]);
}
}
}

return $mounts;
}
}
Loading