aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Petry <vincent@nextcloud.com>2022-04-25 15:50:31 +0200
committerGitHub <noreply@github.com>2022-04-25 15:50:31 +0200
commit407fb8c22bb286c4e84e2e9ec5f178bc4bc52013 (patch)
tree362f45eafe3cfe94b3ac92953af63a54c131321e
parent7872fb05a56e1a04607f767b74f6e2e21a799024 (diff)
parent6b6f24cafd55b6c5d50ef9708d08b70b8053101d (diff)
downloadnextcloud-server-407fb8c22bb286c4e84e2e9ec5f178bc4bc52013.tar.gz
nextcloud-server-407fb8c22bb286c4e84e2e9ec5f178bc4bc52013.zip
Merge pull request #32033 from nextcloud/fix/metadata-scan-app-data
Fix scanning app data with metadata
-rw-r--r--lib/private/Metadata/FileEventListener.php23
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());