Skip to content

Commit fad3857

Browse files
committed
fixup!: Move common logic to caller
Signed-off-by: Louis Chmn <[email protected]>
1 parent 1fc7dcb commit fad3857

File tree

3 files changed

+19
-34
lines changed

3 files changed

+19
-34
lines changed

apps/files_sharing/lib/External/MountProvider.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use OCP\DB\QueryBuilder\IQueryBuilder;
1414
use OCP\Federation\ICloudIdManager;
1515
use OCP\Files\Config\IMountProvider;
16-
use OCP\Files\Config\IMountProviderArgs;
1716
use OCP\Files\Config\IPartialMountProvider;
1817
use OCP\Files\Storage\IStorageFactory;
1918
use OCP\Http\Client\IClientService;
@@ -78,20 +77,7 @@ public function getMountsForPath(
7877
array $mountProviderArgs,
7978
IStorageFactory $loader,
8079
): array {
81-
if (empty($mountProviderArgs)) {
82-
return [];
83-
}
84-
85-
$userId = null;
86-
$user = null;
87-
foreach ($mountProviderArgs as $mountProviderArg) {
88-
if ($userId === null) {
89-
$user = $mountProviderArg->mountInfo->getUser();
90-
$userId = $user->getUID();
91-
} elseif ($userId !== $mountProviderArg->mountInfo->getUser()->getUID()) {
92-
throw new \LogicException('Mounts must belong to the same user!');
93-
}
94-
}
80+
$user = $mountProviderArgs[0]->mountInfo->getUser();
9581

9682
if (!$forChildren) {
9783
// override path with mount point when fetching without children

apps/files_sharing/lib/MountProvider.php

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use OCP\Cache\CappedMemoryCache;
1515
use OCP\EventDispatcher\IEventDispatcher;
1616
use OCP\Files\Config\IMountProvider;
17-
use OCP\Files\Config\IMountProviderArgs;
1817
use OCP\Files\Config\IPartialMountProvider;
1918
use OCP\Files\Mount\IMountManager;
2019
use OCP\Files\Mount\IMountPoint;
@@ -364,21 +363,9 @@ public function getMountsForPath(
364363
array $mountProviderArgs,
365364
IStorageFactory $loader,
366365
): array {
367-
if (empty($mountProviderArgs)) {
368-
return [];
369-
}
370-
371366
$limit = -1;
372-
$userId = null;
373-
$user = null;
374-
foreach ($mountProviderArgs as $mountProviderArg) {
375-
if ($userId === null) {
376-
$user = $mountProviderArg->mountInfo->getUser();
377-
$userId = $user->getUID();
378-
} elseif ($userId !== $mountProviderArg->mountInfo->getUser()->getUID()) {
379-
throw new \LogicException('Mounts must belong to the same user!');
380-
}
381-
}
367+
$user = $mountProviderArgs[0]->mountInfo->getUser();
368+
$userId = $user->getUID();
382369

383370
if (!$forChildren) {
384371
// override path with mount point when fetching without children
@@ -406,10 +393,7 @@ public function getMountsForPath(
406393
$shares = $this->filterShares($shares, $userId);
407394
$superShares = $this->buildSuperShares($shares, $user);
408395

409-
return $this->getMountsFromSuperShares($userId,
410-
$superShares,
411-
$loader,
412-
$user);
396+
return $this->getMountsFromSuperShares($userId, $superShares, $loader, $user);
413397
}
414398

415399
/**

lib/private/Files/Config/MountProviderCollection.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,27 @@ public function getUserMountsFromProviderByPath(
9999
return [];
100100
}
101101

102+
if (empty($mountProviderArgs)) {
103+
return [];
104+
}
105+
102106
if (!is_a($providerClass, IPartialMountProvider::class, true)) {
103107
throw new \LogicException(
104108
'Mount provider does not support partial mounts'
105109
);
106110
}
107111

112+
$userId = null;
113+
$user = null;
114+
foreach ($mountProviderArgs as $mountProviderArg) {
115+
if ($userId === null) {
116+
$user = $mountProviderArg->mountInfo->getUser();
117+
$userId = $user->getUID();
118+
} elseif ($userId !== $mountProviderArg->mountInfo->getUser()->getUID()) {
119+
throw new \LogicException('Mounts must belong to the same user!');
120+
}
121+
}
122+
108123
/** @var IPartialMountProvider $provider */
109124
return $provider->getMountsForPath(
110125
$path,

0 commit comments

Comments
 (0)