Home.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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\IUser;
  10. /**
  11. * Specialized version of Local storage for home directory usage
  12. */
  13. class Home extends Local implements \OCP\Files\IHomeStorage {
  14. /**
  15. * @var string
  16. */
  17. protected $id;
  18. /**
  19. * @var \OC\User\User $user
  20. */
  21. protected $user;
  22. /**
  23. * Construct a Home storage instance
  24. *
  25. * @param array $arguments array with "user" containing the
  26. * storage owner
  27. */
  28. public function __construct($arguments) {
  29. $this->user = $arguments['user'];
  30. $datadir = $this->user->getHome();
  31. $this->id = 'home::' . $this->user->getUID();
  32. parent::__construct(['datadir' => $datadir]);
  33. }
  34. public function getId() {
  35. return $this->id;
  36. }
  37. /**
  38. * @return \OC\Files\Cache\HomeCache
  39. */
  40. public function getCache($path = '', $storage = null) {
  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. /**
  50. * get a propagator instance for the cache
  51. *
  52. * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher
  53. * @return \OC\Files\Cache\Propagator
  54. */
  55. public function getPropagator($storage = null) {
  56. if (!$storage) {
  57. $storage = $this;
  58. }
  59. if (!isset($this->propagator)) {
  60. $this->propagator = new HomePropagator($storage, \OC::$server->getDatabaseConnection());
  61. }
  62. return $this->propagator;
  63. }
  64. /**
  65. * Returns the owner of this home storage
  66. *
  67. * @return \OC\User\User owner of this home storage
  68. */
  69. public function getUser(): IUser {
  70. return $this->user;
  71. }
  72. /**
  73. * get the owner of a path
  74. *
  75. * @param string $path The path to get the owner
  76. * @return string uid or false
  77. */
  78. public function getOwner($path) {
  79. return $this->user->getUID();
  80. }
  81. }