diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-04-25 19:56:52 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-25 19:56:52 +0300 |
commit | 1bb4d7853fee221ae934c0829ad4e070999cf852 (patch) | |
tree | 0e03cc785db34405d05bf659737c4055d7a7f9de | |
parent | af4258436ba9599dd8e41e00679605f6e58038c9 (diff) | |
parent | 953c8875dba06e4ef640bc5580c074e76aee6242 (diff) |
Merge pull request #32134 from nextcloud/backport/32033/stable24
[stable24] Fix scanning app data with metadata
-rw-r--r-- | lib/private/Metadata/FileEventListener.php | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/lib/private/Metadata/FileEventListener.php b/lib/private/Metadata/FileEventListener.php index fdec891c6e2..6d41ccdef30 100644 --- a/lib/private/Metadata/FileEventListener.php +++ b/lib/private/Metadata/FileEventListener.php @@ -31,12 +31,15 @@ use OCP\Files\File; use OCP\Files\Node; use OCP\Files\NotFoundException; use OCP\Files\FileInfo; +use Psr\Log\LoggerInterface; class FileEventListener implements IEventListener { private IMetadataManager $manager; + private LoggerInterface $logger; - public function __construct(IMetadataManager $manager) { + public function __construct(IMetadataManager $manager, LoggerInterface $logger) { $this->manager = $manager; + $this->logger = $logger; } private function shouldExtractMetadata(Node $node): bool { @@ -52,13 +55,31 @@ class FileEventListener implements IEventListener { } $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. + $e = new \Exception(); // don't trigger, just get backtrace + $this->logger->error('Detecting deletion of a file with possible metadata but file system setup is not setup', [ + 'exception' => $e, + 'app' => 'metadata' + ]); + return; + } $info = $view->getFileInfo($event->getPath()); if ($info && $info->getType() === FileInfo::TYPE_FILE) { $this->manager->clearMetadata($info->getId()); |