From 93f064d97433b138f1af5ed322e68bc411d80264 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 19 May 2025 17:33:17 +0200 Subject: [PATCH] fix(files_versions): Log error instead of crashing when event listeners get called on non-existing files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- .../lib/Listener/FileEventsListener.php | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/apps/files_versions/lib/Listener/FileEventsListener.php b/apps/files_versions/lib/Listener/FileEventsListener.php index fd77706753747..d5c60dd93434d 100644 --- a/apps/files_versions/lib/Listener/FileEventsListener.php +++ b/apps/files_versions/lib/Listener/FileEventsListener.php @@ -125,6 +125,22 @@ public function pre_touch_hook(Node $node): void { } public function touch_hook(Node $node): void { + // Do not handle folders. + if ($node instanceof Folder) { + return; + } + + if ($node instanceof NonExistingFile) { + $this->logger->error( + 'Failed to create or update version for {path}, node does not exist', + [ + 'path' => $node->getPath(), + ] + ); + + return; + } + $previousNode = $this->nodesTouched[$node->getId()] ?? null; if ($previousNode === null) { @@ -152,7 +168,22 @@ public function touch_hook(Node $node): void { public function created(Node $node): void { // Do not handle folders. - if ($node instanceof File && $this->versionManager instanceof INeedSyncVersionBackend) { + if (!($node instanceof File)) { + return; + } + + if ($node instanceof NonExistingFile) { + $this->logger->error( + 'Failed to create version for {path}, node does not exist', + [ + 'path' => $node->getPath(), + ] + ); + + return; + } + + if ($this->versionManager instanceof INeedSyncVersionBackend) { $this->versionManager->createVersionEntity($node); } } @@ -190,6 +221,17 @@ public function post_write_hook(Node $node): void { return; } + if ($node instanceof NonExistingFile) { + $this->logger->error( + 'Failed to create or update version for {path}, node does not exist', + [ + 'path' => $node->getPath(), + ] + ); + + return; + } + $writeHookInfo = $this->writeHookInfo[$node->getId()] ?? null; if ($writeHookInfo === null) {