Skip to content

Commit c7d209d

Browse files
committed
enh(IMountManager): Add method to get MountPoint from CachedMountInfo
Signed-off-by: Jonas <[email protected]>
1 parent c62cac1 commit c7d209d

File tree

5 files changed

+45
-6
lines changed

5 files changed

+45
-6
lines changed

apps/workflowengine/lib/Entity/File.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*
88
* @author Arthur Schiwon <[email protected]>
99
* @author Christoph Wurst <[email protected]>
10+
* @author Jonas Meurer <[email protected]>
1011
*
1112
* @license GNU AGPL version 3 or any later version
1213
*
@@ -31,6 +32,7 @@
3132
use OCP\EventDispatcher\GenericEvent;
3233
use OCP\Files\InvalidPathException;
3334
use OCP\Files\IRootFolder;
35+
use OCP\Files\Mount\IMountManager;
3436
use OCP\Files\Node;
3537
use OCP\Files\NotFoundException;
3638
use OCP\IL10N;
@@ -74,6 +76,8 @@ class File implements IEntity, IDisplayText, IUrl, IIcon, IContextPortation {
7476
private $userManager;
7577
/** @var UserMountCache */
7678
private $userMountCache;
79+
/** @var IMountManager */
80+
private $mountManager;
7781

7882
public function __construct(
7983
IL10N $l10n,
@@ -82,7 +86,8 @@ public function __construct(
8286
IUserSession $userSession,
8387
ISystemTagManager $tagManager,
8488
IUserManager $userManager,
85-
UserMountCache $userMountCache
89+
UserMountCache $userMountCache,
90+
IMountManager $mountManager
8691
) {
8792
$this->l10n = $l10n;
8893
$this->urlGenerator = $urlGenerator;
@@ -91,6 +96,7 @@ public function __construct(
9196
$this->tagManager = $tagManager;
9297
$this->userManager = $userManager;
9398
$this->userMountCache = $userMountCache;
99+
$this->mountManager = $mountManager;
94100
}
95101

96102
public function getName(): string {
@@ -143,10 +149,10 @@ public function isLegitimatedForUserId(string $uid): bool {
143149
$fileId = $node->getId();
144150
}
145151

146-
$mounts = $this->userMountCache->getMountsForFileId($fileId, $uid);
147-
foreach ($mounts as $mount) {
148-
$userFolder = $this->root->getUserFolder($uid);
149-
if (!empty($userFolder->getById($fileId))) {
152+
$mountInfos = $this->userMountCache->getMountsForFileId($fileId, $uid);
153+
foreach ($mountInfos as $mountInfo) {
154+
$mount = $this->mountManager->getMountFromMountInfo($mountInfo);
155+
if ($mount && !empty($mount->getStorage()->getCache()->get($fileId))) {
150156
return true;
151157
}
152158
}

apps/workflowengine/tests/ManagerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use OCP\EventDispatcher\IEventDispatcher;
3636
use OCP\Files\Events\Node\NodeCreatedEvent;
3737
use OCP\Files\IRootFolder;
38+
use OCP\Files\Mount\IMountManager;
3839
use OCP\ICache;
3940
use OCP\ICacheFactory;
4041
use OCP\IConfig;
@@ -408,6 +409,7 @@ public function testUpdateOperation() {
408409
$this->createMock(ISystemTagManager::class),
409410
$this->createMock(IUserManager::class),
410411
$this->createMock(UserMountCache::class),
412+
$this->createMock(IMountManager::class),
411413
])
412414
->setMethodsExcept(['getEvents'])
413415
->getMock();

lib/private/Files/Config/UserMountCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ public function getMountForPath(IUser $user, string $path): ICachedMountInfo {
463463
}, $mounts);
464464
$mounts = array_combine($mountPoints, $mounts);
465465

466-
$current = $path;
466+
$current = rtrim($path, '/');
467467
// walk up the directory tree until we find a path that has a mountpoint set
468468
// the loop will return if a mountpoint is found or break if none are found
469469
while (true) {

lib/private/Files/Mount/Manager.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* @author Robin Appelman <[email protected]>
1111
* @author Robin McCorkell <[email protected]>
1212
* @author Roeland Jago Douma <[email protected]>
13+
* @author Jonas <[email protected]>
1314
*
1415
* @license AGPL-3.0
1516
*
@@ -33,6 +34,7 @@
3334
use OC\Files\Filesystem;
3435
use OC\Files\SetupManager;
3536
use OC\Files\SetupManagerFactory;
37+
use OCP\Files\Config\ICachedMountInfo;
3638
use OCP\Files\Mount\IMountManager;
3739
use OCP\Files\Mount\IMountPoint;
3840
use OCP\Files\NotFoundException;
@@ -226,4 +228,21 @@ public function getMountsByMountProvider(string $path, array $mountProviders) {
226228
});
227229
}
228230
}
231+
232+
/**
233+
* Return the mount matching a cached mount info (or mount file info)
234+
*
235+
* @param ICachedMountInfo $info
236+
*
237+
* @return IMountPoint|null
238+
*/
239+
public function getMountFromMountInfo(ICachedMountInfo $info): ?IMountPoint {
240+
$this->setupManager->setupForPath($info->getMountPoint());
241+
foreach ($this->mounts as $mount) {
242+
if ($mount->getMountPoint() === $info->getMountPoint()) {
243+
return $mount;
244+
}
245+
}
246+
return null;
247+
}
229248
}

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|null
118+
* @since 28.0.0
119+
*/
120+
public function getMountFromMountInfo(ICachedMountInfo $info): ?IMountPoint;
109121
}

0 commit comments

Comments
 (0)