From 197a9073d725560e7886060e2f5e60a25c94ec6d Mon Sep 17 00:00:00 2001 From: Git'Fellow <12234510+solracsf@users.noreply.github.com> Date: Wed, 23 Sep 2026 15:40:39 +0200 Subject: [PATCH] fix(files): keep deleting live photo peers after a missing one handleCacheEntriesRemovedEvent() returned from the loop as soon as one peer could not be found, so every remaining peer in the same batch was left behind. This happens whenever both halves of a live photo are in the removed tree, since the first half is already gone when its peer id is looked up. Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> --- .../lib/Listener/SyncLivePhotosListener.php | 2 +- .../Listener/SyncLivePhotosListenerTest.php | 66 +++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 apps/files/tests/Listener/SyncLivePhotosListenerTest.php diff --git a/apps/files/lib/Listener/SyncLivePhotosListener.php b/apps/files/lib/Listener/SyncLivePhotosListener.php index 62a8725bc16e2..5f84cc3b21334 100644 --- a/apps/files/lib/Listener/SyncLivePhotosListener.php +++ b/apps/files/lib/Listener/SyncLivePhotosListener.php @@ -102,7 +102,7 @@ public function handleCacheEntriesRemovedEvent(CacheEntriesRemovedEvent $cacheEn $peerFile = $this->userFolder->getFirstNodeById($peerFileId); if ($peerFile === null) { - return; // Peer file not found. + continue; // Peer file not found. } $peerFile->delete(); } diff --git a/apps/files/tests/Listener/SyncLivePhotosListenerTest.php b/apps/files/tests/Listener/SyncLivePhotosListenerTest.php new file mode 100644 index 0000000000000..b57ec6cd9a512 --- /dev/null +++ b/apps/files/tests/Listener/SyncLivePhotosListenerTest.php @@ -0,0 +1,66 @@ +userFolder = $this->createMock(Folder::class); + $this->livePhotosService = $this->createMock(LivePhotosService::class); + + $this->listener = new SyncLivePhotosListener( + $this->userFolder, + $this->createMock(IFilesMetadataManager::class), + $this->livePhotosService, + $this->createMock(IRootFolder::class), + $this->createMock(View::class), + ); + } + + public function testCacheEntriesRemovedDeletesPeersAfterMissingOne(): void { + $entries = array_map(function (int $fileId): ICacheEvent { + $entry = $this->createMock(ICacheEvent::class); + $entry->method('getFileId')->willReturn($fileId); + return $entry; + }, [1, 2]); + + $this->livePhotosService->method('getLivePhotoPeerIds') + ->with([1, 2]) + ->willReturn([11, 12]); + + $peer = $this->createMock(File::class); + $peer->expects($this->once())->method('delete'); + + $this->userFolder->method('getFirstNodeById') + ->willReturnMap([ + [11, null], + [12, $peer], + ]); + + $this->listener->handle(new CacheEntriesRemovedEvent($entries)); + } +}