CachedMountInfo.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\Files\Config;
  8. use OC\Files\Filesystem;
  9. use OCP\Files\Config\ICachedMountInfo;
  10. use OCP\Files\Node;
  11. use OCP\IUser;
  12. class CachedMountInfo implements ICachedMountInfo {
  13. protected IUser $user;
  14. protected int $storageId;
  15. protected int $rootId;
  16. protected string $mountPoint;
  17. protected ?int $mountId;
  18. protected string $rootInternalPath;
  19. protected string $mountProvider;
  20. protected string $key;
  21. /**
  22. * CachedMountInfo constructor.
  23. *
  24. * @param IUser $user
  25. * @param int $storageId
  26. * @param int $rootId
  27. * @param string $mountPoint
  28. * @param int|null $mountId
  29. * @param string $rootInternalPath
  30. */
  31. public function __construct(
  32. IUser $user,
  33. int $storageId,
  34. int $rootId,
  35. string $mountPoint,
  36. string $mountProvider,
  37. ?int $mountId = null,
  38. string $rootInternalPath = ''
  39. ) {
  40. $this->user = $user;
  41. $this->storageId = $storageId;
  42. $this->rootId = $rootId;
  43. $this->mountPoint = $mountPoint;
  44. $this->mountId = $mountId;
  45. $this->rootInternalPath = $rootInternalPath;
  46. if (strlen($mountProvider) > 128) {
  47. throw new \Exception("Mount provider $mountProvider name exceeds the limit of 128 characters");
  48. }
  49. $this->mountProvider = $mountProvider;
  50. $this->key = $rootId . '::' . $mountPoint;
  51. }
  52. /**
  53. * @return IUser
  54. */
  55. public function getUser(): IUser {
  56. return $this->user;
  57. }
  58. /**
  59. * @return int the numeric storage id of the mount
  60. */
  61. public function getStorageId(): int {
  62. return $this->storageId;
  63. }
  64. /**
  65. * @return int the fileid of the root of the mount
  66. */
  67. public function getRootId(): int {
  68. return $this->rootId;
  69. }
  70. /**
  71. * @return Node|null the root node of the mount
  72. */
  73. public function getMountPointNode(): ?Node {
  74. // TODO injection etc
  75. Filesystem::initMountPoints($this->getUser()->getUID());
  76. $userNode = \OC::$server->getUserFolder($this->getUser()->getUID());
  77. return $userNode->getParent()->getFirstNodeById($this->getRootId());
  78. }
  79. /**
  80. * @return string the mount point of the mount for the user
  81. */
  82. public function getMountPoint(): string {
  83. return $this->mountPoint;
  84. }
  85. /**
  86. * Get the id of the configured mount
  87. *
  88. * @return int|null mount id or null if not applicable
  89. * @since 9.1.0
  90. */
  91. public function getMountId(): ?int {
  92. return $this->mountId;
  93. }
  94. /**
  95. * Get the internal path (within the storage) of the root of the mount
  96. *
  97. * @return string
  98. */
  99. public function getRootInternalPath(): string {
  100. return $this->rootInternalPath;
  101. }
  102. public function getMountProvider(): string {
  103. return $this->mountProvider;
  104. }
  105. public function getKey(): string {
  106. return $this->key;
  107. }
  108. }