CachedMountInfo.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. /**
  37. * CachedMountInfo constructor.
  38. *
  39. * @param IUser $user
  40. * @param int $storageId
  41. * @param int $rootId
  42. * @param string $mountPoint
  43. * @param int|null $mountId
  44. * @param string $rootInternalPath
  45. */
  46. public function __construct(
  47. IUser $user,
  48. int $storageId,
  49. int $rootId,
  50. string $mountPoint,
  51. string $mountProvider,
  52. int $mountId = null,
  53. string $rootInternalPath = ''
  54. ) {
  55. $this->user = $user;
  56. $this->storageId = $storageId;
  57. $this->rootId = $rootId;
  58. $this->mountPoint = $mountPoint;
  59. $this->mountId = $mountId;
  60. $this->rootInternalPath = $rootInternalPath;
  61. if (strlen($mountProvider) > 128) {
  62. throw new \Exception("Mount provider $mountProvider name exceeds the limit of 128 characters");
  63. }
  64. $this->mountProvider = $mountProvider;
  65. }
  66. /**
  67. * @return IUser
  68. */
  69. public function getUser(): IUser {
  70. return $this->user;
  71. }
  72. /**
  73. * @return int the numeric storage id of the mount
  74. */
  75. public function getStorageId(): int {
  76. return $this->storageId;
  77. }
  78. /**
  79. * @return int the fileid of the root of the mount
  80. */
  81. public function getRootId(): int {
  82. return $this->rootId;
  83. }
  84. /**
  85. * @return Node|null the root node of the mount
  86. */
  87. public function getMountPointNode(): ?Node {
  88. // TODO injection etc
  89. Filesystem::initMountPoints($this->getUser()->getUID());
  90. $userNode = \OC::$server->getUserFolder($this->getUser()->getUID());
  91. $nodes = $userNode->getParent()->getById($this->getRootId());
  92. if (count($nodes) > 0) {
  93. return $nodes[0];
  94. } else {
  95. return null;
  96. }
  97. }
  98. /**
  99. * @return string the mount point of the mount for the user
  100. */
  101. public function getMountPoint(): string {
  102. return $this->mountPoint;
  103. }
  104. /**
  105. * Get the id of the configured mount
  106. *
  107. * @return int|null mount id or null if not applicable
  108. * @since 9.1.0
  109. */
  110. public function getMountId(): ?int {
  111. return $this->mountId;
  112. }
  113. /**
  114. * Get the internal path (within the storage) of the root of the mount
  115. *
  116. * @return string
  117. */
  118. public function getRootInternalPath(): string {
  119. return $this->rootInternalPath;
  120. }
  121. public function getMountProvider(): string {
  122. return $this->mountProvider;
  123. }
  124. }