Home.php 2.6 KB

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