Skip to content

Commit 28662e3

Browse files
committed
only setup part of the filesystem for appdata requests
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent c84c765 commit 28662e3

File tree

4 files changed

+91
-37
lines changed

4 files changed

+91
-37
lines changed

lib/private/Files/Filesystem.php

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,7 @@ public static function getLoader() {
240240
* @return \OC\Files\Mount\Manager
241241
*/
242242
public static function getMountManager($user = '') {
243-
if (!self::$mounts) {
244-
\OC_Util::setupFS($user);
245-
}
243+
self::initMountManager();
246244
return self::$mounts;
247245
}
248246

@@ -292,10 +290,7 @@ public static function getMountPoints($path) {
292290
* @return \OC\Files\Storage\Storage|null
293291
*/
294292
public static function getStorage($mountPoint) {
295-
if (!self::$mounts) {
296-
\OC_Util::setupFS();
297-
}
298-
$mount = self::$mounts->find($mountPoint);
293+
$mount = self::getMountManager()->find($mountPoint);
299294
return $mount->getStorage();
300295
}
301296

@@ -304,21 +299,15 @@ public static function getStorage($mountPoint) {
304299
* @return Mount\MountPoint[]
305300
*/
306301
public static function getMountByStorageId($id) {
307-
if (!self::$mounts) {
308-
\OC_Util::setupFS();
309-
}
310-
return self::$mounts->findByStorageId($id);
302+
return self::getMountManager()->findByStorageId($id);
311303
}
312304

313305
/**
314306
* @param int $id
315307
* @return Mount\MountPoint[]
316308
*/
317309
public static function getMountByNumericId($id) {
318-
if (!self::$mounts) {
319-
\OC_Util::setupFS();
320-
}
321-
return self::$mounts->findByNumericId($id);
310+
return self::getMountManager()->findByNumericId($id);
322311
}
323312

324313
/**

lib/private/Files/Mount/Manager.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,23 @@ public function moveMount(string $mountPoint, string $target) {
8181
$this->inPathCache->clear();
8282
}
8383

84+
private function setupForFind(string $path) {
85+
if (strpos($path, '/appdata_' . \OC_Util::getInstanceId()) === 0) {
86+
// for appdata, we only setup the root bits, not the user bits
87+
\OC_Util::setupRootFS();
88+
} else {
89+
\OC_Util::setupFS();
90+
}
91+
}
92+
8493
/**
8594
* Find the mount for $path
8695
*
8796
* @param string $path
8897
* @return MountPoint|null
8998
*/
9099
public function find(string $path) {
91-
\OC_Util::setupFS();
100+
$this->setupForFind($path);
92101
$path = Filesystem::normalizePath($path);
93102

94103
if (isset($this->pathCache[$path])) {
@@ -121,7 +130,7 @@ public function find(string $path) {
121130
* @return MountPoint[]
122131
*/
123132
public function findIn(string $path): array {
124-
\OC_Util::setupFS();
133+
$this->setupForFind($path);
125134
$path = $this->formatPath($path);
126135

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

lib/private/legacy/OC_Util.php

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class OC_Util {
8181
public static $styles = [];
8282
public static $headers = [];
8383
private static $rootMounted = false;
84+
private static $rootFsSetup = false;
8485
private static $fsSetup = false;
8586

8687
/** @var array Local cache of version.php */
@@ -186,30 +187,18 @@ private static function initObjectStoreMultibucketRootFS($config) {
186187
* @suppress PhanDeprecatedFunction
187188
* @suppress PhanAccessMethodInternal
188189
*/
189-
public static function setupFS($user = '') {
190+
public static function setupRootFS(string $user = '') {
190191
//setting up the filesystem twice can only lead to trouble
191-
if (self::$fsSetup) {
192+
if (self::$rootFsSetup) {
192193
return false;
193194
}
194195

195-
\OC::$server->getEventLogger()->start('setup_fs', 'Setup filesystem');
196-
197-
// If we are not forced to load a specific user we load the one that is logged in
198-
if ($user === null) {
199-
$user = '';
200-
} elseif ($user == "" && \OC::$server->getUserSession()->isLoggedIn()) {
201-
$user = OC_User::getUser();
202-
}
196+
\OC::$server->getEventLogger()->start('setup_root_fs', 'Setup root filesystem');
203197

204198
// load all filesystem apps before, so no setup-hook gets lost
205199
OC_App::loadApps(['filesystem']);
206200

207-
// the filesystem will finish when $user is not empty,
208-
// mark fs setup here to avoid doing the setup from loading
209-
// OC_Filesystem
210-
if ($user != '') {
211-
self::$fsSetup = true;
212-
}
201+
self::$rootFsSetup = true;
213202

214203
\OC\Files\Filesystem::initMountManager();
215204

@@ -277,10 +266,10 @@ public static function setupFS($user = '') {
277266
return new \OC\Files\Storage\Wrapper\PermissionsMask([
278267
'storage' => $storage,
279268
'mask' => \OCP\Constants::PERMISSION_ALL & ~(
280-
\OCP\Constants::PERMISSION_UPDATE |
281-
\OCP\Constants::PERMISSION_CREATE |
282-
\OCP\Constants::PERMISSION_DELETE
283-
),
269+
\OCP\Constants::PERMISSION_UPDATE |
270+
\OCP\Constants::PERMISSION_CREATE |
271+
\OCP\Constants::PERMISSION_DELETE
272+
),
284273
]);
285274
}
286275
return $storage;
@@ -313,11 +302,40 @@ public static function setupFS($user = '') {
313302
$mountManager->addMount($rootMountProvider);
314303
}
315304

305+
\OC::$server->getEventLogger()->end('setup_root_fs');
306+
}
307+
308+
/**
309+
* Can be set up
310+
*
311+
* @param string $user
312+
* @return boolean
313+
* @description configure the initial filesystem based on the configuration
314+
* @suppress PhanDeprecatedFunction
315+
* @suppress PhanAccessMethodInternal
316+
*/
317+
public static function setupFS($user = '') {
318+
// If we are not forced to load a specific user we load the one that is logged in
319+
if ($user === null) {
320+
$user = '';
321+
} elseif ($user == "" && \OC::$server->getUserSession()->isLoggedIn()) {
322+
$user = OC_User::getUser();
323+
}
324+
325+
if (self::$fsSetup) {
326+
return false;
327+
}
328+
self::setupRootFS($user);
329+
330+
\OC::$server->getEventLogger()->start('setup_fs', 'Setup filesystem');
331+
316332
if ($user != '' && !\OC::$server->getUserManager()->userExists($user)) {
317333
\OC::$server->getEventLogger()->end('setup_fs');
318334
return false;
319335
}
320336

337+
self::$fsSetup = true;
338+
321339
//if we aren't logged in, there is no use to set up the filesystem
322340
if ($user != "") {
323341
$userDir = '/' . $user . '/files';
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php declare(strict_types=1);
2+
/**
3+
* @copyright Copyright (c) 2022 Robin Appelman <robin@icewind.nl>
4+
*
5+
* @license GNU AGPL version 3 or any later version
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Affero General Public License as
9+
* published by the Free Software Foundation, either version 3 of the
10+
* License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Affero General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*
20+
*/
21+
22+
namespace OCP\Files\Config;
23+
24+
use OCP\IUser;
25+
26+
/**
27+
* Denotes a roots that all mounts from this provider belong to
28+
*
29+
* @since 24.0.0
30+
*/
31+
interface IScopedMountProvider extends IMountProvider {
32+
/**
33+
* Get the common roots for all mounts from this provider
34+
*
35+
* @return string[]
36+
*/
37+
public function getRoots(IUser $user): array;
38+
}

0 commit comments

Comments
 (0)