From 3b4efc74f0a0755466c41cf594c9cffc8531607a Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Thu, 21 Apr 2022 09:57:30 +0200 Subject: [PATCH] Fix scanning app data with metadata Previously we were listening to change in the appdata folder but an appdata scan didn't setup the file system, so the view was unavailable. **Test plan:** 1. rm -rf data/appdata_...../preview data//Media 2. occ files:scan-app-data 3. occ files:scan No errors and the files and metadata are correctly removed from the database too. Signed-off-by: Carl Schwan --- lib/private/Metadata/FileEventListener.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/private/Metadata/FileEventListener.php b/lib/private/Metadata/FileEventListener.php index fdec891c6e26b..dfec6c2db092a 100644 --- a/lib/private/Metadata/FileEventListener.php +++ b/lib/private/Metadata/FileEventListener.php @@ -52,13 +52,26 @@ private function shouldExtractMetadata(Node $node): bool { } $path = $node->getPath(); + return $this->isCorrectPath($path); + } + + private function isCorrectPath(string $path): bool { // TODO make this more dynamic, we have the same issue in other places return !str_starts_with($path, 'appdata_') && !str_starts_with($path, 'files_versions/') && !str_starts_with($path, 'files_trashbin/'); } public function handle(Event $event): void { if ($event instanceof NodeRemovedFromCache) { + if (!$this->isCorrectPath($event->getPath())) { + // Don't listen to paths for which we don't extract metadata + return; + } $view = Filesystem::getView(); + if (!$view) { + // Should not happen since a scan in the user folder should setup + // the file system. + return; + } $info = $view->getFileInfo($event->getPath()); if ($info && $info->getType() === FileInfo::TYPE_FILE) { $this->manager->clearMetadata($info->getId());