Skip to content

Commit

Permalink
WIP: enh(IMountManager): Add method to get MountPoint from CachedMoun…
Browse files Browse the repository at this point in the history
…tInfo

Signed-off-by: Jonas <jonas@freesources.org>
  • Loading branch information
mejo- committed Sep 25, 2023
1 parent 4f5141c commit 5858970
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
17 changes: 14 additions & 3 deletions apps/workflowengine/lib/Entity/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use OCP\EventDispatcher\GenericEvent;
use OCP\Files\InvalidPathException;
use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountManager;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\IL10N;
Expand Down Expand Up @@ -74,6 +75,8 @@ class File implements IEntity, IDisplayText, IUrl, IIcon, IContextPortation {
private $userManager;
/** @var UserMountCache */
private $userMountCache;
/** @var IMountManager */
private $mountManager;

public function __construct(
IL10N $l10n,
Expand All @@ -82,7 +85,8 @@ public function __construct(
IUserSession $userSession,
ISystemTagManager $tagManager,
IUserManager $userManager,
UserMountCache $userMountCache
UserMountCache $userMountCache,
IMountManager $mountManager
) {
$this->l10n = $l10n;
$this->urlGenerator = $urlGenerator;
Expand All @@ -91,6 +95,7 @@ public function __construct(
$this->tagManager = $tagManager;
$this->userManager = $userManager;
$this->userMountCache = $userMountCache;
$this->mountManager = $mountManager;
}

public function getName(): string {
Expand Down Expand Up @@ -143,12 +148,18 @@ public function isLegitimatedForUserId(string $uid): bool {
$fileId = $node->getId();
}

$mounts = $this->userMountCache->getMountsForFileId($fileId, $uid);
foreach ($mounts as $mount) {
$mountInfos = $this->userMountCache->getMountsForFileId($fileId, $uid);
foreach ($mountInfos as $mountInfo) {
$mount = $this->mountManager->getMountFromMountInfo($mountInfo);

Check failure on line 153 in apps/workflowengine/lib/Entity/File.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidArgument

apps/workflowengine/lib/Entity/File.php:153:57: InvalidArgument: Argument 1 of OCP\Files\Mount\IMountManager::getMountFromMountInfo expects OCP\Files\Mount\CachedMountFileInfo|OCP\Files\Mount\CachedMountInfo, but OCP\Files\Config\ICachedMountFileInfo provided (see https://psalm.dev/004)

Check failure

Code scanning / Psalm

InvalidArgument Error

Argument 1 of OCP\Files\Mount\IMountManager::getMountFromMountInfo expects OCP\Files\Mount\CachedMountFileInfo|OCP\Files\Mount\CachedMountInfo, but OCP\Files\Config\ICachedMountFileInfo provided
if (!empty($mount->getStorage()->getCache()->get($fileId))) {

Check notice

Code scanning / Psalm

PossiblyNullReference Note

Cannot call method getCache on possibly null value
return true;
}
/*
$userFolder = $this->root->getUserFolder($uid);
if (!empty($userFolder->getById($fileId))) {
return true;
}
*/
}
return false;
} catch (NotFoundException $e) {
Expand Down
18 changes: 18 additions & 0 deletions lib/private/Files/Mount/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use OC\Files\Filesystem;
use OC\Files\SetupManager;
use OC\Files\SetupManagerFactory;
use OCP\Files\Config\ICachedMountInfo;
use OCP\Files\Mount\IMountManager;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\NotFoundException;
Expand Down Expand Up @@ -226,4 +227,21 @@ public function getMountsByMountProvider(string $path, array $mountProviders) {
});
}
}

/**
* Return the mount matching a cached mount info (or mount file info)
*
* @param ICachedMountInfo $info
*
* @return IMountPoint
* @throws NotFoundException
*/
public function getMountFromMountInfo(ICachedMountInfo $info): IMountPoint {

Check failure on line 239 in lib/private/Files/Mount/Manager.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

ImplementedParamTypeMismatch

lib/private/Files/Mount/Manager.php:239:57: ImplementedParamTypeMismatch: Argument 1 of OC\Files\Mount\Manager::getMountFromMountInfo has wrong type 'OCP\Files\Config\ICachedMountInfo', expecting 'OCP\Files\Mount\CachedMountFileInfo|OCP\Files\Mount\CachedMountInfo' as defined by OCP\Files\Mount\IMountManager::getMountFromMountInfo (see https://psalm.dev/199)

Check failure

Code scanning / Psalm

ImplementedParamTypeMismatch Error

Argument 1 of OC\Files\Mount\Manager::getMountFromMountInfo has wrong type 'OCP\Files\Config\ICachedMountInfo', expecting 'OCP\Files\Mount\CachedMountFileInfo|OCP\Files\Mount\CachedMountInfo' as defined by OCP\Files\Mount\IMountManager::getMountFromMountInfo
foreach ($this->mounts as $mount) {
if ($mount->getStorageRootId() === $info->getRootId()) {
return $mount;
}
}
throw new NotFoundException("No mount for mount info with rootId " . (string)$info->getRootId());
}
}
12 changes: 12 additions & 0 deletions lib/public/Files/Mount/IMountManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
*/
namespace OCP\Files\Mount;

use OCP\Files\Config\ICachedMountInfo;

/**
* Interface IMountManager
*
Expand Down Expand Up @@ -106,4 +108,14 @@ public function getAll(): array;
* @since 8.2.0
*/
public function findByNumericId(int $id): array;

/**
* Return the mount matching a cached mount info (or mount file info)
*
* @param CachedMountInfo|CachedMountFileInfo $info

Check failure on line 115 in lib/public/Files/Mount/IMountManager.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedDocblockClass

lib/public/Files/Mount/IMountManager.php:115:12: UndefinedDocblockClass: Docblock-defined class, interface or enum named OCP\Files\Mount\CachedMountInfo does not exist (see https://psalm.dev/200)

Check failure on line 115 in lib/public/Files/Mount/IMountManager.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedDocblockClass

lib/public/Files/Mount/IMountManager.php:115:12: UndefinedDocblockClass: Docblock-defined class, interface or enum named OCP\Files\Mount\CachedMountFileInfo does not exist (see https://psalm.dev/200)

Check failure on line 115 in lib/public/Files/Mount/IMountManager.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

MismatchingDocblockParamType

lib/public/Files/Mount/IMountManager.php:115:12: MismatchingDocblockParamType: Parameter $info has wrong type 'OCP\Files\Mount\CachedMountFileInfo|OCP\Files\Mount\CachedMountInfo', should be 'OCP\Files\Config\ICachedMountInfo' (see https://psalm.dev/141)

Check failure on line 115 in lib/public/Files/Mount/IMountManager.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-ocp

UndefinedDocblockClass

lib/public/Files/Mount/IMountManager.php:115:12: UndefinedDocblockClass: Docblock-defined class, interface or enum named OCP\Files\Mount\CachedMountInfo does not exist (see https://psalm.dev/200)

Check failure on line 115 in lib/public/Files/Mount/IMountManager.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-ocp

UndefinedDocblockClass

lib/public/Files/Mount/IMountManager.php:115:12: UndefinedDocblockClass: Docblock-defined class, interface or enum named OCP\Files\Mount\CachedMountFileInfo does not exist (see https://psalm.dev/200)

Check failure on line 115 in lib/public/Files/Mount/IMountManager.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-ocp

MismatchingDocblockParamType

lib/public/Files/Mount/IMountManager.php:115:12: MismatchingDocblockParamType: Parameter $info has wrong type 'OCP\Files\Mount\CachedMountFileInfo|OCP\Files\Mount\CachedMountInfo', should be 'OCP\Files\Config\ICachedMountInfo' (see https://psalm.dev/141)

Check failure

Code scanning / Psalm

UndefinedDocblockClass Error

Docblock-defined class, interface or enum named OCP\Files\Mount\CachedMountInfo does not exist

Check failure

Code scanning / Psalm

UndefinedDocblockClass Error

Docblock-defined class, interface or enum named OCP\Files\Mount\CachedMountFileInfo does not exist

Check failure

Code scanning / Psalm

MismatchingDocblockParamType Error

Parameter $info has wrong type 'OCP\Files\Mount\CachedMountFileInfo|OCP\Files\Mount\CachedMountInfo', should be 'OCP\Files\Config\ICachedMountInfo'
*
* @return IMountPoint
* @since 28.0.0
*/
public function getMountFromMountInfo(ICachedMountInfo $info): IMountPoint;
}

0 comments on commit 5858970

Please sign in to comment.