1
0

LazyStorageMountInfo.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Robin Appelman <robin@icewind.nl>
  6. *
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OC\Files\Config;
  23. use OCP\Files\Mount\IMountPoint;
  24. use OCP\IUser;
  25. class LazyStorageMountInfo extends CachedMountInfo {
  26. private IMountPoint $mount;
  27. /**
  28. * CachedMountInfo constructor.
  29. *
  30. * @param IUser $user
  31. * @param IMountPoint $mount
  32. */
  33. public function __construct(IUser $user, IMountPoint $mount) {
  34. $this->user = $user;
  35. $this->mount = $mount;
  36. $this->rootId = 0;
  37. $this->storageId = 0;
  38. $this->mountPoint = '';
  39. $this->key = '';
  40. }
  41. /**
  42. * @return int the numeric storage id of the mount
  43. */
  44. public function getStorageId(): int {
  45. if (!$this->storageId) {
  46. $this->storageId = $this->mount->getNumericStorageId();
  47. }
  48. return parent::getStorageId();
  49. }
  50. /**
  51. * @return int the fileid of the root of the mount
  52. */
  53. public function getRootId(): int {
  54. if (!$this->rootId) {
  55. $this->rootId = $this->mount->getStorageRootId();
  56. }
  57. return parent::getRootId();
  58. }
  59. /**
  60. * @return string the mount point of the mount for the user
  61. */
  62. public function getMountPoint(): string {
  63. if (!$this->mountPoint) {
  64. $this->mountPoint = $this->mount->getMountPoint();
  65. }
  66. return parent::getMountPoint();
  67. }
  68. public function getMountId(): ?int {
  69. return $this->mount->getMountId();
  70. }
  71. /**
  72. * Get the internal path (within the storage) of the root of the mount
  73. *
  74. * @return string
  75. */
  76. public function getRootInternalPath(): string {
  77. return $this->mount->getInternalPath($this->mount->getMountPoint());
  78. }
  79. public function getMountProvider(): string {
  80. return $this->mount->getMountProvider();
  81. }
  82. public function getKey(): string {
  83. if (!$this->key) {
  84. $this->key = $this->getRootId() . '::' . $this->getMountPoint();
  85. }
  86. return $this->key;
  87. }
  88. }