Skip to content

Commit 69cf41c

Browse files
Merge pull request #58733 from nextcloud/backport/58727/stable33
2 parents dc1e8d5 + 27e63dd commit 69cf41c

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

lib/private/Files/Config/UserMountCache.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,15 @@ private function addToCache(ICachedMountInfo $mount) {
194194

195195
private function updateCachedMount(ICachedMountInfo $mount) {
196196
$builder = $this->connection->getQueryBuilder();
197+
$hash = hash('xxh128', $mount->getMountPoint());
197198

198199
$query = $builder->update('mounts')
199200
->set('storage_id', $builder->createNamedParameter($mount->getStorageId()))
200-
->set('mount_point', $builder->createNamedParameter($mount->getMountPoint()))
201-
->set('mount_point_hash', $builder->createNamedParameter(hash('xxh128', $mount->getMountPoint())))
202201
->set('mount_id', $builder->createNamedParameter($mount->getMountId(), IQueryBuilder::PARAM_INT))
203202
->set('mount_provider_class', $builder->createNamedParameter($mount->getMountProvider()))
204203
->where($builder->expr()->eq('user_id', $builder->createNamedParameter($mount->getUser()->getUID())))
205-
->andWhere($builder->expr()->eq('root_id', $builder->createNamedParameter($mount->getRootId(), IQueryBuilder::PARAM_INT)));
204+
->andWhere($builder->expr()->eq('root_id', $builder->createNamedParameter($mount->getRootId(), IQueryBuilder::PARAM_INT)))
205+
->andWhere($builder->expr()->eq('mount_point_hash', $builder->createNamedParameter($hash)));
206206

207207
$query->executeStatement();
208208
}

tests/lib/Files/Config/UserMountCacheTest.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public function testRemoveMounts(): void {
184184
->expects($this->exactly(2))
185185
->method('dispatchTyped')
186186
->with($this->callback(function (UserMountAddedEvent|UserMountRemovedEvent $event) use (&$operation) {
187-
return match(++$operation) {
187+
return match (++$operation) {
188188
1 => $event instanceof UserMountAddedEvent && $event->mountPoint->getMountPoint() === '/asd/',
189189
2 => $event instanceof UserMountRemovedEvent && $event->mountPoint->getMountPoint() === '/asd/',
190190
default => false,
@@ -215,7 +215,7 @@ public function testChangeMounts(): void {
215215
->expects($this->exactly(3))
216216
->method('dispatchTyped')
217217
->with($this->callback(function (UserMountAddedEvent|UserMountRemovedEvent $event) use (&$operation) {
218-
return match(++$operation) {
218+
return match (++$operation) {
219219
1 => $event instanceof UserMountAddedEvent && $event->mountPoint->getMountPoint() === '/bar/',
220220
2 => $event instanceof UserMountAddedEvent && $event->mountPoint->getMountPoint() === '/foo/',
221221
3 => $event instanceof UserMountRemovedEvent && $event->mountPoint->getMountPoint() === '/bar/',
@@ -251,7 +251,7 @@ public function testChangeMountId(): void {
251251
->expects($this->exactly(2))
252252
->method('dispatchTyped')
253253
->with($this->callback(function (UserMountAddedEvent|UserMountUpdatedEvent $event) use (&$operation) {
254-
return match(++$operation) {
254+
return match (++$operation) {
255255
1 => $event instanceof UserMountAddedEvent && $event->mountPoint->getMountPoint() === '/foo/',
256256
2 => $event instanceof UserMountUpdatedEvent && $event->oldMountPoint->getMountId() === null && $event->newMountPoint->getMountId() === 1,
257257
default => false,
@@ -596,4 +596,26 @@ public function testMigrateMountProvider(): void {
596596
$this->assertCount(1, $cachedMounts);
597597
$this->assertEquals('dummy', $cachedMounts[$this->keyForMount($mount1)]->getMountProvider());
598598
}
599+
600+
public function testChangedSameRootId(): void {
601+
$user = $this->userManager->get('u1');
602+
603+
[$storage] = $this->getStorage(10);
604+
$mount1 = new MountPoint($storage, '/asd/');
605+
$mount2 = new MountPoint($storage, '/asd2/');
606+
607+
$this->cache->registerMounts($user, [$mount1, $mount2]);
608+
609+
$mount2 = new MountPoint($storage, '/asd2/', null, null, null, 1);
610+
$this->cache->registerMounts($user, [$mount1, $mount2]);
611+
612+
$cached = $this->cache->getMountsForUser($user);
613+
usort($cached, fn (ICachedMountInfo $a, ICachedMountInfo $b) => $a->getMountPoint() <=> $b->getMountPoint());
614+
615+
$mountPoints = array_map(fn (ICachedMountInfo $mountInfo) => $mountInfo->getMountPoint(), $cached);
616+
$this->assertEquals(['/asd/', '/asd2/'], $mountPoints);
617+
618+
$mountIds = array_map(fn (ICachedMountInfo $mountInfo) => $mountInfo->getMountId(), $cached);
619+
$this->assertEquals([null, 1], $mountIds);
620+
}
599621
}

0 commit comments

Comments
 (0)