@@ -52,243 +52,243 @@ |
||
| 52 | 52 | use OCP\Lockdown\ILockdownManager; |
| 53 | 53 | |
| 54 | 54 | class SetupManager { |
| 55 | - private bool $rootSetup = false; |
|
| 56 | - private IEventLogger $eventLogger; |
|
| 57 | - private MountProviderCollection $mountProviderCollection; |
|
| 58 | - private IMountManager $mountManager; |
|
| 59 | - private IUserManager $userManager; |
|
| 60 | - private array $setupUsers = []; |
|
| 61 | - private IEventDispatcher $eventDispatcher; |
|
| 62 | - private IUserMountCache $userMountCache; |
|
| 63 | - private ILockdownManager $lockdownManager; |
|
| 64 | - private IUserSession $userSession; |
|
| 65 | - private bool $listeningForProviders; |
|
| 66 | - |
|
| 67 | - public function __construct( |
|
| 68 | - IEventLogger $eventLogger, |
|
| 69 | - MountProviderCollection $mountProviderCollection, |
|
| 70 | - IMountManager $mountManager, |
|
| 71 | - IUserManager $userManager, |
|
| 72 | - IEventDispatcher $eventDispatcher, |
|
| 73 | - IUserMountCache $userMountCache, |
|
| 74 | - ILockdownManager $lockdownManager, |
|
| 75 | - IUserSession $userSession |
|
| 76 | - ) { |
|
| 77 | - $this->eventLogger = $eventLogger; |
|
| 78 | - $this->mountProviderCollection = $mountProviderCollection; |
|
| 79 | - $this->mountManager = $mountManager; |
|
| 80 | - $this->userManager = $userManager; |
|
| 81 | - $this->eventDispatcher = $eventDispatcher; |
|
| 82 | - $this->userMountCache = $userMountCache; |
|
| 83 | - $this->lockdownManager = $lockdownManager; |
|
| 84 | - $this->userSession = $userSession; |
|
| 85 | - $this->listeningForProviders = false; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - private function setupBuiltinWrappers() { |
|
| 89 | - Filesystem::addStorageWrapper('mount_options', function ($mountPoint, IStorage $storage, IMountPoint $mount) { |
|
| 90 | - if ($storage->instanceOfStorage(Common::class)) { |
|
| 91 | - $storage->setMountOptions($mount->getOptions()); |
|
| 92 | - } |
|
| 93 | - return $storage; |
|
| 94 | - }); |
|
| 95 | - |
|
| 96 | - Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, IStorage $storage, IMountPoint $mount) { |
|
| 97 | - if (!$mount->getOption('enable_sharing', true)) { |
|
| 98 | - return new PermissionsMask([ |
|
| 99 | - 'storage' => $storage, |
|
| 100 | - 'mask' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE, |
|
| 101 | - ]); |
|
| 102 | - } |
|
| 103 | - return $storage; |
|
| 104 | - }); |
|
| 105 | - |
|
| 106 | - // install storage availability wrapper, before most other wrappers |
|
| 107 | - Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, IStorage $storage) { |
|
| 108 | - if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 109 | - return new Availability(['storage' => $storage]); |
|
| 110 | - } |
|
| 111 | - return $storage; |
|
| 112 | - }); |
|
| 113 | - |
|
| 114 | - Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, IStorage $storage, IMountPoint $mount) { |
|
| 115 | - if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 116 | - return new Encoding(['storage' => $storage]); |
|
| 117 | - } |
|
| 118 | - return $storage; |
|
| 119 | - }); |
|
| 120 | - |
|
| 121 | - Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) { |
|
| 122 | - // set up quota for home storages, even for other users |
|
| 123 | - // which can happen when using sharing |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * @var Storage $storage |
|
| 127 | - */ |
|
| 128 | - if ($storage->instanceOfStorage(HomeObjectStoreStorage::class) || $storage->instanceOfStorage(Home::class)) { |
|
| 129 | - if (is_object($storage->getUser())) { |
|
| 130 | - $quota = OC_Util::getUserQuota($storage->getUser()); |
|
| 131 | - if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
| 132 | - return new Quota(['storage' => $storage, 'quota' => $quota, 'root' => 'files']); |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - return $storage; |
|
| 138 | - }); |
|
| 139 | - |
|
| 140 | - Filesystem::addStorageWrapper('readonly', function ($mountPoint, IStorage $storage, IMountPoint $mount) { |
|
| 141 | - /* |
|
| 55 | + private bool $rootSetup = false; |
|
| 56 | + private IEventLogger $eventLogger; |
|
| 57 | + private MountProviderCollection $mountProviderCollection; |
|
| 58 | + private IMountManager $mountManager; |
|
| 59 | + private IUserManager $userManager; |
|
| 60 | + private array $setupUsers = []; |
|
| 61 | + private IEventDispatcher $eventDispatcher; |
|
| 62 | + private IUserMountCache $userMountCache; |
|
| 63 | + private ILockdownManager $lockdownManager; |
|
| 64 | + private IUserSession $userSession; |
|
| 65 | + private bool $listeningForProviders; |
|
| 66 | + |
|
| 67 | + public function __construct( |
|
| 68 | + IEventLogger $eventLogger, |
|
| 69 | + MountProviderCollection $mountProviderCollection, |
|
| 70 | + IMountManager $mountManager, |
|
| 71 | + IUserManager $userManager, |
|
| 72 | + IEventDispatcher $eventDispatcher, |
|
| 73 | + IUserMountCache $userMountCache, |
|
| 74 | + ILockdownManager $lockdownManager, |
|
| 75 | + IUserSession $userSession |
|
| 76 | + ) { |
|
| 77 | + $this->eventLogger = $eventLogger; |
|
| 78 | + $this->mountProviderCollection = $mountProviderCollection; |
|
| 79 | + $this->mountManager = $mountManager; |
|
| 80 | + $this->userManager = $userManager; |
|
| 81 | + $this->eventDispatcher = $eventDispatcher; |
|
| 82 | + $this->userMountCache = $userMountCache; |
|
| 83 | + $this->lockdownManager = $lockdownManager; |
|
| 84 | + $this->userSession = $userSession; |
|
| 85 | + $this->listeningForProviders = false; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + private function setupBuiltinWrappers() { |
|
| 89 | + Filesystem::addStorageWrapper('mount_options', function ($mountPoint, IStorage $storage, IMountPoint $mount) { |
|
| 90 | + if ($storage->instanceOfStorage(Common::class)) { |
|
| 91 | + $storage->setMountOptions($mount->getOptions()); |
|
| 92 | + } |
|
| 93 | + return $storage; |
|
| 94 | + }); |
|
| 95 | + |
|
| 96 | + Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, IStorage $storage, IMountPoint $mount) { |
|
| 97 | + if (!$mount->getOption('enable_sharing', true)) { |
|
| 98 | + return new PermissionsMask([ |
|
| 99 | + 'storage' => $storage, |
|
| 100 | + 'mask' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE, |
|
| 101 | + ]); |
|
| 102 | + } |
|
| 103 | + return $storage; |
|
| 104 | + }); |
|
| 105 | + |
|
| 106 | + // install storage availability wrapper, before most other wrappers |
|
| 107 | + Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, IStorage $storage) { |
|
| 108 | + if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 109 | + return new Availability(['storage' => $storage]); |
|
| 110 | + } |
|
| 111 | + return $storage; |
|
| 112 | + }); |
|
| 113 | + |
|
| 114 | + Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, IStorage $storage, IMountPoint $mount) { |
|
| 115 | + if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 116 | + return new Encoding(['storage' => $storage]); |
|
| 117 | + } |
|
| 118 | + return $storage; |
|
| 119 | + }); |
|
| 120 | + |
|
| 121 | + Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) { |
|
| 122 | + // set up quota for home storages, even for other users |
|
| 123 | + // which can happen when using sharing |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * @var Storage $storage |
|
| 127 | + */ |
|
| 128 | + if ($storage->instanceOfStorage(HomeObjectStoreStorage::class) || $storage->instanceOfStorage(Home::class)) { |
|
| 129 | + if (is_object($storage->getUser())) { |
|
| 130 | + $quota = OC_Util::getUserQuota($storage->getUser()); |
|
| 131 | + if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
| 132 | + return new Quota(['storage' => $storage, 'quota' => $quota, 'root' => 'files']); |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + return $storage; |
|
| 138 | + }); |
|
| 139 | + |
|
| 140 | + Filesystem::addStorageWrapper('readonly', function ($mountPoint, IStorage $storage, IMountPoint $mount) { |
|
| 141 | + /* |
|
| 142 | 142 | * Do not allow any operations that modify the storage |
| 143 | 143 | */ |
| 144 | - if ($mount->getOption('readonly', false)) { |
|
| 145 | - return new PermissionsMask([ |
|
| 146 | - 'storage' => $storage, |
|
| 147 | - 'mask' => Constants::PERMISSION_ALL & ~( |
|
| 148 | - Constants::PERMISSION_UPDATE | |
|
| 149 | - Constants::PERMISSION_CREATE | |
|
| 150 | - Constants::PERMISSION_DELETE |
|
| 151 | - ), |
|
| 152 | - ]); |
|
| 153 | - } |
|
| 154 | - return $storage; |
|
| 155 | - }); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Setup the full filesystem for the specified user |
|
| 160 | - */ |
|
| 161 | - public function setupForUser(IUser $user): void { |
|
| 162 | - $this->setupRoot(); |
|
| 163 | - |
|
| 164 | - if (in_array($user->getUID(), $this->setupUsers, true)) { |
|
| 165 | - return; |
|
| 166 | - } |
|
| 167 | - $this->setupUsers[] = $user->getUID(); |
|
| 168 | - |
|
| 169 | - $this->eventLogger->start('setup_fs', 'Setup filesystem'); |
|
| 170 | - |
|
| 171 | - $prevLogging = Filesystem::logWarningWhenAddingStorageWrapper(false); |
|
| 172 | - |
|
| 173 | - OC_Hook::emit('OC_Filesystem', 'preSetup', ['user' => $user->getUID()]); |
|
| 174 | - |
|
| 175 | - Filesystem::logWarningWhenAddingStorageWrapper($prevLogging); |
|
| 176 | - |
|
| 177 | - $userDir = '/' . $user->getUID() . '/files'; |
|
| 178 | - |
|
| 179 | - Filesystem::init($user, $userDir); |
|
| 180 | - |
|
| 181 | - if ($this->lockdownManager->canAccessFilesystem()) { |
|
| 182 | - // home mounts are handled separate since we need to ensure this is mounted before we call the other mount providers |
|
| 183 | - $homeMount = $this->mountProviderCollection->getHomeMountForUser($user); |
|
| 184 | - $this->mountManager->addMount($homeMount); |
|
| 185 | - |
|
| 186 | - if ($homeMount->getStorageRootId() === -1) { |
|
| 187 | - $homeMount->getStorage()->mkdir(''); |
|
| 188 | - $homeMount->getStorage()->getScanner()->scan(''); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - // Chance to mount for other storages |
|
| 192 | - $mounts = $this->mountProviderCollection->addMountForUser($user, $this->mountManager); |
|
| 193 | - $mounts[] = $homeMount; |
|
| 194 | - $this->userMountCache->registerMounts($user, $mounts); |
|
| 195 | - |
|
| 196 | - $this->listenForNewMountProviders(); |
|
| 197 | - } else { |
|
| 198 | - $this->mountManager->addMount(new MountPoint( |
|
| 199 | - new NullStorage([]), |
|
| 200 | - '/' . $user->getUID() |
|
| 201 | - )); |
|
| 202 | - $this->mountManager->addMount(new MountPoint( |
|
| 203 | - new NullStorage([]), |
|
| 204 | - '/' . $user->getUID() . '/files' |
|
| 205 | - )); |
|
| 206 | - } |
|
| 207 | - \OC_Hook::emit('OC_Filesystem', 'post_initMountPoints', ['user' => $user->getUID()]); |
|
| 208 | - |
|
| 209 | - OC_Hook::emit('OC_Filesystem', 'setup', ['user' => $user->getUID(), 'user_dir' => $userDir]); |
|
| 210 | - |
|
| 211 | - $this->eventLogger->end('setup_fs'); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Set up the root filesystem |
|
| 216 | - */ |
|
| 217 | - public function setupRoot(): void { |
|
| 218 | - //setting up the filesystem twice can only lead to trouble |
|
| 219 | - if ($this->rootSetup) { |
|
| 220 | - return; |
|
| 221 | - } |
|
| 222 | - $this->rootSetup = true; |
|
| 223 | - |
|
| 224 | - $this->eventLogger->start('setup_root_fs', 'Setup root filesystem'); |
|
| 225 | - |
|
| 226 | - // load all filesystem apps before, so no setup-hook gets lost |
|
| 227 | - OC_App::loadApps(['filesystem']); |
|
| 228 | - $prevLogging = Filesystem::logWarningWhenAddingStorageWrapper(false); |
|
| 229 | - |
|
| 230 | - $this->setupBuiltinWrappers(); |
|
| 231 | - |
|
| 232 | - Filesystem::logWarningWhenAddingStorageWrapper($prevLogging); |
|
| 233 | - |
|
| 234 | - $rootMounts = $this->mountProviderCollection->getRootMounts(); |
|
| 235 | - foreach ($rootMounts as $rootMountProvider) { |
|
| 236 | - $this->mountManager->addMount($rootMountProvider); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - $this->eventLogger->end('setup_root_fs'); |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * Set up the filesystem for the specified path |
|
| 244 | - */ |
|
| 245 | - public function setupForPath(string $path): void { |
|
| 246 | - if (substr_count($path, '/') < 2) { |
|
| 247 | - if ($user = $this->userSession->getUser()) { |
|
| 248 | - $this->setupForUser($user); |
|
| 249 | - } else { |
|
| 250 | - $this->setupRoot(); |
|
| 251 | - } |
|
| 252 | - return; |
|
| 253 | - } elseif (strpos($path, '/appdata_' . \OC_Util::getInstanceId()) === 0 || strpos($path, '/files_external/') === 0) { |
|
| 254 | - $this->setupRoot(); |
|
| 255 | - return; |
|
| 256 | - } else { |
|
| 257 | - [, $userId] = explode('/', $path); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - $user = $this->userManager->get($userId); |
|
| 261 | - |
|
| 262 | - if (!$user) { |
|
| 263 | - $this->setupRoot(); |
|
| 264 | - return; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - $this->setupForUser($user); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - public function tearDown() { |
|
| 271 | - $this->setupUsers = []; |
|
| 272 | - $this->rootSetup = false; |
|
| 273 | - $this->mountManager->clear(); |
|
| 274 | - $this->eventDispatcher->dispatchTyped(new FilesystemTornDownEvent()); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * Get mounts from mount providers that are registered after setup |
|
| 279 | - */ |
|
| 280 | - private function listenForNewMountProviders() { |
|
| 281 | - if (!$this->listeningForProviders) { |
|
| 282 | - $this->listeningForProviders = true; |
|
| 283 | - $this->mountProviderCollection->listen('\OC\Files\Config', 'registerMountProvider', function (IMountProvider $provider) { |
|
| 284 | - foreach ($this->setupUsers as $userId) { |
|
| 285 | - $user = $this->userManager->get($userId); |
|
| 286 | - if ($user) { |
|
| 287 | - $mounts = $provider->getMountsForUser($user, Filesystem::getLoader()); |
|
| 288 | - array_walk($mounts, [$this->mountManager, 'addMount']); |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - }); |
|
| 292 | - } |
|
| 293 | - } |
|
| 144 | + if ($mount->getOption('readonly', false)) { |
|
| 145 | + return new PermissionsMask([ |
|
| 146 | + 'storage' => $storage, |
|
| 147 | + 'mask' => Constants::PERMISSION_ALL & ~( |
|
| 148 | + Constants::PERMISSION_UPDATE | |
|
| 149 | + Constants::PERMISSION_CREATE | |
|
| 150 | + Constants::PERMISSION_DELETE |
|
| 151 | + ), |
|
| 152 | + ]); |
|
| 153 | + } |
|
| 154 | + return $storage; |
|
| 155 | + }); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Setup the full filesystem for the specified user |
|
| 160 | + */ |
|
| 161 | + public function setupForUser(IUser $user): void { |
|
| 162 | + $this->setupRoot(); |
|
| 163 | + |
|
| 164 | + if (in_array($user->getUID(), $this->setupUsers, true)) { |
|
| 165 | + return; |
|
| 166 | + } |
|
| 167 | + $this->setupUsers[] = $user->getUID(); |
|
| 168 | + |
|
| 169 | + $this->eventLogger->start('setup_fs', 'Setup filesystem'); |
|
| 170 | + |
|
| 171 | + $prevLogging = Filesystem::logWarningWhenAddingStorageWrapper(false); |
|
| 172 | + |
|
| 173 | + OC_Hook::emit('OC_Filesystem', 'preSetup', ['user' => $user->getUID()]); |
|
| 174 | + |
|
| 175 | + Filesystem::logWarningWhenAddingStorageWrapper($prevLogging); |
|
| 176 | + |
|
| 177 | + $userDir = '/' . $user->getUID() . '/files'; |
|
| 178 | + |
|
| 179 | + Filesystem::init($user, $userDir); |
|
| 180 | + |
|
| 181 | + if ($this->lockdownManager->canAccessFilesystem()) { |
|
| 182 | + // home mounts are handled separate since we need to ensure this is mounted before we call the other mount providers |
|
| 183 | + $homeMount = $this->mountProviderCollection->getHomeMountForUser($user); |
|
| 184 | + $this->mountManager->addMount($homeMount); |
|
| 185 | + |
|
| 186 | + if ($homeMount->getStorageRootId() === -1) { |
|
| 187 | + $homeMount->getStorage()->mkdir(''); |
|
| 188 | + $homeMount->getStorage()->getScanner()->scan(''); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + // Chance to mount for other storages |
|
| 192 | + $mounts = $this->mountProviderCollection->addMountForUser($user, $this->mountManager); |
|
| 193 | + $mounts[] = $homeMount; |
|
| 194 | + $this->userMountCache->registerMounts($user, $mounts); |
|
| 195 | + |
|
| 196 | + $this->listenForNewMountProviders(); |
|
| 197 | + } else { |
|
| 198 | + $this->mountManager->addMount(new MountPoint( |
|
| 199 | + new NullStorage([]), |
|
| 200 | + '/' . $user->getUID() |
|
| 201 | + )); |
|
| 202 | + $this->mountManager->addMount(new MountPoint( |
|
| 203 | + new NullStorage([]), |
|
| 204 | + '/' . $user->getUID() . '/files' |
|
| 205 | + )); |
|
| 206 | + } |
|
| 207 | + \OC_Hook::emit('OC_Filesystem', 'post_initMountPoints', ['user' => $user->getUID()]); |
|
| 208 | + |
|
| 209 | + OC_Hook::emit('OC_Filesystem', 'setup', ['user' => $user->getUID(), 'user_dir' => $userDir]); |
|
| 210 | + |
|
| 211 | + $this->eventLogger->end('setup_fs'); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Set up the root filesystem |
|
| 216 | + */ |
|
| 217 | + public function setupRoot(): void { |
|
| 218 | + //setting up the filesystem twice can only lead to trouble |
|
| 219 | + if ($this->rootSetup) { |
|
| 220 | + return; |
|
| 221 | + } |
|
| 222 | + $this->rootSetup = true; |
|
| 223 | + |
|
| 224 | + $this->eventLogger->start('setup_root_fs', 'Setup root filesystem'); |
|
| 225 | + |
|
| 226 | + // load all filesystem apps before, so no setup-hook gets lost |
|
| 227 | + OC_App::loadApps(['filesystem']); |
|
| 228 | + $prevLogging = Filesystem::logWarningWhenAddingStorageWrapper(false); |
|
| 229 | + |
|
| 230 | + $this->setupBuiltinWrappers(); |
|
| 231 | + |
|
| 232 | + Filesystem::logWarningWhenAddingStorageWrapper($prevLogging); |
|
| 233 | + |
|
| 234 | + $rootMounts = $this->mountProviderCollection->getRootMounts(); |
|
| 235 | + foreach ($rootMounts as $rootMountProvider) { |
|
| 236 | + $this->mountManager->addMount($rootMountProvider); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + $this->eventLogger->end('setup_root_fs'); |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * Set up the filesystem for the specified path |
|
| 244 | + */ |
|
| 245 | + public function setupForPath(string $path): void { |
|
| 246 | + if (substr_count($path, '/') < 2) { |
|
| 247 | + if ($user = $this->userSession->getUser()) { |
|
| 248 | + $this->setupForUser($user); |
|
| 249 | + } else { |
|
| 250 | + $this->setupRoot(); |
|
| 251 | + } |
|
| 252 | + return; |
|
| 253 | + } elseif (strpos($path, '/appdata_' . \OC_Util::getInstanceId()) === 0 || strpos($path, '/files_external/') === 0) { |
|
| 254 | + $this->setupRoot(); |
|
| 255 | + return; |
|
| 256 | + } else { |
|
| 257 | + [, $userId] = explode('/', $path); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + $user = $this->userManager->get($userId); |
|
| 261 | + |
|
| 262 | + if (!$user) { |
|
| 263 | + $this->setupRoot(); |
|
| 264 | + return; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + $this->setupForUser($user); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + public function tearDown() { |
|
| 271 | + $this->setupUsers = []; |
|
| 272 | + $this->rootSetup = false; |
|
| 273 | + $this->mountManager->clear(); |
|
| 274 | + $this->eventDispatcher->dispatchTyped(new FilesystemTornDownEvent()); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * Get mounts from mount providers that are registered after setup |
|
| 279 | + */ |
|
| 280 | + private function listenForNewMountProviders() { |
|
| 281 | + if (!$this->listeningForProviders) { |
|
| 282 | + $this->listeningForProviders = true; |
|
| 283 | + $this->mountProviderCollection->listen('\OC\Files\Config', 'registerMountProvider', function (IMountProvider $provider) { |
|
| 284 | + foreach ($this->setupUsers as $userId) { |
|
| 285 | + $user = $this->userManager->get($userId); |
|
| 286 | + if ($user) { |
|
| 287 | + $mounts = $provider->getMountsForUser($user, Filesystem::getLoader()); |
|
| 288 | + array_walk($mounts, [$this->mountManager, 'addMount']); |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + }); |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | 294 | } |
@@ -86,14 +86,14 @@ discard block |
||
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | private function setupBuiltinWrappers() { |
| 89 | - Filesystem::addStorageWrapper('mount_options', function ($mountPoint, IStorage $storage, IMountPoint $mount) { |
|
| 89 | + Filesystem::addStorageWrapper('mount_options', function($mountPoint, IStorage $storage, IMountPoint $mount) { |
|
| 90 | 90 | if ($storage->instanceOfStorage(Common::class)) { |
| 91 | 91 | $storage->setMountOptions($mount->getOptions()); |
| 92 | 92 | } |
| 93 | 93 | return $storage; |
| 94 | 94 | }); |
| 95 | 95 | |
| 96 | - Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, IStorage $storage, IMountPoint $mount) { |
|
| 96 | + Filesystem::addStorageWrapper('enable_sharing', function($mountPoint, IStorage $storage, IMountPoint $mount) { |
|
| 97 | 97 | if (!$mount->getOption('enable_sharing', true)) { |
| 98 | 98 | return new PermissionsMask([ |
| 99 | 99 | 'storage' => $storage, |
@@ -104,21 +104,21 @@ discard block |
||
| 104 | 104 | }); |
| 105 | 105 | |
| 106 | 106 | // install storage availability wrapper, before most other wrappers |
| 107 | - Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, IStorage $storage) { |
|
| 107 | + Filesystem::addStorageWrapper('oc_availability', function($mountPoint, IStorage $storage) { |
|
| 108 | 108 | if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
| 109 | 109 | return new Availability(['storage' => $storage]); |
| 110 | 110 | } |
| 111 | 111 | return $storage; |
| 112 | 112 | }); |
| 113 | 113 | |
| 114 | - Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, IStorage $storage, IMountPoint $mount) { |
|
| 114 | + Filesystem::addStorageWrapper('oc_encoding', function($mountPoint, IStorage $storage, IMountPoint $mount) { |
|
| 115 | 115 | if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
| 116 | 116 | return new Encoding(['storage' => $storage]); |
| 117 | 117 | } |
| 118 | 118 | return $storage; |
| 119 | 119 | }); |
| 120 | 120 | |
| 121 | - Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) { |
|
| 121 | + Filesystem::addStorageWrapper('oc_quota', function($mountPoint, $storage) { |
|
| 122 | 122 | // set up quota for home storages, even for other users |
| 123 | 123 | // which can happen when using sharing |
| 124 | 124 | |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | return $storage; |
| 138 | 138 | }); |
| 139 | 139 | |
| 140 | - Filesystem::addStorageWrapper('readonly', function ($mountPoint, IStorage $storage, IMountPoint $mount) { |
|
| 140 | + Filesystem::addStorageWrapper('readonly', function($mountPoint, IStorage $storage, IMountPoint $mount) { |
|
| 141 | 141 | /* |
| 142 | 142 | * Do not allow any operations that modify the storage |
| 143 | 143 | */ |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | |
| 175 | 175 | Filesystem::logWarningWhenAddingStorageWrapper($prevLogging); |
| 176 | 176 | |
| 177 | - $userDir = '/' . $user->getUID() . '/files'; |
|
| 177 | + $userDir = '/'.$user->getUID().'/files'; |
|
| 178 | 178 | |
| 179 | 179 | Filesystem::init($user, $userDir); |
| 180 | 180 | |
@@ -197,11 +197,11 @@ discard block |
||
| 197 | 197 | } else { |
| 198 | 198 | $this->mountManager->addMount(new MountPoint( |
| 199 | 199 | new NullStorage([]), |
| 200 | - '/' . $user->getUID() |
|
| 200 | + '/'.$user->getUID() |
|
| 201 | 201 | )); |
| 202 | 202 | $this->mountManager->addMount(new MountPoint( |
| 203 | 203 | new NullStorage([]), |
| 204 | - '/' . $user->getUID() . '/files' |
|
| 204 | + '/'.$user->getUID().'/files' |
|
| 205 | 205 | )); |
| 206 | 206 | } |
| 207 | 207 | \OC_Hook::emit('OC_Filesystem', 'post_initMountPoints', ['user' => $user->getUID()]); |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | $this->setupRoot(); |
| 251 | 251 | } |
| 252 | 252 | return; |
| 253 | - } elseif (strpos($path, '/appdata_' . \OC_Util::getInstanceId()) === 0 || strpos($path, '/files_external/') === 0) { |
|
| 253 | + } elseif (strpos($path, '/appdata_'.\OC_Util::getInstanceId()) === 0 || strpos($path, '/files_external/') === 0) { |
|
| 254 | 254 | $this->setupRoot(); |
| 255 | 255 | return; |
| 256 | 256 | } else { |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | private function listenForNewMountProviders() { |
| 281 | 281 | if (!$this->listeningForProviders) { |
| 282 | 282 | $this->listeningForProviders = true; |
| 283 | - $this->mountProviderCollection->listen('\OC\Files\Config', 'registerMountProvider', function (IMountProvider $provider) { |
|
| 283 | + $this->mountProviderCollection->listen('\OC\Files\Config', 'registerMountProvider', function(IMountProvider $provider) { |
|
| 284 | 284 | foreach ($this->setupUsers as $userId) { |
| 285 | 285 | $user = $this->userManager->get($userId); |
| 286 | 286 | if ($user) { |
@@ -33,47 +33,47 @@ |
||
| 33 | 33 | use OCP\Lockdown\ILockdownManager; |
| 34 | 34 | |
| 35 | 35 | class SetupManagerFactory { |
| 36 | - private IEventLogger $eventLogger; |
|
| 37 | - private IMountProviderCollection $mountProviderCollection; |
|
| 38 | - private IUserManager $userManager; |
|
| 39 | - private IEventDispatcher $eventDispatcher; |
|
| 40 | - private IUserMountCache $userMountCache; |
|
| 41 | - private ILockdownManager $lockdownManager; |
|
| 42 | - private IUserSession $userSession; |
|
| 43 | - private ?SetupManager $setupManager; |
|
| 36 | + private IEventLogger $eventLogger; |
|
| 37 | + private IMountProviderCollection $mountProviderCollection; |
|
| 38 | + private IUserManager $userManager; |
|
| 39 | + private IEventDispatcher $eventDispatcher; |
|
| 40 | + private IUserMountCache $userMountCache; |
|
| 41 | + private ILockdownManager $lockdownManager; |
|
| 42 | + private IUserSession $userSession; |
|
| 43 | + private ?SetupManager $setupManager; |
|
| 44 | 44 | |
| 45 | - public function __construct( |
|
| 46 | - IEventLogger $eventLogger, |
|
| 47 | - IMountProviderCollection $mountProviderCollection, |
|
| 48 | - IUserManager $userManager, |
|
| 49 | - IEventDispatcher $eventDispatcher, |
|
| 50 | - IUserMountCache $userMountCache, |
|
| 51 | - ILockdownManager $lockdownManager, |
|
| 52 | - IUserSession $userSession |
|
| 53 | - ) { |
|
| 54 | - $this->eventLogger = $eventLogger; |
|
| 55 | - $this->mountProviderCollection = $mountProviderCollection; |
|
| 56 | - $this->userManager = $userManager; |
|
| 57 | - $this->eventDispatcher = $eventDispatcher; |
|
| 58 | - $this->userMountCache = $userMountCache; |
|
| 59 | - $this->lockdownManager = $lockdownManager; |
|
| 60 | - $this->userSession = $userSession; |
|
| 61 | - $this->setupManager = null; |
|
| 62 | - } |
|
| 45 | + public function __construct( |
|
| 46 | + IEventLogger $eventLogger, |
|
| 47 | + IMountProviderCollection $mountProviderCollection, |
|
| 48 | + IUserManager $userManager, |
|
| 49 | + IEventDispatcher $eventDispatcher, |
|
| 50 | + IUserMountCache $userMountCache, |
|
| 51 | + ILockdownManager $lockdownManager, |
|
| 52 | + IUserSession $userSession |
|
| 53 | + ) { |
|
| 54 | + $this->eventLogger = $eventLogger; |
|
| 55 | + $this->mountProviderCollection = $mountProviderCollection; |
|
| 56 | + $this->userManager = $userManager; |
|
| 57 | + $this->eventDispatcher = $eventDispatcher; |
|
| 58 | + $this->userMountCache = $userMountCache; |
|
| 59 | + $this->lockdownManager = $lockdownManager; |
|
| 60 | + $this->userSession = $userSession; |
|
| 61 | + $this->setupManager = null; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - public function create(IMountManager $mountManager): SetupManager { |
|
| 65 | - if (!$this->setupManager) { |
|
| 66 | - $this->setupManager = new SetupManager( |
|
| 67 | - $this->eventLogger, |
|
| 68 | - $this->mountProviderCollection, |
|
| 69 | - $mountManager, |
|
| 70 | - $this->userManager, |
|
| 71 | - $this->eventDispatcher, |
|
| 72 | - $this->userMountCache, |
|
| 73 | - $this->lockdownManager, |
|
| 74 | - $this->userSession, |
|
| 75 | - ); |
|
| 76 | - } |
|
| 77 | - return $this->setupManager; |
|
| 78 | - } |
|
| 64 | + public function create(IMountManager $mountManager): SetupManager { |
|
| 65 | + if (!$this->setupManager) { |
|
| 66 | + $this->setupManager = new SetupManager( |
|
| 67 | + $this->eventLogger, |
|
| 68 | + $this->mountProviderCollection, |
|
| 69 | + $mountManager, |
|
| 70 | + $this->userManager, |
|
| 71 | + $this->eventDispatcher, |
|
| 72 | + $this->userMountCache, |
|
| 73 | + $this->lockdownManager, |
|
| 74 | + $this->userSession, |
|
| 75 | + ); |
|
| 76 | + } |
|
| 77 | + return $this->setupManager; |
|
| 78 | + } |
|
| 79 | 79 | } |