1
0

SetupManager.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  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 ($storage->instanceOfStorage(Common::class)) {
  113. $options = array_merge($mount->getOptions(), ['mount_point' => $mountPoint]);
  114. $storage->setMountOptions($options);
  115. }
  116. return $storage;
  117. });
  118. $reSharingEnabled = Share::isResharingAllowed();
  119. $user = $this->userSession->getUser();
  120. $sharingEnabledForUser = $user ? !$this->shareDisableChecker->sharingDisabledForUser($user->getUID()) : true;
  121. Filesystem::addStorageWrapper(
  122. 'sharing_mask',
  123. function ($mountPoint, IStorage $storage, IMountPoint $mount) use ($reSharingEnabled, $sharingEnabledForUser) {
  124. $sharingEnabledForMount = $mount->getOption('enable_sharing', true);
  125. $isShared = $mount instanceof ISharedMountPoint;
  126. if (!$sharingEnabledForMount || !$sharingEnabledForUser || (!$reSharingEnabled && $isShared)) {
  127. return new PermissionsMask([
  128. 'storage' => $storage,
  129. 'mask' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE,
  130. ]);
  131. }
  132. return $storage;
  133. }
  134. );
  135. // install storage availability wrapper, before most other wrappers
  136. Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
  137. $externalMount = $mount instanceof ConfigAdapter || $mount instanceof Mount;
  138. if ($externalMount && !$storage->isLocal()) {
  139. return new Availability(['storage' => $storage]);
  140. }
  141. return $storage;
  142. });
  143. Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
  144. if ($mount->getOption('encoding_compatibility', false) && !$mount instanceof SharedMount) {
  145. return new Encoding(['storage' => $storage]);
  146. }
  147. return $storage;
  148. });
  149. $quotaIncludeExternal = $this->config->getSystemValue('quota_include_external_storage', false);
  150. Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage, IMountPoint $mount) use ($quotaIncludeExternal) {
  151. // set up quota for home storages, even for other users
  152. // which can happen when using sharing
  153. if ($mount instanceof HomeMountPoint) {
  154. $user = $mount->getUser();
  155. return new Quota(['storage' => $storage, 'quotaCallback' => function () use ($user) {
  156. return OC_Util::getUserQuota($user);
  157. }, 'root' => 'files', 'include_external_storage' => $quotaIncludeExternal]);
  158. }
  159. return $storage;
  160. });
  161. Filesystem::addStorageWrapper('readonly', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
  162. /*
  163. * Do not allow any operations that modify the storage
  164. */
  165. if ($mount->getOption('readonly', false)) {
  166. return new PermissionsMask([
  167. 'storage' => $storage,
  168. 'mask' => Constants::PERMISSION_ALL & ~(
  169. Constants::PERMISSION_UPDATE |
  170. Constants::PERMISSION_CREATE |
  171. Constants::PERMISSION_DELETE
  172. ),
  173. ]);
  174. }
  175. return $storage;
  176. });
  177. Filesystem::logWarningWhenAddingStorageWrapper($prevLogging);
  178. }
  179. /**
  180. * Setup the full filesystem for the specified user
  181. */
  182. public function setupForUser(IUser $user): void {
  183. if ($this->isSetupComplete($user)) {
  184. return;
  185. }
  186. $this->setupUsersComplete[] = $user->getUID();
  187. $this->eventLogger->start('fs:setup:user:full', 'Setup full filesystem for user');
  188. if (!isset($this->setupUserMountProviders[$user->getUID()])) {
  189. $this->setupUserMountProviders[$user->getUID()] = [];
  190. }
  191. $previouslySetupProviders = $this->setupUserMountProviders[$user->getUID()];
  192. $this->setupForUserWith($user, function () use ($user) {
  193. $this->mountProviderCollection->addMountForUser($user, $this->mountManager, function (
  194. IMountProvider $provider
  195. ) use ($user) {
  196. return !in_array(get_class($provider), $this->setupUserMountProviders[$user->getUID()]);
  197. });
  198. });
  199. $this->afterUserFullySetup($user, $previouslySetupProviders);
  200. $this->eventLogger->end('fs:setup:user:full');
  201. }
  202. /**
  203. * part of the user setup that is run only once per user
  204. */
  205. private function oneTimeUserSetup(IUser $user) {
  206. if ($this->isSetupStarted($user)) {
  207. return;
  208. }
  209. $this->setupUsers[] = $user->getUID();
  210. $this->setupRoot();
  211. $this->eventLogger->start('fs:setup:user:onetime', 'Onetime filesystem for user');
  212. $this->setupBuiltinWrappers();
  213. $prevLogging = Filesystem::logWarningWhenAddingStorageWrapper(false);
  214. OC_Hook::emit('OC_Filesystem', 'preSetup', ['user' => $user->getUID()]);
  215. Filesystem::logWarningWhenAddingStorageWrapper($prevLogging);
  216. $userDir = '/' . $user->getUID() . '/files';
  217. Filesystem::initInternal($userDir);
  218. if ($this->lockdownManager->canAccessFilesystem()) {
  219. $this->eventLogger->start('fs:setup:user:home', 'Setup home filesystem for user');
  220. // home mounts are handled separate since we need to ensure this is mounted before we call the other mount providers
  221. $homeMount = $this->mountProviderCollection->getHomeMountForUser($user);
  222. $this->mountManager->addMount($homeMount);
  223. if ($homeMount->getStorageRootId() === -1) {
  224. $this->eventLogger->start('fs:setup:user:home:scan', 'Scan home filesystem for user');
  225. $homeMount->getStorage()->mkdir('');
  226. $homeMount->getStorage()->getScanner()->scan('');
  227. $this->eventLogger->end('fs:setup:user:home:scan');
  228. }
  229. $this->eventLogger->end('fs:setup:user:home');
  230. } else {
  231. $this->mountManager->addMount(new MountPoint(
  232. new NullStorage([]),
  233. '/' . $user->getUID()
  234. ));
  235. $this->mountManager->addMount(new MountPoint(
  236. new NullStorage([]),
  237. '/' . $user->getUID() . '/files'
  238. ));
  239. $this->setupUsersComplete[] = $user->getUID();
  240. }
  241. $this->listenForNewMountProviders();
  242. $this->eventLogger->end('fs:setup:user:onetime');
  243. }
  244. /**
  245. * Final housekeeping after a user has been fully setup
  246. */
  247. private function afterUserFullySetup(IUser $user, array $previouslySetupProviders): void {
  248. $this->eventLogger->start('fs:setup:user:full:post', 'Housekeeping after user is setup');
  249. $userRoot = '/' . $user->getUID() . '/';
  250. $mounts = $this->mountManager->getAll();
  251. $mounts = array_filter($mounts, function (IMountPoint $mount) use ($userRoot) {
  252. return str_starts_with($mount->getMountPoint(), $userRoot);
  253. });
  254. $allProviders = array_map(function (IMountProvider $provider) {
  255. return get_class($provider);
  256. }, $this->mountProviderCollection->getProviders());
  257. $newProviders = array_diff($allProviders, $previouslySetupProviders);
  258. $mounts = array_filter($mounts, function (IMountPoint $mount) use ($previouslySetupProviders) {
  259. return !in_array($mount->getMountProvider(), $previouslySetupProviders);
  260. });
  261. $this->userMountCache->registerMounts($user, $mounts, $newProviders);
  262. $cacheDuration = $this->config->getSystemValueInt('fs_mount_cache_duration', 5 * 60);
  263. if ($cacheDuration > 0) {
  264. $this->cache->set($user->getUID(), true, $cacheDuration);
  265. $this->fullSetupRequired[$user->getUID()] = false;
  266. }
  267. $this->eventLogger->end('fs:setup:user:full:post');
  268. }
  269. /**
  270. * @param IUser $user
  271. * @param IMountPoint $mounts
  272. * @return void
  273. * @throws \OCP\HintException
  274. * @throws \OC\ServerNotAvailableException
  275. */
  276. private function setupForUserWith(IUser $user, callable $mountCallback): void {
  277. $this->oneTimeUserSetup($user);
  278. if ($this->lockdownManager->canAccessFilesystem()) {
  279. $mountCallback();
  280. }
  281. $this->eventLogger->start('fs:setup:user:post-init-mountpoint', 'post_initMountPoints legacy hook');
  282. \OC_Hook::emit('OC_Filesystem', 'post_initMountPoints', ['user' => $user->getUID()]);
  283. $this->eventLogger->end('fs:setup:user:post-init-mountpoint');
  284. $userDir = '/' . $user->getUID() . '/files';
  285. $this->eventLogger->start('fs:setup:user:setup-hook', 'setup legacy hook');
  286. OC_Hook::emit('OC_Filesystem', 'setup', ['user' => $user->getUID(), 'user_dir' => $userDir]);
  287. $this->eventLogger->end('fs:setup:user:setup-hook');
  288. }
  289. /**
  290. * Set up the root filesystem
  291. */
  292. public function setupRoot(): void {
  293. //setting up the filesystem twice can only lead to trouble
  294. if ($this->rootSetup) {
  295. return;
  296. }
  297. $this->setupBuiltinWrappers();
  298. $this->rootSetup = true;
  299. $this->eventLogger->start('fs:setup:root', 'Setup root filesystem');
  300. $rootMounts = $this->mountProviderCollection->getRootMounts();
  301. foreach ($rootMounts as $rootMountProvider) {
  302. $this->mountManager->addMount($rootMountProvider);
  303. }
  304. $this->eventLogger->end('fs:setup:root');
  305. }
  306. /**
  307. * Get the user to setup for a path or `null` if the root needs to be setup
  308. *
  309. * @param string $path
  310. * @return IUser|null
  311. */
  312. private function getUserForPath(string $path) {
  313. if (str_starts_with($path, '/__groupfolders')) {
  314. return null;
  315. } elseif (substr_count($path, '/') < 2) {
  316. if ($user = $this->userSession->getUser()) {
  317. return $user;
  318. } else {
  319. return null;
  320. }
  321. } elseif (str_starts_with($path, '/appdata_' . \OC_Util::getInstanceId()) || str_starts_with($path, '/files_external/')) {
  322. return null;
  323. } else {
  324. [, $userId] = explode('/', $path);
  325. }
  326. return $this->userManager->get($userId);
  327. }
  328. /**
  329. * Set up the filesystem for the specified path
  330. */
  331. public function setupForPath(string $path, bool $includeChildren = false): void {
  332. $user = $this->getUserForPath($path);
  333. if (!$user) {
  334. $this->setupRoot();
  335. return;
  336. }
  337. if ($this->isSetupComplete($user)) {
  338. return;
  339. }
  340. if ($this->fullSetupRequired($user)) {
  341. $this->setupForUser($user);
  342. return;
  343. }
  344. // for the user's home folder, and includes children we need everything always
  345. if (rtrim($path) === "/" . $user->getUID() . "/files" && $includeChildren) {
  346. $this->setupForUser($user);
  347. return;
  348. }
  349. if (!isset($this->setupUserMountProviders[$user->getUID()])) {
  350. $this->setupUserMountProviders[$user->getUID()] = [];
  351. }
  352. $setupProviders = &$this->setupUserMountProviders[$user->getUID()];
  353. $currentProviders = [];
  354. try {
  355. $cachedMount = $this->userMountCache->getMountForPath($user, $path);
  356. } catch (NotFoundException $e) {
  357. $this->setupForUser($user);
  358. return;
  359. }
  360. $this->oneTimeUserSetup($user);
  361. $this->eventLogger->start('fs:setup:user:path', "Setup $path filesystem for user");
  362. $this->eventLogger->start('fs:setup:user:path:find', "Find mountpoint for $path");
  363. $mounts = [];
  364. if (!in_array($cachedMount->getMountProvider(), $setupProviders)) {
  365. $currentProviders[] = $cachedMount->getMountProvider();
  366. if ($cachedMount->getMountProvider()) {
  367. $setupProviders[] = $cachedMount->getMountProvider();
  368. $mounts = $this->mountProviderCollection->getUserMountsForProviderClasses($user, [$cachedMount->getMountProvider()]);
  369. } else {
  370. $this->logger->debug("mount at " . $cachedMount->getMountPoint() . " has no provider set, performing full setup");
  371. $this->eventLogger->end('fs:setup:user:path:find');
  372. $this->setupForUser($user);
  373. $this->eventLogger->end('fs:setup:user:path');
  374. return;
  375. }
  376. }
  377. if ($includeChildren) {
  378. $subCachedMounts = $this->userMountCache->getMountsInPath($user, $path);
  379. $this->eventLogger->end('fs:setup:user:path:find');
  380. $needsFullSetup = array_reduce($subCachedMounts, function (bool $needsFullSetup, ICachedMountInfo $cachedMountInfo) {
  381. return $needsFullSetup || $cachedMountInfo->getMountProvider() === '';
  382. }, false);
  383. if ($needsFullSetup) {
  384. $this->logger->debug("mount has no provider set, performing full setup");
  385. $this->setupForUser($user);
  386. $this->eventLogger->end('fs:setup:user:path');
  387. return;
  388. } else {
  389. foreach ($subCachedMounts as $cachedMount) {
  390. if (!in_array($cachedMount->getMountProvider(), $setupProviders)) {
  391. $currentProviders[] = $cachedMount->getMountProvider();
  392. $setupProviders[] = $cachedMount->getMountProvider();
  393. $mounts = array_merge($mounts, $this->mountProviderCollection->getUserMountsForProviderClasses($user, [$cachedMount->getMountProvider()]));
  394. }
  395. }
  396. }
  397. } else {
  398. $this->eventLogger->end('fs:setup:user:path:find');
  399. }
  400. if (count($mounts)) {
  401. $this->userMountCache->registerMounts($user, $mounts, $currentProviders);
  402. $this->setupForUserWith($user, function () use ($mounts) {
  403. array_walk($mounts, [$this->mountManager, 'addMount']);
  404. });
  405. } elseif (!$this->isSetupStarted($user)) {
  406. $this->oneTimeUserSetup($user);
  407. }
  408. $this->eventLogger->end('fs:setup:user:path');
  409. }
  410. private function fullSetupRequired(IUser $user): bool {
  411. // we perform a "cached" setup only after having done the full setup recently
  412. // this is also used to trigger a full setup after handling events that are likely
  413. // to change the available mounts
  414. if (!isset($this->fullSetupRequired[$user->getUID()])) {
  415. $this->fullSetupRequired[$user->getUID()] = !$this->cache->get($user->getUID());
  416. }
  417. return $this->fullSetupRequired[$user->getUID()];
  418. }
  419. /**
  420. * @param string $path
  421. * @param string[] $providers
  422. */
  423. public function setupForProvider(string $path, array $providers): void {
  424. $user = $this->getUserForPath($path);
  425. if (!$user) {
  426. $this->setupRoot();
  427. return;
  428. }
  429. if ($this->isSetupComplete($user)) {
  430. return;
  431. }
  432. if ($this->fullSetupRequired($user)) {
  433. $this->setupForUser($user);
  434. return;
  435. }
  436. $this->eventLogger->start('fs:setup:user:providers', "Setup filesystem for " . implode(', ', $providers));
  437. $this->oneTimeUserSetup($user);
  438. // home providers are always used
  439. $providers = array_filter($providers, function (string $provider) {
  440. return !is_subclass_of($provider, IHomeMountProvider::class);
  441. });
  442. if (in_array('', $providers)) {
  443. $this->setupForUser($user);
  444. return;
  445. }
  446. $setupProviders = $this->setupUserMountProviders[$user->getUID()] ?? [];
  447. $providers = array_diff($providers, $setupProviders);
  448. if (count($providers) === 0) {
  449. if (!$this->isSetupStarted($user)) {
  450. $this->oneTimeUserSetup($user);
  451. }
  452. $this->eventLogger->end('fs:setup:user:providers');
  453. return;
  454. } else {
  455. $this->setupUserMountProviders[$user->getUID()] = array_merge($setupProviders, $providers);
  456. $mounts = $this->mountProviderCollection->getUserMountsForProviderClasses($user, $providers);
  457. }
  458. $this->userMountCache->registerMounts($user, $mounts, $providers);
  459. $this->setupForUserWith($user, function () use ($mounts) {
  460. array_walk($mounts, [$this->mountManager, 'addMount']);
  461. });
  462. $this->eventLogger->end('fs:setup:user:providers');
  463. }
  464. public function tearDown() {
  465. $this->setupUsers = [];
  466. $this->setupUsersComplete = [];
  467. $this->setupUserMountProviders = [];
  468. $this->fullSetupRequired = [];
  469. $this->rootSetup = false;
  470. $this->mountManager->clear();
  471. $this->eventDispatcher->dispatchTyped(new FilesystemTornDownEvent());
  472. }
  473. /**
  474. * Get mounts from mount providers that are registered after setup
  475. */
  476. private function listenForNewMountProviders() {
  477. if (!$this->listeningForProviders) {
  478. $this->listeningForProviders = true;
  479. $this->mountProviderCollection->listen('\OC\Files\Config', 'registerMountProvider', function (
  480. IMountProvider $provider
  481. ) {
  482. foreach ($this->setupUsers as $userId) {
  483. $user = $this->userManager->get($userId);
  484. if ($user) {
  485. $mounts = $provider->getMountsForUser($user, Filesystem::getLoader());
  486. array_walk($mounts, [$this->mountManager, 'addMount']);
  487. }
  488. }
  489. });
  490. }
  491. }
  492. private function setupListeners() {
  493. // note that this event handling is intentionally pessimistic
  494. // clearing the cache to often is better than not enough
  495. $this->eventDispatcher->addListener(UserAddedEvent::class, function (UserAddedEvent $event) {
  496. $this->cache->remove($event->getUser()->getUID());
  497. });
  498. $this->eventDispatcher->addListener(UserRemovedEvent::class, function (UserRemovedEvent $event) {
  499. $this->cache->remove($event->getUser()->getUID());
  500. });
  501. $this->eventDispatcher->addListener(ShareCreatedEvent::class, function (ShareCreatedEvent $event) {
  502. $this->cache->remove($event->getShare()->getSharedWith());
  503. });
  504. $this->eventDispatcher->addListener(InvalidateMountCacheEvent::class, function (InvalidateMountCacheEvent $event
  505. ) {
  506. if ($user = $event->getUser()) {
  507. $this->cache->remove($user->getUID());
  508. } else {
  509. $this->cache->clear();
  510. }
  511. });
  512. $genericEvents = [
  513. 'OCA\Circles\Events\CreatingCircleEvent',
  514. 'OCA\Circles\Events\DestroyingCircleEvent',
  515. 'OCA\Circles\Events\AddingCircleMemberEvent',
  516. 'OCA\Circles\Events\RemovingCircleMemberEvent',
  517. ];
  518. foreach ($genericEvents as $genericEvent) {
  519. $this->eventDispatcher->addListener($genericEvent, function ($event) {
  520. $this->cache->clear();
  521. });
  522. }
  523. }
  524. }