Skip to content

Commit 0fc7f9b

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

3 files changed

Lines changed: 34 additions & 64 deletions

File tree

apps/files_sharing/lib/External/MountProvider.php

Lines changed: 1 addition & 30 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,35 +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-
}
95-
96-
if (!$forChildren) {
97-
// override path with mount point when fetching without children
98-
$path = $mountProviderArgs[0]->mountInfo->getMountPoint();
99-
}
100-
101-
// remove /uid/files as the target is stored without
102-
$path = \substr($path, \strlen('/' . $userId . '/files'));
103-
// remove trailing slash
104-
$path = \rtrim($path, '/');
105-
106-
// make sure trailing slash is present when loading children
107-
if ($forChildren || $path === '') {
108-
$path .= '/';
109-
}
80+
$user = $mountProviderArgs[0]->mountInfo->getUser();
11081

11182
$qb = $this->connection->getQueryBuilder();
11283
$qb->select('id', 'remote', 'share_token', 'password', 'mountpoint', 'owner')

apps/files_sharing/lib/MountProvider.php

Lines changed: 3 additions & 34 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,36 +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-
}
382-
383-
if (!$forChildren) {
384-
// override path with mount point when fetching without children
385-
$path = $mountProviderArgs[0]->mountInfo->getMountPoint();
386-
}
387-
388-
// remove /uid/files as the target is stored without
389-
$path = \substr($path, \strlen('/' . $userId . '/files'));
390-
// remove trailing slash
391-
$path = \rtrim($path, '/');
392-
393-
// make sure trailing slash is present when loading children
394-
if ($forChildren || $path === '') {
395-
$path .= '/';
396-
}
367+
$user = $mountProviderArgs[0]->mountInfo->getUser();
368+
$userId = $user->getUID();
397369

398370
$shares = $this->mergeIterables(
399371
$this->shareManager->getSharedWithByPath($userId, IShare::TYPE_USER, $path, $forChildren, $limit),
@@ -406,10 +378,7 @@ public function getMountsForPath(
406378
$shares = $this->filterShares($shares, $userId);
407379
$superShares = $this->buildSuperShares($shares, $user);
408380

409-
return $this->getMountsFromSuperShares($userId,
410-
$superShares,
411-
$loader,
412-
$user);
381+
return $this->getMountsFromSuperShares($userId, $superShares, $loader, $user);
413382
}
414383

415384
/**

lib/private/Files/Config/MountProviderCollection.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,42 @@ 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+
123+
if (!$forChildren) {
124+
// override path with mount point when fetching without children
125+
$path = $mountProviderArgs[0]->mountInfo->getMountPoint();
126+
}
127+
128+
// remove /uid/files as the target is stored without
129+
$path = \substr($path, \strlen('/' . $userId . '/files'));
130+
// remove trailing slash
131+
$path = \rtrim($path, '/');
132+
133+
// make sure trailing slash is present when loading children
134+
if ($forChildren || $path === '') {
135+
$path .= '/';
136+
}
137+
108138
/** @var IPartialMountProvider $provider */
109139
return $provider->getMountsForPath(
110140
$path,

0 commit comments

Comments
 (0)