diff options
author | Julius Härtl <jus@bitgrid.net> | 2023-02-08 20:04:57 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-08 20:04:57 +0100 |
commit | 08802ad13f2485f5b8c24dbfe295ce3ad15836c6 (patch) | |
tree | efe6913349b03455de61229f80c467c0288e778b | |
parent | 7341d339eb7a1aa20c6b35e8edb40c1cd7946b96 (diff) | |
parent | 9f3dbb699a4e1e0fbfc55e1fb9bb070e26816e20 (diff) | |
download | nextcloud-server-08802ad13f2485f5b8c24dbfe295ce3ad15836c6.tar.gz nextcloud-server-08802ad13f2485f5b8c24dbfe295ce3ad15836c6.zip |
Merge pull request #36566 from nextcloud/mount-find-by-numeric-id
-rw-r--r-- | lib/private/Files/Mount/Manager.php | 9 | ||||
-rw-r--r-- | lib/private/Files/Mount/MountPoint.php | 24 | ||||
-rw-r--r-- | lib/public/Files/Mount/IMountPoint.php | 4 | ||||
-rw-r--r-- | tests/lib/Files/ViewTest.php | 3 |
4 files changed, 26 insertions, 14 deletions
diff --git a/lib/private/Files/Mount/Manager.php b/lib/private/Files/Mount/Manager.php index 9ba0e504058..805cce658a6 100644 --- a/lib/private/Files/Mount/Manager.php +++ b/lib/private/Files/Mount/Manager.php @@ -184,8 +184,13 @@ class Manager implements IMountManager { * @return IMountPoint[] */ public function findByNumericId(int $id): array { - $storageId = \OC\Files\Cache\Storage::getStorageId($id); - return $this->findByStorageId($storageId); + $result = []; + foreach ($this->mounts as $mount) { + if ($mount->getNumericStorageId() === $id) { + $result[] = $mount; + } + } + return $result; } /** diff --git a/lib/private/Files/Mount/MountPoint.php b/lib/private/Files/Mount/MountPoint.php index 49f7e560ad3..20e08120080 100644 --- a/lib/private/Files/Mount/MountPoint.php +++ b/lib/private/Files/Mount/MountPoint.php @@ -44,6 +44,7 @@ class MountPoint implements IMountPoint { protected $storage = null; protected $class; protected $storageId; + protected $numericStorageId = null; protected $rootId = null; /** @@ -195,19 +196,15 @@ class MountPoint implements IMountPoint { } /** - * @return string + * @return string|null */ public function getStorageId() { if (!$this->storageId) { - if (is_null($this->storage)) { - $storage = $this->createStorage(); //FIXME: start using exceptions - if (is_null($storage)) { - return null; - } - - $this->storage = $storage; + $storage = $this->getStorage(); + if (is_null($storage)) { + return null; } - $this->storageId = $this->storage->getId(); + $this->storageId = $storage->getId(); if (strlen($this->storageId) > 64) { $this->storageId = md5($this->storageId); } @@ -219,7 +216,14 @@ class MountPoint implements IMountPoint { * @return int */ public function getNumericStorageId() { - return $this->getStorage()->getStorageCache()->getNumericId(); + if (is_null($this->numericStorageId)) { + $storage = $this->getStorage(); + if (is_null($storage)) { + return -1; + } + $this->numericStorageId = $storage->getStorageCache()->getNumericId(); + } + return $this->numericStorageId; } /** diff --git a/lib/public/Files/Mount/IMountPoint.php b/lib/public/Files/Mount/IMountPoint.php index b8e7ec9118f..1272550d737 100644 --- a/lib/public/Files/Mount/IMountPoint.php +++ b/lib/public/Files/Mount/IMountPoint.php @@ -55,7 +55,7 @@ interface IMountPoint { /** * Get the id of the storages * - * @return string + * @return string|null * @since 8.0.0 */ public function getStorageId(); @@ -63,7 +63,7 @@ interface IMountPoint { /** * Get the id of the storages * - * @return int + * @return int|null * @since 9.1.0 */ public function getNumericStorageId(); diff --git a/tests/lib/Files/ViewTest.php b/tests/lib/Files/ViewTest.php index f2195810bb7..7a449c4893b 100644 --- a/tests/lib/Files/ViewTest.php +++ b/tests/lib/Files/ViewTest.php @@ -1590,6 +1590,9 @@ class ViewTest extends \Test\TestCase { ->setConstructorArgs([[]]) ->getMock(); $storage->method('getId')->willReturn('non-null-id'); + $storage->method('getStorageCache')->willReturnCallback(function () use ($storage) { + return new \OC\Files\Cache\Storage($storage); + }); $mounts[] = $this->getMockBuilder(TestMoveableMountPoint::class) ->setMethods(['moveMount']) |