Skip to content

Commit 74b0139

Browse files
committed
WIP: enh(IMountManager): Add method to get MountPoint from CachedMountInfo
Signed-off-by: Jonas <jonas@freesources.org>
1 parent b05358f commit 74b0139

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

apps/workflowengine/lib/Entity/File.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use OCP\EventDispatcher\GenericEvent;
3232
use OCP\Files\InvalidPathException;
3333
use OCP\Files\IRootFolder;
34+
use OCP\Files\Mount\IMountManager;
3435
use OCP\Files\Node;
3536
use OCP\Files\NotFoundException;
3637
use OCP\IL10N;
@@ -74,6 +75,8 @@ class File implements IEntity, IDisplayText, IUrl, IIcon, IContextPortation {
7475
private $userManager;
7576
/** @var UserMountCache */
7677
private $userMountCache;
78+
/** @var IMountManager */
79+
private $mountManager;
7780

7881
public function __construct(
7982
IL10N $l10n,
@@ -82,7 +85,8 @@ public function __construct(
8285
IUserSession $userSession,
8386
ISystemTagManager $tagManager,
8487
IUserManager $userManager,
85-
UserMountCache $userMountCache
88+
UserMountCache $userMountCache,
89+
IMountManager $mountManager
8690
) {
8791
$this->l10n = $l10n;
8892
$this->urlGenerator = $urlGenerator;
@@ -91,6 +95,7 @@ public function __construct(
9195
$this->tagManager = $tagManager;
9296
$this->userManager = $userManager;
9397
$this->userMountCache = $userMountCache;
98+
$this->mountManager = $mountManager;
9499
}
95100

96101
public function getName(): string {
@@ -143,12 +148,18 @@ public function isLegitimatedForUserId(string $uid): bool {
143148
$fileId = $node->getId();
144149
}
145150

146-
$mounts = $this->userMountCache->getMountsForFileId($fileId, $uid);
147-
foreach ($mounts as $mount) {
151+
$mountInfos = $this->userMountCache->getMountsForFileId($fileId, $uid);
152+
foreach ($mountInfos as $mountInfo) {
153+
$mount = $this->mountManager->getMountFromMountInfo($mountInfo);
154+
if (!empty($mount->getStorage()->getCache()->get($fileId))) {
155+
return true;
156+
}
157+
/*
148158
$userFolder = $this->root->getUserFolder($uid);
149159
if (!empty($userFolder->getById($fileId))) {
150160
return true;
151161
}
162+
*/
152163
}
153164
return false;
154165
} catch (NotFoundException $e) {

lib/private/Files/Mount/Manager.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use OC\Files\Filesystem;
3434
use OC\Files\SetupManager;
3535
use OC\Files\SetupManagerFactory;
36+
use OCP\Files\Config\ICachedMountInfo;
3637
use OCP\Files\Mount\IMountManager;
3738
use OCP\Files\Mount\IMountPoint;
3839
use OCP\Files\NotFoundException;
@@ -226,4 +227,21 @@ public function getMountsByMountProvider(string $path, array $mountProviders) {
226227
});
227228
}
228229
}
230+
231+
/**
232+
* Return the mount matching a cached mount info (or mount file info)
233+
*
234+
* @param ICachedMountInfo $info
235+
*
236+
* @return IMountPoint
237+
* @throws NotFoundException
238+
*/
239+
public function getMountFromMountInfo(ICachedMountInfo $info): IMountPoint {
240+
foreach ($this->mounts as $mount) {
241+
if ($mount->getStorageRootId() === $info->getRootId()) {
242+
return $mount;
243+
}
244+
}
245+
throw new NotFoundException("No mount for mount info with rootId " . (string)$info->getRootId());
246+
}
229247
}

lib/public/Files/Mount/IMountManager.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
*/
2727
namespace OCP\Files\Mount;
2828

29+
use OCP\Files\Config\ICachedMountInfo;
30+
2931
/**
3032
* Interface IMountManager
3133
*
@@ -106,4 +108,14 @@ public function getAll(): array;
106108
* @since 8.2.0
107109
*/
108110
public function findByNumericId(int $id): array;
111+
112+
/**
113+
* Return the mount matching a cached mount info (or mount file info)
114+
*
115+
* @param ICachedMountInfo $info
116+
*
117+
* @return IMountPoint
118+
* @since 28.0.0
119+
*/
120+
public function getMountFromMountInfo(ICachedMountInfo $info): IMountPoint;
109121
}

0 commit comments

Comments
 (0)