diff --git a/apps/files_sharing/lib/Repair/CleanupShareTarget.php b/apps/files_sharing/lib/Repair/CleanupShareTarget.php index 340cc8840f04a..872fbb70930b0 100644 --- a/apps/files_sharing/lib/Repair/CleanupShareTarget.php +++ b/apps/files_sharing/lib/Repair/CleanupShareTarget.php @@ -118,16 +118,18 @@ public function run(IOutput $output) { $oldMountPoint = "/{$recipient->getUID()}/files$oldTarget/"; $newMountPoint = "/{$recipient->getUID()}/files$newTarget/"; - /** @var ICachedMountInfo $mount */ - $mount = $userMounts[$oldMountPoint]; - $userMounts[$newMountPoint] = $mount; - unset($userMounts[$oldMountPoint]); - - $this->userMountCache->removeMount($oldMountPoint); - $this->userMountCache->addMount($recipient, $newMountPoint, new CacheEntry([ - 'fileid' => $mount->getRootId(), - 'storage' => $mount->getStorageId(), - ]), $mount->getMountProvider(), $mount->getMountId()); + /** @var ICachedMountInfo|null $mount */ + $mount = $userMounts[$oldMountPoint] ?? null; + if ($mount !== null) { + $userMounts[$newMountPoint] = $mount; + unset($userMounts[$oldMountPoint]); + + $this->userMountCache->removeMount($oldMountPoint); + $this->userMountCache->addMount($recipient, $newMountPoint, new CacheEntry([ + 'fileid' => $mount->getRootId(), + 'storage' => $mount->getStorageId(), + ]), $mount->getMountProvider(), $mount->getMountId()); + } } } catch (\Exception $e) { $msg = 'error cleaning up share target: ' . $e->getMessage(); diff --git a/apps/files_sharing/tests/Repair/CleanupShareTargetTest.php b/apps/files_sharing/tests/Repair/CleanupShareTargetTest.php index e781a8ec72ef2..ffc095196d36a 100644 --- a/apps/files_sharing/tests/Repair/CleanupShareTargetTest.php +++ b/apps/files_sharing/tests/Repair/CleanupShareTargetTest.php @@ -10,6 +10,7 @@ use OC\Migration\NullOutput; use OCA\Files_Sharing\Repair\CleanupShareTarget; use OCA\Files_Sharing\Tests\TestCase; +use OCP\Files\Config\IUserMountCache; use OCP\Files\NotFoundException; use OCP\Server; use OCP\Share\IShare; @@ -66,6 +67,17 @@ public function testBasicRepair() { $this->assertEquals(self::TEST_FOLDER_NAME, $share->getTarget()); } + public function testRepairWithoutCachedMount() { + $share = $this->createUserShare(self::TEST_FILES_SHARING_API_USER1, self::TEST_FOLDER_NAME . ' (2) (2) (2) (2)'); + $mountPoint = '/' . self::TEST_FILES_SHARING_API_USER2 . '/files' . $share->getTarget() . '/'; + Server::get(IUserMountCache::class)->removeMount($mountPoint); + + $this->cleanupShareTarget->run(new NullOutput()); + + $share = $this->shareManager->getShareById($share->getFullId()); + $this->assertEquals(self::TEST_FOLDER_NAME, $share->getTarget()); + } + public function testRepairConflictFile() { $share = $this->createUserShare(self::TEST_FILES_SHARING_API_USER1, self::TEST_FOLDER_NAME . ' (2) (2) (2) (2)');