1
0

Home.php 2.7 KB

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 <pvince81@owncloud.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. /**
  29. * Specialized version of Local storage for home directory usage
  30. */
  31. class Home extends Local implements \OCP\Files\IHomeStorage {
  32. /**
  33. * @var string
  34. */
  35. protected $id;
  36. /**
  37. * @var \OC\User\User $user
  38. */
  39. protected $user;
  40. /**
  41. * Construct a Home storage instance
  42. *
  43. * @param array $arguments array with "user" containing the
  44. * storage owner
  45. */
  46. public function __construct($arguments) {
  47. $this->user = $arguments['user'];
  48. $datadir = $this->user->getHome();
  49. $this->id = 'home::' . $this->user->getUID();
  50. parent::__construct(['datadir' => $datadir]);
  51. }
  52. public function getId() {
  53. return $this->id;
  54. }
  55. /**
  56. * @return \OC\Files\Cache\HomeCache
  57. */
  58. public function getCache($path = '', $storage = null) {
  59. if (!$storage) {
  60. $storage = $this;
  61. }
  62. if (!isset($this->cache)) {
  63. $this->cache = new \OC\Files\Cache\HomeCache($storage);
  64. }
  65. return $this->cache;
  66. }
  67. /**
  68. * get a propagator instance for the cache
  69. *
  70. * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher
  71. * @return \OC\Files\Cache\Propagator
  72. */
  73. public function getPropagator($storage = null) {
  74. if (!$storage) {
  75. $storage = $this;
  76. }
  77. if (!isset($this->propagator)) {
  78. $this->propagator = new HomePropagator($storage, \OC::$server->getDatabaseConnection());
  79. }
  80. return $this->propagator;
  81. }
  82. /**
  83. * Returns the owner of this home storage
  84. *
  85. * @return \OC\User\User owner of this home storage
  86. */
  87. public function getUser() {
  88. return $this->user;
  89. }
  90. /**
  91. * get the owner of a path
  92. *
  93. * @param string $path The path to get the owner
  94. * @return string uid or false
  95. */
  96. public function getOwner($path) {
  97. return $this->user->getUID();
  98. }
  99. }