SetupManager.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2022 Robin Appelman <robin@icewind.nl>
  5. *
  6. * @license GNU AGPL version 3 or any later version
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. namespace OC\Files;
  23. use OC\Files\Config\MountProviderCollection;
  24. use OC\Files\Mount\HomeMountPoint;
  25. use OC\Files\Mount\MountPoint;
  26. use OC\Files\Storage\Common;
  27. use OC\Files\Storage\Home;
  28. use OC\Files\Storage\Storage;
  29. use OC\Files\Storage\Wrapper\Availability;
  30. use OC\Files\Storage\Wrapper\Encoding;
  31. use OC\Files\Storage\Wrapper\PermissionsMask;
  32. use OC\Files\Storage\Wrapper\Quota;
  33. use OC\Lockdown\Filesystem\NullStorage;
  34. use OC\Share\Share;
  35. use OC\Share20\ShareDisableChecker;
  36. use OC_App;
  37. use OC_Hook;
  38. use OC_Util;
  39. use OCA\Files_External\Config\ConfigAdapter;
  40. use OCA\Files_Sharing\External\Mount;
  41. use OCA\Files_Sharing\ISharedMountPoint;
  42. use OCA\Files_Sharing\SharedMount;
  43. use OCP\Constants;
  44. use OCP\Diagnostics\IEventLogger;
  45. use OCP\EventDispatcher\IEventDispatcher;
  46. use OCP\Files\Config\ICachedMountInfo;
  47. use OCP\Files\Config\IHomeMountProvider;
  48. use OCP\Files\Config\IMountProvider;
  49. use OCP\Files\Config\IUserMountCache;
  50. use OCP\Files\Events\InvalidateMountCacheEvent;
  51. use OCP\Files\Events\Node\FilesystemTornDownEvent;
  52. use OCP\Files\Mount\IMountManager;
  53. use OCP\Files\Mount\IMountPoint;
  54. use OCP\Files\NotFoundException;
  55. use OCP\Files\Storage\IStorage;
  56. use OCP\Group\Events\UserAddedEvent;
  57. use OCP\Group\Events\UserRemovedEvent;
  58. use OCP\ICache;
  59. use OCP\ICacheFactory;
  60. use OCP\IConfig;
  61. use OCP\IUser;
  62. use OCP\IUserManager;
  63. use OCP\IUserSession;
  64. use OCP\Lockdown\ILockdownManager;
  65. use OCP\Share\Events\ShareCreatedEvent;
  66. use Psr\Log\LoggerInterface;
  67. class SetupManager {
  68. private bool $rootSetup = false;
  69. // List of users for which at least one mount is setup
  70. private array $setupUsers = [];
  71. // List of users for which all mounts are setup
  72. private array $setupUsersComplete = [];
  73. /** @var array<string, string[]> */
  74. private array $setupUserMountProviders = [];
  75. private ICache $cache;
  76. private bool $listeningForProviders;
  77. private array $fullSetupRequired = [];
  78. private bool $setupBuiltinWrappersDone = false;
  79. public function __construct(
  80. private IEventLogger $eventLogger,
  81. private MountProviderCollection $mountProviderCollection,
  82. private IMountManager $mountManager,
  83. private IUserManager $userManager,
  84. private IEventDispatcher $eventDispatcher,
  85. private IUserMountCache $userMountCache,
  86. private ILockdownManager $lockdownManager,
  87. private IUserSession $userSession,
  88. ICacheFactory $cacheFactory,
  89. private LoggerInterface $logger,
  90. private IConfig $config,
  91. private ShareDisableChecker $shareDisableChecker,
  92. ) {
  93. $this->cache = $cacheFactory->createDistributed('setupmanager::');
  94. $this->listeningForProviders = false;
  95. $this->setupListeners();
  96. }
  97. private function isSetupStarted(IUser $user): bool {
  98. return in_array($user->getUID(), $this->setupUsers, true);
  99. }
  100. public function isSetupComplete(IUser $user): bool {
  101. return in_array($user->getUID(), $this->setupUsersComplete, true);
  102. }
  103. private function setupBuiltinWrappers() {
  104. if ($this->setupBuiltinWrappersDone) {
  105. return;
  106. }
  107. $this->setupBuiltinWrappersDone = true;
  108. // load all filesystem apps before, so no setup-hook gets lost
  109. OC_App::loadApps(['filesystem']);
  110. $prevLogging = Filesystem::logWarningWhenAddingStorageWrapper(false);
  111. Filesystem::addStorageWrapper('mount_options', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
  112. if ($mount->getOptions() && $storage->instanceOfStorage(Common::class)) {
  113. $storage->setMountOptions($mount->getOptions());
  114. }
  115. return $storage;
  116. });
  117. $reSharingEnabled = Share::isResharingAllowed();
  118. $user = $this->userSession->getUser();
  119. $sharingEnabledForUser = $user ? !$this->shareDisableChecker->sharingDisabledForUser($user->getUID()) : true;
  120. Filesystem::addStorageWrapper(
  121. 'sharing_mask',
  122. function ($mountPoint, IStorage $storage, IMountPoint $mount) use ($reSharingEnabled, $sharingEnabledForUser) {
  123. $sharingEnabledForMount = $mount->getOption('enable_sharing', true);
  124. $isShared = $mount instanceof ISharedMountPoint;
  125. if (!$sharingEnabledForMount || !$sharingEnabledForUser || (!$reSharingEnabled && $isShared)) {
  126. return new PermissionsMask([
  127. 'storage' => $storage,
  128. 'mask' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE,
  129. ]);
  130. }
  131. return $storage;
  132. }
  133. );
  134. // install storage availability wrapper, before most other wrappers
  135. Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
  136. $externalMount = $mount instanceof ConfigAdapter || $mount instanceof Mount;
  137. if ($externalMount && !$storage->isLocal()) {
  138. return new Availability(['storage' => $storage]);
  139. }
  140. return $storage;
  141. });
  142. Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
  143. if ($mount->getOption('encoding_compatibility', false) && !$mount instanceof SharedMount) {
  144. return new Encoding(['storage' => $storage]);
  145. }
  146. return $storage;
  147. });
  148. $quotaIncludeExternal = $this->config->getSystemValue('quota_include_external_storage', false);
  149. Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage, IMountPoint $mount) use ($quotaIncludeExternal) {
  150. // set up quota for home storages, even for other users
  151. // which can happen when using sharing
  152. if ($mount instanceof HomeMountPoint) {
  153. $user = $mount->getUser();
  154. return new Quota(['storage' => $storage, 'quotaCallback' => function () use ($user) {
  155. return OC_Util::getUserQuota($user);
  156. }, 'root' => 'files', 'include_external_storage' => $quotaIncludeExternal]);
  157. }
  158. return $storage;
  159. });
  160. Filesystem::addStorageWrapper('readonly', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
  161. /*
  162. * Do not allow any operations that modify the storage
  163. */
  164. if ($mount->getOption('readonly', false)) {
  165. return new PermissionsMask([
  166. 'storage' => $storage,
  167. 'mask' => Constants::PERMISSION_ALL & ~(
  168. Constants::PERMISSION_UPDATE |
  169. Constants::PERMISSION_CREATE |
  170. Constants::PERMISSION_DELETE
  171. ),
  172. ]);
  173. }
  174. return $storage;
  175. });
  176. Filesystem::logWarningWhenAddingStorageWrapper($prevLogging);
  177. }
  178. /**
  179. * Setup the full filesystem for the specified user
  180. */
  181. public function setupForUser(IUser $user): void {
  182. if ($this->isSetupComplete($user)) {
  183. return;
  184. }
  185. $this->setupUsersComplete[] = $user->getUID();
  186. $this->eventLogger->start('fs:setup:user:full', 'Setup full filesystem for user');
  187. if (!isset($this->setupUserMountProviders[$user->getUID()])) {
  188. $this->setupUserMountProviders[$user->getUID()] = [];
  189. }
  190. $previouslySetupProviders = $this->setupUserMountProviders[$user->getUID()];
  191. $this->setupForUserWith($user, function () use ($user) {
  192. $this->mountProviderCollection->addMountForUser($user, $this->mountManager, function (
  193. IMountProvider $provider
  194. ) use ($user) {
  195. return !in_array(get_class($provider), $this->setupUserMountProviders[$user->getUID()]);
  196. });
  197. });
  198. $this->afterUserFullySetup($user, $previouslySetupProviders);
  199. $this->eventLogger->end('fs:setup:user:full');
  200. }
  201. /**
  202. * part of the user setup that is run only once per user
  203. */
  204. private function oneTimeUserSetup(IUser $user) {
  205. if ($this->isSetupStarted($user)) {
  206. return;
  207. }
  208. $this->setupUsers[] = $user->getUID();
  209. $this->setupRoot();
  210. $this->eventLogger->start('fs:setup:user:onetime', 'Onetime filesystem for user');
  211. $this->setupBuiltinWrappers();
  212. $prevLogging = Filesystem::logWarningWhenAddingStorageWrapper(false);
  213. OC_Hook::emit('OC_Filesystem', 'preSetup', ['user' => $user->getUID()]);
  214. Filesystem::logWarningWhenAddingStorageWrapper($prevLogging);
  215. $userDir = '/' . $user->getUID() . '/files';
  216. Filesystem::initInternal($userDir);
  217. if ($this->lockdownManager->canAccessFilesystem()) {
  218. $this->eventLogger->start('fs:setup:user:home', 'Setup home filesystem for user');
  219. // home mounts are handled separate since we need to ensure this is mounted before we call the other mount providers
  220. $homeMount = $this->mountProviderCollection->getHomeMountForUser($user);
  221. $this->mountManager->addMount($homeMount);
  222. if ($homeMount->getStorageRootId() === -1) {
  223. $this->eventLogger->start('fs:setup:user:home:scan', 'Scan home filesystem for user');
  224. $homeMount->getStorage()->mkdir('');
  225. $homeMount->getStorage()->getScanner()->scan('');
  226. $this->eventLogger->end('fs:setup:user:home:scan');
  227. }
  228. $this->eventLogger->end('fs:setup:user:home');
  229. } else {
  230. $this->mountManager->addMount(new MountPoint(
  231. new NullStorage([]),
  232. '/' . $user->getUID()
  233. ));
  234. $this->mountManager->addMount(new MountPoint(
  235. new NullStorage([]),
  236. '/' . $user->getUID() . '/files'
  237. ));
  238. $this->setupUsersComplete[] = $user->getUID();
  239. }
  240. $this->listenForNewMountProviders();
  241. $this->eventLogger->end('fs:setup:user:onetime');
  242. }
  243. /**
  244. * Final housekeeping after a user has been fully setup
  245. */
  246. private function afterUserFullySetup(IUser $user, array $previouslySetupProviders): void {
  247. $this->eventLogger->start('fs:setup:user:full:post', 'Housekeeping after user is setup');
  248. $userRoot = '/' . $user->getUID() . '/';
  249. $mounts = $this->mountManager->getAll();
  250. $mounts = array_filter($mounts, function (IMountPoint $mount) use ($userRoot) {
  251. return str_starts_with($mount->getMountPoint(), $userRoot);
  252. });
  253. $allProviders = array_map(function (IMountProvider $provider) {
  254. return get_class($provider);
  255. }, $this->mountProviderCollection->getProviders());
  256. $newProviders = array_diff($allProviders, $previouslySetupProviders);
  257. $mounts = array_filter($mounts, function (IMountPoint $mount) use ($previouslySetupProviders) {
  258. return !in_array($mount->getMountProvider(), $previouslySetupProviders);
  259. });
  260. $this->userMountCache->registerMounts($user, $mounts, $newProviders);
  261. $cacheDuration = $this->config->getSystemValueInt('fs_mount_cache_duration', 5 * 60);
  262. if ($cacheDuration > 0) {
  263. $this->cache->set($user->getUID(), true, $cacheDuration);
  264. $this->fullSetupRequired[$user->getUID()] = false;
  265. }
  266. $this->eventLogger->end('fs:setup:user:full:post');
  267. }
  268. /**
  269. * @param IUser $user
  270. * @param IMountPoint $mounts
  271. * @return void
  272. * @throws \OCP\HintException
  273. * @throws \OC\ServerNotAvailableException
  274. */
  275. private function setupForUserWith(IUser $user, callable $mountCallback): void {
  276. $this->oneTimeUserSetup($user);
  277. if ($this->lockdownManager->canAccessFilesystem()) {
  278. $mountCallback();
  279. }
  280. $this->eventLogger->start('fs:setup:user:post-init-mountpoint', 'post_initMountPoints legacy hook');
  281. \OC_Hook::emit('OC_Filesystem', 'post_initMountPoints', ['user' => $user->getUID()]);
  282. $this->eventLogger->end('fs:setup:user:post-init-mountpoint');
  283. $userDir = '/' . $user->getUID() . '/files';
  284. $this->eventLogger->start('fs:setup:user:setup-hook', 'setup legacy hook');
  285. OC_Hook::emit('OC_Filesystem', 'setup', ['user' => $user->getUID(), 'user_dir' => $userDir]);
  286. $this->eventLogger->end('fs:setup:user:setup-hook');
  287. }
  288. /**
  289. * Set up the root filesystem
  290. */
  291. public function setupRoot(): void {
  292. //setting up the filesystem twice can only lead to trouble
  293. if ($this->rootSetup) {
  294. return;
  295. }
  296. $this->setupBuiltinWrappers();
  297. $this->rootSetup = true;
  298. $this->eventLogger->start('fs:setup:root', 'Setup root filesystem');
  299. $rootMounts = $this->mountProviderCollection->getRootMounts();
  300. foreach ($rootMounts as $rootMountProvider) {
  301. $this->mountManager->addMount($rootMountProvider);
  302. }
  303. $this->eventLogger->end('fs:setup:root');
  304. }
  305. /**
  306. * Get the user to setup for a path or `null` if the root needs to be setup
  307. *
  308. * @param string $path
  309. * @return IUser|null
  310. */
  311. private function getUserForPath(string $path) {
  312. if (str_starts_with($path, '/__groupfolders')) {
  313. return null;
  314. } elseif (substr_count($path, '/') < 2) {
  315. if ($user = $this->userSession->getUser()) {
  316. return $user;
  317. } else {
  318. return null;
  319. }
  320. } elseif (str_starts_with($path, '/appdata_' . \OC_Util::getInstanceId()) || str_starts_with($path, '/files_external/')) {
  321. return null;
  322. } else {
  323. [, $userId] = explode('/', $path);
  324. }
  325. return $this->userManager->get($userId);
  326. }
  327. /**
  328. * Set up the filesystem for the specified path
  329. */
  330. public function setupForPath(string $path, bool $includeChildren = false): void {
  331. $user = $this->getUserForPath($path);
  332. if (!$user) {
  333. $this->setupRoot();
  334. return;
  335. }
  336. if ($this->isSetupComplete($user)) {
  337. return;
  338. }
  339. if ($this->fullSetupRequired($user)) {
  340. $this->setupForUser($user);
  341. return;
  342. }
  343. // for the user's home folder, and includes children we need everything always
  344. if (rtrim($path) === "/" . $user->getUID() . "/files" && $includeChildren) {
  345. $this->setupForUser($user);
  346. return;
  347. }
  348. if (!isset($this->setupUserMountProviders[$user->getUID()])) {
  349. $this->setupUserMountProviders[$user->getUID()] = [];
  350. }
  351. $setupProviders = &$this->setupUserMountProviders[$user->getUID()];
  352. $currentProviders = [];
  353. try {
  354. $cachedMount = $this->userMountCache->getMountForPath($user, $path);
  355. } catch (NotFoundException $e) {
  356. $this->setupForUser($user);
  357. return;
  358. }
  359. $this->oneTimeUserSetup($user);
  360. $this->eventLogger->start('fs:setup:user:path', "Setup $path filesystem for user");
  361. $this->eventLogger->start('fs:setup:user:path:find', "Find mountpoint for $path");
  362. $mounts = [];
  363. if (!in_array($cachedMount->getMountProvider(), $setupProviders)) {
  364. $currentProviders[] = $cachedMount->getMountProvider();
  365. if ($cachedMount->getMountProvider()) {
  366. $setupProviders[] = $cachedMount->getMountProvider();
  367. $mounts = $this->mountProviderCollection->getUserMountsForProviderClasses($user, [$cachedMount->getMountProvider()]);
  368. } else {
  369. $this->logger->debug("mount at " . $cachedMount->getMountPoint() . " has no provider set, performing full setup");
  370. $this->eventLogger->end('fs:setup:user:path:find');
  371. $this->setupForUser($user);
  372. $this->eventLogger->end('fs:setup:user:path');
  373. return;
  374. }
  375. }
  376. if ($includeChildren) {
  377. $subCachedMounts = $this->userMountCache->getMountsInPath($user, $path);
  378. $this->eventLogger->end('fs:setup:user:path:find');
  379. $needsFullSetup = array_reduce($subCachedMounts, function (bool $needsFullSetup, ICachedMountInfo $cachedMountInfo) {
  380. return $needsFullSetup || $cachedMountInfo->getMountProvider() === '';
  381. }, false);
  382. if ($needsFullSetup) {
  383. $this->logger->debug("mount has no provider set, performing full setup");
  384. $this->setupForUser($user);
  385. $this->eventLogger->end('fs:setup:user:path');
  386. return;
  387. } else {
  388. foreach ($subCachedMounts as $cachedMount) {
  389. if (!in_array($cachedMount->getMountProvider(), $setupProviders)) {
  390. $currentProviders[] = $cachedMount->getMountProvider();
  391. $setupProviders[] = $cachedMount->getMountProvider();
  392. $mounts = array_merge($mounts, $this->mountProviderCollection->getUserMountsForProviderClasses($user, [$cachedMount->getMountProvider()]));
  393. }
  394. }
  395. }
  396. } else {
  397. $this->eventLogger->end('fs:setup:user:path:find');
  398. }
  399. if (count($mounts)) {
  400. $this->userMountCache->registerMounts($user, $mounts, $currentProviders);
  401. $this->setupForUserWith($user, function () use ($mounts) {
  402. array_walk($mounts, [$this->mountManager, 'addMount']);
  403. });
  404. } elseif (!$this->isSetupStarted($user)) {
  405. $this->oneTimeUserSetup($user);
  406. }
  407. $this->eventLogger->end('fs:setup:user:path');
  408. }
  409. private function fullSetupRequired(IUser $user): bool {
  410. // we perform a "cached" setup only after having done the full setup recently
  411. // this is also used to trigger a full setup after handling events that are likely
  412. // to change the available mounts
  413. if (!isset($this->fullSetupRequired[$user->getUID()])) {
  414. $this->fullSetupRequired[$user->getUID()] = !$this->cache->get($user->getUID());
  415. }
  416. return $this->fullSetupRequired[$user->getUID()];
  417. }
  418. /**
  419. * @param string $path
  420. * @param string[] $providers
  421. */
  422. public function setupForProvider(string $path, array $providers): void {
  423. $user = $this->getUserForPath($path);
  424. if (!$user) {
  425. $this->setupRoot();
  426. return;
  427. }
  428. if ($this->isSetupComplete($user)) {
  429. return;
  430. }
  431. if ($this->fullSetupRequired($user)) {
  432. $this->setupForUser($user);
  433. return;
  434. }
  435. $this->eventLogger->start('fs:setup:user:providers', "Setup filesystem for " . implode(', ', $providers));
  436. $this->oneTimeUserSetup($user);
  437. // home providers are always used
  438. $providers = array_filter($providers, function (string $provider) {
  439. return !is_subclass_of($provider, IHomeMountProvider::class);
  440. });
  441. if (in_array('', $providers)) {
  442. $this->setupForUser($user);
  443. return;
  444. }
  445. $setupProviders = $this->setupUserMountProviders[$user->getUID()] ?? [];
  446. $providers = array_diff($providers, $setupProviders);
  447. if (count($providers) === 0) {
  448. if (!$this->isSetupStarted($user)) {
  449. $this->oneTimeUserSetup($user);
  450. }
  451. $this->eventLogger->end('fs:setup:user:providers');
  452. return;
  453. } else {
  454. $this->setupUserMountProviders[$user->getUID()] = array_merge($setupProviders, $providers);
  455. $mounts = $this->mountProviderCollection->getUserMountsForProviderClasses($user, $providers);
  456. }
  457. $this->userMountCache->registerMounts($user, $mounts, $providers);
  458. $this->setupForUserWith($user, function () use ($mounts) {
  459. array_walk($mounts, [$this->mountManager, 'addMount']);
  460. });
  461. $this->eventLogger->end('fs:setup:user:providers');
  462. }
  463. public function tearDown() {
  464. $this->setupUsers = [];
  465. $this->setupUsersComplete = [];
  466. $this->setupUserMountProviders = [];
  467. $this->fullSetupRequired = [];
  468. $this->rootSetup = false;
  469. $this->mountManager->clear();
  470. $this->eventDispatcher->dispatchTyped(new FilesystemTornDownEvent());
  471. }
  472. /**
  473. * Get mounts from mount providers that are registered after setup
  474. */
  475. private function listenForNewMountProviders() {
  476. if (!$this->listeningForProviders) {
  477. $this->listeningForProviders = true;
  478. $this->mountProviderCollection->listen('\OC\Files\Config', 'registerMountProvider', function (
  479. IMountProvider $provider
  480. ) {
  481. foreach ($this->setupUsers as $userId) {
  482. $user = $this->userManager->get($userId);
  483. if ($user) {
  484. $mounts = $provider->getMountsForUser($user, Filesystem::getLoader());
  485. array_walk($mounts, [$this->mountManager, 'addMount']);
  486. }
  487. }
  488. });
  489. }
  490. }
  491. private function setupListeners() {
  492. // note that this event handling is intentionally pessimistic
  493. // clearing the cache to often is better than not enough
  494. $this->eventDispatcher->addListener(UserAddedEvent::class, function (UserAddedEvent $event) {
  495. $this->cache->remove($event->getUser()->getUID());
  496. });
  497. $this->eventDispatcher->addListener(UserRemovedEvent::class, function (UserRemovedEvent $event) {
  498. $this->cache->remove($event->getUser()->getUID());
  499. });
  500. $this->eventDispatcher->addListener(ShareCreatedEvent::class, function (ShareCreatedEvent $event) {
  501. $this->cache->remove($event->getShare()->getSharedWith());
  502. });
  503. $this->eventDispatcher->addListener(InvalidateMountCacheEvent::class, function (InvalidateMountCacheEvent $event
  504. ) {
  505. if ($user = $event->getUser()) {
  506. $this->cache->remove($user->getUID());
  507. } else {
  508. $this->cache->clear();
  509. }
  510. });
  511. $genericEvents = [
  512. 'OCA\Circles\Events\CreatingCircleEvent',
  513. 'OCA\Circles\Events\DestroyingCircleEvent',
  514. 'OCA\Circles\Events\AddingCircleMemberEvent',
  515. 'OCA\Circles\Events\RemovingCircleMemberEvent',
  516. ];
  517. foreach ($genericEvents as $genericEvent) {
  518. $this->eventDispatcher->addListener($genericEvent, function ($event) {
  519. $this->cache->clear();
  520. });
  521. }
  522. }
  523. }