1
0

home.php 2.9 KB

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