Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scanning app data with metadata #32033

Merged
merged 1 commit into from
Apr 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion lib/private/Metadata/FileEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@
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 {
Expand All @@ -52,13 +55,31 @@ 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.
$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());
Expand Down