CachedMountInfo.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Robin Appelman <robin@icewind.nl>
  6. * @author Semih Serhat Karakaya <karakayasemi@itu.edu.tr>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OC\Files\Config;
  24. use OC\Files\Filesystem;
  25. use OCP\Files\Config\ICachedMountInfo;
  26. use OCP\Files\Node;
  27. use OCP\IUser;
  28. class CachedMountInfo implements ICachedMountInfo {
  29. protected IUser $user;
  30. protected int $storageId;
  31. protected int $rootId;
  32. protected string $mountPoint;
  33. protected ?int $mountId;
  34. protected string $rootInternalPath;
  35. protected string $mountProvider;
  36. protected string $key;
  37. /**
  38. * CachedMountInfo constructor.
  39. *
  40. * @param IUser $user
  41. * @param int $storageId
  42. * @param int $rootId
  43. * @param string $mountPoint
  44. * @param int|null $mountId
  45. * @param string $rootInternalPath
  46. */
  47. public function __construct(
  48. IUser $user,
  49. int $storageId,
  50. int $rootId,
  51. string $mountPoint,
  52. string $mountProvider,
  53. int $mountId = null,
  54. string $rootInternalPath = ''
  55. ) {
  56. $this->user = $user;
  57. $this->storageId = $storageId;
  58. $this->rootId = $rootId;
  59. $this->mountPoint = $mountPoint;
  60. $this->mountId = $mountId;
  61. $this->rootInternalPath = $rootInternalPath;
  62. if (strlen($mountProvider) > 128) {
  63. throw new \Exception("Mount provider $mountProvider name exceeds the limit of 128 characters");
  64. }
  65. $this->mountProvider = $mountProvider;
  66. $this->key = $rootId . '::' . $mountPoint;
  67. }
  68. /**
  69. * @return IUser
  70. */
  71. public function getUser(): IUser {
  72. return $this->user;
  73. }
  74. /**
  75. * @return int the numeric storage id of the mount
  76. */
  77. public function getStorageId(): int {
  78. return $this->storageId;
  79. }
  80. /**
  81. * @return int the fileid of the root of the mount
  82. */
  83. public function getRootId(): int {
  84. return $this->rootId;
  85. }
  86. /**
  87. * @return Node|null the root node of the mount
  88. */
  89. public function getMountPointNode(): ?Node {
  90. // TODO injection etc
  91. Filesystem::initMountPoints($this->getUser()->getUID());
  92. $userNode = \OC::$server->getUserFolder($this->getUser()->getUID());
  93. $nodes = $userNode->getParent()->getById($this->getRootId());
  94. if (count($nodes) > 0) {
  95. return $nodes[0];
  96. } else {
  97. return null;
  98. }
  99. }
  100. /**
  101. * @return string the mount point of the mount for the user
  102. */
  103. public function getMountPoint(): string {
  104. return $this->mountPoint;
  105. }
  106. /**
  107. * Get the id of the configured mount
  108. *
  109. * @return int|null mount id or null if not applicable
  110. * @since 9.1.0
  111. */
  112. public function getMountId(): ?int {
  113. return $this->mountId;
  114. }
  115. /**
  116. * Get the internal path (within the storage) of the root of the mount
  117. *
  118. * @return string
  119. */
  120. public function getRootInternalPath(): string {
  121. return $this->rootInternalPath;
  122. }
  123. public function getMountProvider(): string {
  124. return $this->mountProvider;
  125. }
  126. public function getKey(): string {
  127. return $this->key;
  128. }
  129. }