Skip to content

Commit 1524b5f

Browse files
authored
Merge pull request #34797 from nextcloud/backport/33540/stable24
[stable24] fix updating cached mounts that didn't have their mount provider set previously
2 parents aad2525 + 82b915e commit 1524b5f

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

lib/private/Files/Config/UserMountCache.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,12 @@ public function registerMounts(IUser $user, array $mounts, array $mountProviderC
104104

105105
$cachedMounts = $this->getMountsForUser($user);
106106
if (is_array($mountProviderClasses)) {
107-
$cachedMounts = array_filter($cachedMounts, function (ICachedMountInfo $mountInfo) use ($mountProviderClasses) {
107+
$cachedMounts = array_filter($cachedMounts, function (ICachedMountInfo $mountInfo) use ($mountProviderClasses, $newMounts) {
108+
// for existing mounts that didn't have a mount provider set
109+
// we still want the ones that map to new mounts
110+
if ($mountInfo->getMountProvider() === '' && isset($newMounts[$mountInfo->getRootId()])) {
111+
return true;
112+
}
108113
return in_array($mountInfo->getMountProvider(), $mountProviderClasses);
109114
});
110115
}

tests/lib/Files/Config/UserMountCacheTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,4 +506,29 @@ public function testGetUsedSpaceForUsers() {
506506
$result = $this->cache->getUsedSpaceForUsers([$user1, $user2]);
507507
$this->assertEquals(['u1' => 100], $result);
508508
}
509+
510+
511+
public function testMigrateMountProvider() {
512+
$user1 = $this->userManager->get('u1');
513+
514+
[$storage1, $rootId] = $this->getStorage(2);
515+
$rootId = $this->createCacheEntry('', 2);
516+
$mount1 = new MountPoint($storage1, '/foo/');
517+
$this->cache->registerMounts($user1, [$mount1]);
518+
519+
$this->clearCache();
520+
521+
$cachedMounts = $this->cache->getMountsForUser($user1);
522+
$this->assertCount(1, $cachedMounts);
523+
$this->assertEquals('', $cachedMounts[0]->getMountProvider());
524+
525+
$mount1 = new MountPoint($storage1, '/foo/', null, null, null, null, 'dummy');
526+
$this->cache->registerMounts($user1, [$mount1], ['dummy']);
527+
528+
$this->clearCache();
529+
530+
$cachedMounts = $this->cache->getMountsForUser($user1);
531+
$this->assertCount(1, $cachedMounts);
532+
$this->assertEquals('dummy', $cachedMounts[0]->getMountProvider());
533+
}
509534
}

0 commit comments

Comments
 (0)