From 43589312ccbdf977bb6d89eae3bec28bde2dceff Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 6 Feb 2023 18:16:23 +0100 Subject: [PATCH 1/4] dont delegate Mount\Manager::getByNumericId to getByStorageId Signed-off-by: Robin Appelman --- lib/private/Files/Mount/Manager.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/private/Files/Mount/Manager.php b/lib/private/Files/Mount/Manager.php index 9ba0e50405880..805cce658a678 100644 --- a/lib/private/Files/Mount/Manager.php +++ b/lib/private/Files/Mount/Manager.php @@ -184,8 +184,13 @@ public function getAll(): array { * @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; } /** From 9281359fa47b5b67d09b0661bdfb0dcee9795b54 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 6 Feb 2023 18:17:40 +0100 Subject: [PATCH 2/4] deduplicate getStorage() logic in Mount\Manager Signed-off-by: Robin Appelman --- lib/private/Files/Mount/MountPoint.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/lib/private/Files/Mount/MountPoint.php b/lib/private/Files/Mount/MountPoint.php index 49f7e560ad373..770655fae5061 100644 --- a/lib/private/Files/Mount/MountPoint.php +++ b/lib/private/Files/Mount/MountPoint.php @@ -199,15 +199,7 @@ public function getStorage() { */ 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; - } - $this->storageId = $this->storage->getId(); + $this->storageId = $this->getStorage()->getId(); if (strlen($this->storageId) > 64) { $this->storageId = md5($this->storageId); } From e3bafcc7a813f6adb305c2e35057b925c278d4bd Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 6 Feb 2023 18:20:08 +0100 Subject: [PATCH 3/4] cache numeric id in mountpoint Signed-off-by: Robin Appelman --- lib/private/Files/Mount/MountPoint.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/private/Files/Mount/MountPoint.php b/lib/private/Files/Mount/MountPoint.php index 770655fae5061..67601f016be7c 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; /** @@ -211,7 +212,10 @@ public function getStorageId() { * @return int */ public function getNumericStorageId() { - return $this->getStorage()->getStorageCache()->getNumericId(); + if (is_null($this->numericStorageId)) { + $this->numericStorageId = $this->getStorage()->getStorageCache()->getNumericId(); + } + return $this->numericStorageId; } /** From 9f3dbb699a4e1e0fbfc55e1fb9bb070e26816e20 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 6 Feb 2023 18:56:54 +0100 Subject: [PATCH 4/4] fix tests Signed-off-by: Robin Appelman --- lib/private/Files/Mount/MountPoint.php | 14 +++++++++++--- lib/public/Files/Mount/IMountPoint.php | 4 ++-- tests/lib/Files/ViewTest.php | 3 +++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/private/Files/Mount/MountPoint.php b/lib/private/Files/Mount/MountPoint.php index 67601f016be7c..20e081200805a 100644 --- a/lib/private/Files/Mount/MountPoint.php +++ b/lib/private/Files/Mount/MountPoint.php @@ -196,11 +196,15 @@ public function getStorage() { } /** - * @return string + * @return string|null */ public function getStorageId() { if (!$this->storageId) { - $this->storageId = $this->getStorage()->getId(); + $storage = $this->getStorage(); + if (is_null($storage)) { + return null; + } + $this->storageId = $storage->getId(); if (strlen($this->storageId) > 64) { $this->storageId = md5($this->storageId); } @@ -213,7 +217,11 @@ public function getStorageId() { */ public function getNumericStorageId() { if (is_null($this->numericStorageId)) { - $this->numericStorageId = $this->getStorage()->getStorageCache()->getNumericId(); + $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 b8e7ec9118f20..1272550d73779 100644 --- a/lib/public/Files/Mount/IMountPoint.php +++ b/lib/public/Files/Mount/IMountPoint.php @@ -55,7 +55,7 @@ public function getStorage(); /** * Get the id of the storages * - * @return string + * @return string|null * @since 8.0.0 */ public function getStorageId(); @@ -63,7 +63,7 @@ public function getStorageId(); /** * 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 2189e7c09f431..95d9a8e3051eb 100644 --- a/tests/lib/Files/ViewTest.php +++ b/tests/lib/Files/ViewTest.php @@ -1590,6 +1590,9 @@ private function createTestMovableMountPoints($mountPoints) { ->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'])