mirror of
https://github.com/nextcloud/server.git
synced 2026-04-02 07:35:13 -04:00
move logic to decide what to setup to setupmanager
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
1c468129af
commit
22875bf367
6 changed files with 46 additions and 41 deletions
|
|
@ -30,7 +30,7 @@ use OCA\Files_External\Lib\StorageConfig;
|
|||
use OCP\Diagnostics\IEventLogger;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\Files\Config\IMountProviderCollection;
|
||||
use OCP\IUserSession;
|
||||
use OCP\IUserManager;
|
||||
use Test\TestCase;
|
||||
|
||||
class PersonalMountTest extends TestCase {
|
||||
|
|
@ -54,7 +54,7 @@ class PersonalMountTest extends TestCase {
|
|||
$mountManager = new Manager(
|
||||
$this->createMock(IEventLogger::class),
|
||||
$this->createMock(IMountProviderCollection::class),
|
||||
$this->createMock(IUserSession::class),
|
||||
$this->createMock(IUserManager::class),
|
||||
$this->createMock(IEventDispatcher::class)
|
||||
);
|
||||
$mountManager->addMount($mount);
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ class ManagerTest extends TestCase {
|
|||
$this->mountManager = new \OC\Files\Mount\Manager(
|
||||
$this->createMock(IEventLogger::class),
|
||||
$this->createMock(IMountProviderCollection::class),
|
||||
$this->createMock(IUserSession::class),
|
||||
$this->createMock(IUserManager::class),
|
||||
$this->createMock(IEventDispatcher::class)
|
||||
);
|
||||
$this->clientService = $this->getMockBuilder(IClientService::class)
|
||||
|
|
|
|||
|
|
@ -31,14 +31,13 @@ namespace OC\Files\Mount;
|
|||
use OC\Cache\CappedMemoryCache;
|
||||
use OC\Files\Filesystem;
|
||||
use OC\Files\SetupManager;
|
||||
use OC\Setup;
|
||||
use OCP\Diagnostics\IEventLogger;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\Files\Config\IMountProviderCollection;
|
||||
use OCP\Files\Mount\IMountManager;
|
||||
use OCP\Files\Mount\IMountPoint;
|
||||
use OCP\Files\NotFoundException;
|
||||
use OCP\IUserSession;
|
||||
use OCP\IUserManager;
|
||||
|
||||
class Manager implements IMountManager {
|
||||
/** @var MountPoint[] */
|
||||
|
|
@ -50,12 +49,12 @@ class Manager implements IMountManager {
|
|||
public function __construct(
|
||||
IEventLogger $eventLogger,
|
||||
IMountProviderCollection $mountProviderCollection,
|
||||
IUserSession $userSession,
|
||||
IUserManager $userManager,
|
||||
IEventDispatcher $eventDispatcher
|
||||
) {
|
||||
$this->pathCache = new CappedMemoryCache();
|
||||
$this->inPathCache = new CappedMemoryCache();
|
||||
$this->setupManager = new SetupManager($eventLogger, $mountProviderCollection, $this, $userSession, $eventDispatcher);
|
||||
$this->setupManager = new SetupManager($eventLogger, $mountProviderCollection, $this, $userManager, $eventDispatcher);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -91,26 +90,14 @@ class Manager implements IMountManager {
|
|||
$this->inPathCache->clear();
|
||||
}
|
||||
|
||||
private function setupForFind(string $path) {
|
||||
if (strpos($path, '/appdata_' . \OC_Util::getInstanceId()) === 0) {
|
||||
// for appdata, we only setup the root bits, not the user bits
|
||||
$this->setupManager->setupRoot();
|
||||
} elseif (strpos($path, '/files_external/uploads/') === 0) {
|
||||
// for OC\Security\CertificateManager, we only setup the root bits, not the user bits
|
||||
$this->setupManager->setupRoot();
|
||||
} else {
|
||||
$this->setupManager->setupForCurrentUser();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the mount for $path
|
||||
*
|
||||
* @param string $path
|
||||
* @return MountPoint|null
|
||||
* @return MountPoint
|
||||
*/
|
||||
public function find(string $path): ?MountPoint {
|
||||
$this->setupForFind($path);
|
||||
public function find(string $path): MountPoint {
|
||||
$this->setupManager->setupForPath($path);
|
||||
$path = Filesystem::normalizePath($path);
|
||||
|
||||
if (isset($this->pathCache[$path])) {
|
||||
|
|
@ -143,7 +130,7 @@ class Manager implements IMountManager {
|
|||
* @return MountPoint[]
|
||||
*/
|
||||
public function findIn(string $path): array {
|
||||
$this->setupForFind($path);
|
||||
$this->setupManager->setupForPath($path);
|
||||
$path = $this->formatPath($path);
|
||||
|
||||
if (isset($this->inPathCache[$path])) {
|
||||
|
|
|
|||
|
|
@ -43,14 +43,14 @@ use OCP\Files\Mount\IMountManager;
|
|||
use OCP\Files\Mount\IMountPoint;
|
||||
use OCP\Files\Storage\IStorage;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserSession;
|
||||
use OCP\IUserManager;
|
||||
|
||||
class SetupManager {
|
||||
private bool $rootSetup = false;
|
||||
private IEventLogger $eventLogger;
|
||||
private IMountProviderCollection $mountProviderCollection;
|
||||
private IMountManager $mountManager;
|
||||
private IUserSession $userSession;
|
||||
private IUserManager $userManager;
|
||||
private array $setupUsers = [];
|
||||
private IEventDispatcher $eventDispatcher;
|
||||
|
||||
|
|
@ -58,13 +58,13 @@ class SetupManager {
|
|||
IEventLogger $eventLogger,
|
||||
IMountProviderCollection $mountProviderCollection,
|
||||
IMountManager $mountManager,
|
||||
IUserSession $userSession,
|
||||
IUserManager $userManager,
|
||||
IEventDispatcher $eventDispatcher
|
||||
) {
|
||||
$this->eventLogger = $eventLogger;
|
||||
$this->mountProviderCollection = $mountProviderCollection;
|
||||
$this->mountManager = $mountManager;
|
||||
$this->userSession = $userSession;
|
||||
$this->userManager = $userManager;
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
}
|
||||
|
||||
|
|
@ -138,16 +138,10 @@ class SetupManager {
|
|||
});
|
||||
}
|
||||
|
||||
public function setupForCurrentUser() {
|
||||
$user = $this->userSession->getUser();
|
||||
if ($user) {
|
||||
$this->setupForUser($user);
|
||||
} else {
|
||||
$this->setupRoot();
|
||||
}
|
||||
}
|
||||
|
||||
public function setupForUser(IUser $user) {
|
||||
/**
|
||||
* Setup the full filesystem for the specified user
|
||||
*/
|
||||
public function setupForUser(IUser $user): void {
|
||||
$this->setupRoot();
|
||||
|
||||
if (in_array($user->getUID(), $this->setupUsers, true)) {
|
||||
|
|
@ -172,7 +166,10 @@ class SetupManager {
|
|||
$this->eventLogger->end('setup_fs');
|
||||
}
|
||||
|
||||
public function setupRoot() {
|
||||
/**
|
||||
* Set up the root filesystem
|
||||
*/
|
||||
public function setupRoot(): void {
|
||||
//setting up the filesystem twice can only lead to trouble
|
||||
if ($this->rootSetup) {
|
||||
return;
|
||||
|
|
@ -197,6 +194,27 @@ class SetupManager {
|
|||
$this->eventLogger->end('setup_root_fs');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up the filesystem for the specified path
|
||||
*/
|
||||
public function setupForPath(string $path): void {
|
||||
if (substr_count($path, '/') < 2 || strpos($path, '/appdata_' . \OC_Util::getInstanceId()) === 0 || strpos($path, '/files_external/') === 0) {
|
||||
$this->setupRoot();
|
||||
return;
|
||||
} else {
|
||||
[, $userId] = explode('/', $path);
|
||||
}
|
||||
|
||||
$user = $this->userManager->get($userId);
|
||||
|
||||
if (!$user) {
|
||||
$this->setupRoot();
|
||||
return;
|
||||
}
|
||||
|
||||
$this->setupForUser($user);
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
$this->setupUsers = [];
|
||||
$this->rootSetup = false;
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ interface IMountManager {
|
|||
* Find the mount for $path
|
||||
*
|
||||
* @param string $path
|
||||
* @return IMountPoint|null
|
||||
* @return IMountPoint
|
||||
* @since 8.2.0
|
||||
*/
|
||||
public function find(string $path): ?IMountPoint;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use OC\Files\Storage\Temporary;
|
|||
use OCP\Diagnostics\IEventLogger;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\Files\Config\IMountProviderCollection;
|
||||
use OCP\IUserSession;
|
||||
use OCP\IUserManager;
|
||||
|
||||
class LongId extends Temporary {
|
||||
public function getId() {
|
||||
|
|
@ -31,7 +31,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
$this->manager = new \OC\Files\Mount\Manager(
|
||||
$this->createMock(IEventLogger::class),
|
||||
$this->createMock(IMountProviderCollection::class),
|
||||
$this->createMock(IUserSession::class),
|
||||
$this->createMock(IUserManager::class),
|
||||
$this->createMock(IEventDispatcher::class),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue