Skip to content

Commit a924e07

Browse files
committed
move logic to decide what to setup to setupmanager
Signed-off-by: Robin Appelman <[email protected]>
1 parent 34f3b66 commit a924e07

File tree

4 files changed

+41
-36
lines changed

4 files changed

+41
-36
lines changed

apps/files_sharing/tests/External/ManagerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ protected function setUp(): void {
110110
$this->mountManager = new \OC\Files\Mount\Manager(
111111
$this->createMock(IEventLogger::class),
112112
$this->createMock(IMountProviderCollection::class),
113-
$this->createMock(IUserSession::class),
113+
$this->createMock(IUserManager::class),
114114
$this->createMock(IEventDispatcher::class)
115115
);
116116
$this->clientService = $this->getMockBuilder(IClientService::class)

lib/private/Files/Mount/Manager.php

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,13 @@
3131
use OC\Cache\CappedMemoryCache;
3232
use OC\Files\Filesystem;
3333
use OC\Files\SetupManager;
34-
use OC\Setup;
3534
use OCP\Diagnostics\IEventLogger;
3635
use OCP\EventDispatcher\IEventDispatcher;
3736
use OCP\Files\Config\IMountProviderCollection;
3837
use OCP\Files\Mount\IMountManager;
3938
use OCP\Files\Mount\IMountPoint;
4039
use OCP\Files\NotFoundException;
41-
use OCP\IUserSession;
40+
use OCP\IUserManager;
4241

4342
class Manager implements IMountManager {
4443
/** @var MountPoint[] */
@@ -50,12 +49,12 @@ class Manager implements IMountManager {
5049
public function __construct(
5150
IEventLogger $eventLogger,
5251
IMountProviderCollection $mountProviderCollection,
53-
IUserSession $userSession,
52+
IUserManager $userManager,
5453
IEventDispatcher $eventDispatcher
5554
) {
5655
$this->pathCache = new CappedMemoryCache();
5756
$this->inPathCache = new CappedMemoryCache();
58-
$this->setupManager = new SetupManager($eventLogger, $mountProviderCollection, $this, $userSession, $eventDispatcher);
57+
$this->setupManager = new SetupManager($eventLogger, $mountProviderCollection, $this, $userManager, $eventDispatcher);
5958
}
6059

6160
/**
@@ -91,26 +90,14 @@ public function moveMount(string $mountPoint, string $target) {
9190
$this->inPathCache->clear();
9291
}
9392

94-
private function setupForFind(string $path) {
95-
if (strpos($path, '/appdata_' . \OC_Util::getInstanceId()) === 0) {
96-
// for appdata, we only setup the root bits, not the user bits
97-
$this->setupManager->setupRoot();
98-
} elseif (strpos($path, '/files_external/uploads/') === 0) {
99-
// for OC\Security\CertificateManager, we only setup the root bits, not the user bits
100-
$this->setupManager->setupRoot();
101-
} else {
102-
$this->setupManager->setupForCurrentUser();
103-
}
104-
}
105-
10693
/**
10794
* Find the mount for $path
10895
*
10996
* @param string $path
11097
* @return MountPoint|null
11198
*/
11299
public function find(string $path): ?MountPoint {
113-
$this->setupForFind($path);
100+
$this->setupManager->setupForPath($path);
114101
$path = Filesystem::normalizePath($path);
115102

116103
if (isset($this->pathCache[$path])) {
@@ -143,7 +130,7 @@ public function find(string $path): ?MountPoint {
143130
* @return MountPoint[]
144131
*/
145132
public function findIn(string $path): array {
146-
$this->setupForFind($path);
133+
$this->setupManager->setupForPath($path);
147134
$path = $this->formatPath($path);
148135

149136
if (isset($this->inPathCache[$path])) {

lib/private/Files/SetupManager.php

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,28 @@
4343
use OCP\Files\Mount\IMountPoint;
4444
use OCP\Files\Storage\IStorage;
4545
use OCP\IUser;
46-
use OCP\IUserSession;
46+
use OCP\IUserManager;
4747

4848
class SetupManager {
4949
private bool $rootSetup = false;
5050
private IEventLogger $eventLogger;
5151
private IMountProviderCollection $mountProviderCollection;
5252
private IMountManager $mountManager;
53-
private IUserSession $userSession;
53+
private IUserManager $userManager;
5454
private array $setupUsers = [];
5555
private IEventDispatcher $eventDispatcher;
5656

5757
public function __construct(
5858
IEventLogger $eventLogger,
5959
IMountProviderCollection $mountProviderCollection,
6060
IMountManager $mountManager,
61-
IUserSession $userSession,
61+
IUserManager $userManager,
6262
IEventDispatcher $eventDispatcher
6363
) {
6464
$this->eventLogger = $eventLogger;
6565
$this->mountProviderCollection = $mountProviderCollection;
6666
$this->mountManager = $mountManager;
67-
$this->userSession = $userSession;
67+
$this->userManager = $userManager;
6868
$this->eventDispatcher = $eventDispatcher;
6969
}
7070

@@ -138,16 +138,10 @@ private function setupBuiltinWrappers() {
138138
});
139139
}
140140

141-
public function setupForCurrentUser() {
142-
$user = $this->userSession->getUser();
143-
if ($user) {
144-
$this->setupForUser($user);
145-
} else {
146-
$this->setupRoot();
147-
}
148-
}
149-
150-
public function setupForUser(IUser $user) {
141+
/**
142+
* Setup the full filesystem for the specified user
143+
*/
144+
public function setupForUser(IUser $user): void {
151145
$this->setupRoot();
152146

153147
if (in_array($user->getUID(), $this->setupUsers)) {
@@ -172,7 +166,10 @@ public function setupForUser(IUser $user) {
172166
$this->eventLogger->end('setup_fs');
173167
}
174168

175-
public function setupRoot() {
169+
/**
170+
* Set up the root filesystem
171+
*/
172+
public function setupRoot(): void {
176173
//setting up the filesystem twice can only lead to trouble
177174
if ($this->rootSetup) {
178175
return;
@@ -197,6 +194,27 @@ public function setupRoot() {
197194
$this->eventLogger->end('setup_root_fs');
198195
}
199196

197+
/**
198+
* Set up the filesystem for the specified path
199+
*/
200+
public function setupForPath(string $path): void {
201+
if (substr_count($path, '/') < 2 || strpos($path, '/appdata_' . \OC_Util::getInstanceId()) === 0 || strpos($path, '/files_external/') === 0) {
202+
$this->setupRoot();
203+
return;
204+
} else {
205+
[, $userId] = explode('/', $path);
206+
}
207+
208+
$user = $this->userManager->get($userId);
209+
210+
if (!$user) {
211+
$this->setupRoot();
212+
return;
213+
}
214+
215+
$this->setupForUser($user);
216+
}
217+
200218
public function tearDown() {
201219
$this->setupUsers = [];
202220
$this->rootSetup = false;

tests/lib/Files/Mount/ManagerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use OCP\Diagnostics\IEventLogger;
1313
use OCP\EventDispatcher\IEventDispatcher;
1414
use OCP\Files\Config\IMountProviderCollection;
15-
use OCP\IUserSession;
15+
use OCP\IUserManager;
1616

1717
class LongId extends Temporary {
1818
public function getId() {
@@ -31,7 +31,7 @@ protected function setUp(): void {
3131
$this->manager = new \OC\Files\Mount\Manager(
3232
$this->createMock(IEventLogger::class),
3333
$this->createMock(IMountProviderCollection::class),
34-
$this->createMock(IUserSession::class),
34+
$this->createMock(IUserManager::class),
3535
$this->createMock(IEventDispatcher::class),
3636
);
3737
}

0 commit comments

Comments
 (0)