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.

CachedMountInfo.php 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. return $userNode->getParent()->getFirstNodeById($this->getRootId());
  94. }
  95. /**
  96. * @return string the mount point of the mount for the user
  97. */
  98. public function getMountPoint(): string {
  99. return $this->mountPoint;
  100. }
  101. /**
  102. * Get the id of the configured mount
  103. *
  104. * @return int|null mount id or null if not applicable
  105. * @since 9.1.0
  106. */
  107. public function getMountId(): ?int {
  108. return $this->mountId;
  109. }
  110. /**
  111. * Get the internal path (within the storage) of the root of the mount
  112. *
  113. * @return string
  114. */
  115. public function getRootInternalPath(): string {
  116. return $this->rootInternalPath;
  117. }
  118. public function getMountProvider(): string {
  119. return $this->mountProvider;
  120. }
  121. public function getKey(): string {
  122. return $this->key;
  123. }
  124. }