1
0

CacheMountProvider.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\Files\Mount;
  8. use OCP\Files\Config\IMountProvider;
  9. use OCP\Files\Storage\IStorageFactory;
  10. use OCP\IConfig;
  11. use OCP\IUser;
  12. /**
  13. * Mount provider for custom cache storages
  14. */
  15. class CacheMountProvider implements IMountProvider {
  16. /**
  17. * @var IConfig
  18. */
  19. private $config;
  20. /**
  21. * ObjectStoreHomeMountProvider constructor.
  22. *
  23. * @param IConfig $config
  24. */
  25. public function __construct(IConfig $config) {
  26. $this->config = $config;
  27. }
  28. /**
  29. * Get the cache mount for a user
  30. *
  31. * @param IUser $user
  32. * @param IStorageFactory $loader
  33. * @return \OCP\Files\Mount\IMountPoint[]
  34. */
  35. public function getMountsForUser(IUser $user, IStorageFactory $loader) {
  36. $cacheBaseDir = $this->config->getSystemValueString('cache_path', '');
  37. if ($cacheBaseDir !== '') {
  38. $cacheDir = rtrim($cacheBaseDir, '/') . '/' . $user->getUID();
  39. if (!file_exists($cacheDir)) {
  40. mkdir($cacheDir, 0770, true);
  41. mkdir($cacheDir . '/uploads', 0770, true);
  42. }
  43. return [
  44. new MountPoint('\OC\Files\Storage\Local', '/' . $user->getUID() . '/cache', ['datadir' => $cacheDir], $loader, null, null, self::class),
  45. new MountPoint('\OC\Files\Storage\Local', '/' . $user->getUID() . '/uploads', ['datadir' => $cacheDir . '/uploads'], $loader, null, null, self::class)
  46. ];
  47. } else {
  48. return [];
  49. }
  50. }
  51. }