aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Metadata
diff options
context:
space:
mode:
authorCarl Schwan <carl@carlschwan.eu>2022-04-21 09:57:30 +0200
committerCarl Schwan <carl@carlschwan.eu>2022-04-22 15:14:59 +0200
commit6b6f24cafd55b6c5d50ef9708d08b70b8053101d (patch)
treee9da7e143fa4241a67e20ea8691703369cd96fb5 /lib/private/Metadata
parent12ed5c9ff3e9dac25b43a1ad934a97a86037000b (diff)
downloadnextcloud-server-6b6f24cafd55b6c5d50ef9708d08b70b8053101d.tar.gz
nextcloud-server-6b6f24cafd55b6c5d50ef9708d08b70b8053101d.zip
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/<user>/Media 2. occ files:scan-app-data 3. occ files:scan <user> No errors and the files and metadata are correctly removed from the database too. Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'lib/private/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());