Home.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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\Storage;
  8. use OC\Files\Cache\HomePropagator;
  9. use OCP\Files\Cache\ICache;
  10. use OCP\Files\Cache\IPropagator;
  11. use OCP\Files\Storage\IStorage;
  12. use OCP\IUser;
  13. /**
  14. * Specialized version of Local storage for home directory usage
  15. */
  16. class Home extends Local implements \OCP\Files\IHomeStorage {
  17. /**
  18. * @var string
  19. */
  20. protected $id;
  21. /**
  22. * @var \OC\User\User $user
  23. */
  24. protected $user;
  25. /**
  26. * Construct a Home storage instance
  27. *
  28. * @param array $parameters array with "user" containing the
  29. * storage owner
  30. */
  31. public function __construct(array $parameters) {
  32. $this->user = $parameters['user'];
  33. $datadir = $this->user->getHome();
  34. $this->id = 'home::' . $this->user->getUID();
  35. parent::__construct(['datadir' => $datadir]);
  36. }
  37. public function getId(): string {
  38. return $this->id;
  39. }
  40. public function getCache(string $path = '', ?IStorage $storage = null): ICache {
  41. if (!$storage) {
  42. $storage = $this;
  43. }
  44. if (!isset($this->cache)) {
  45. $this->cache = new \OC\Files\Cache\HomeCache($storage, $this->getCacheDependencies());
  46. }
  47. return $this->cache;
  48. }
  49. public function getPropagator(?IStorage $storage = null): IPropagator {
  50. if (!$storage) {
  51. $storage = $this;
  52. }
  53. if (!isset($this->propagator)) {
  54. $this->propagator = new HomePropagator($storage, \OC::$server->getDatabaseConnection());
  55. }
  56. return $this->propagator;
  57. }
  58. public function getUser(): IUser {
  59. return $this->user;
  60. }
  61. public function getOwner(string $path): string|false {
  62. return $this->user->getUID();
  63. }
  64. }