You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Home.php 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Robin Appelman <robin@icewind.nl>
  8. * @author Thomas Müller <thomas.mueller@tmit.eu>
  9. * @author Vincent Petry <vincent@nextcloud.com>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OC\Files\Storage;
  27. use OC\Files\Cache\HomePropagator;
  28. use OCP\IUser;
  29. /**
  30. * Specialized version of Local storage for home directory usage
  31. */
  32. class Home extends Local implements \OCP\Files\IHomeStorage {
  33. /**
  34. * @var string
  35. */
  36. protected $id;
  37. /**
  38. * @var \OC\User\User $user
  39. */
  40. protected $user;
  41. /**
  42. * Construct a Home storage instance
  43. *
  44. * @param array $arguments array with "user" containing the
  45. * storage owner
  46. */
  47. public function __construct($arguments) {
  48. $this->user = $arguments['user'];
  49. $datadir = $this->user->getHome();
  50. $this->id = 'home::' . $this->user->getUID();
  51. parent::__construct(['datadir' => $datadir]);
  52. }
  53. public function getId() {
  54. return $this->id;
  55. }
  56. /**
  57. * @return \OC\Files\Cache\HomeCache
  58. */
  59. public function getCache($path = '', $storage = null) {
  60. if (!$storage) {
  61. $storage = $this;
  62. }
  63. if (!isset($this->cache)) {
  64. $this->cache = new \OC\Files\Cache\HomeCache($storage);
  65. }
  66. return $this->cache;
  67. }
  68. /**
  69. * get a propagator instance for the cache
  70. *
  71. * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher
  72. * @return \OC\Files\Cache\Propagator
  73. */
  74. public function getPropagator($storage = null) {
  75. if (!$storage) {
  76. $storage = $this;
  77. }
  78. if (!isset($this->propagator)) {
  79. $this->propagator = new HomePropagator($storage, \OC::$server->getDatabaseConnection());
  80. }
  81. return $this->propagator;
  82. }
  83. /**
  84. * Returns the owner of this home storage
  85. *
  86. * @return \OC\User\User owner of this home storage
  87. */
  88. public function getUser(): IUser {
  89. return $this->user;
  90. }
  91. /**
  92. * get the owner of a path
  93. *
  94. * @param string $path The path to get the owner
  95. * @return string uid or false
  96. */
  97. public function getOwner($path) {
  98. return $this->user->getUID();
  99. }
  100. }