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: filter more paths from being sent to the daemon #434

Merged
merged 1 commit into from
Apr 29, 2024
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
50 changes: 33 additions & 17 deletions lib/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use OCP\EventDispatcher\Event;
use OCP\Files\Cache\ICacheEvent;
use OCP\Files\IHomeStorage;
use OCP\Files\Storage\IStorage;
use OCP\Group\Events\UserAddedEvent;
use OCP\Group\Events\UserRemovedEvent;
use OCP\Notification\IApp;
Expand All @@ -48,18 +49,6 @@ public function __construct(IQueue $queue) {

public function cacheListener(Event $event): void {
if ($event instanceof ICacheEvent) {
// ignore files in home storage but outside home directory (trashbin, versions, etc)
if (
$event->getStorage()->instanceOfStorage(IHomeStorage::class) && !(
$event->getPath() === 'files' || strpos($event->getPath(), "files/") === 0
)
) {
return;
}
// ignore appdata
if (strpos($event->getPath(), 'appdata_') === 0) {
return;
}
$path = $event->getPath();

$storage = $event->getStorage();
Expand All @@ -69,11 +58,13 @@ public function cacheListener(Event $event): void {
$storage = $storage->getUnjailedStorage();
}

$this->queue->push('notify_storage_update', [
'storage' => $event->getStorageId(),
'path' => $path,
'file_id' => $event->getFileId(),
]);
if ($this->shouldNotifyPath($event->getStorage(), $path)) {
$this->queue->push('notify_storage_update', [
'storage' => $event->getStorageId(),
'path' => $path,
'file_id' => $event->getFileId(),
]);
}
}
}

Expand Down Expand Up @@ -134,4 +125,29 @@ public function dismissNotification(INotification $notification): void {
'user' => $notification->getUser(),
]);
}

private function shouldNotifyPath(IStorage $storage, string $path): bool {
// ignore files in home storage but outside home directory (trashbin, versions, etc)
if (
$storage->instanceOfStorage(IHomeStorage::class)) {
return $path === 'files' || str_starts_with($path, "files/");
}

// ignore appdata
if (str_starts_with($path, 'appdata_')) {
return false;
}

if ($path === '__groupfolders') {
return false;
}
if (str_starts_with($path, '__groupfolders/versions')) {
return false;
}
if (str_starts_with($path, '__groupfolders/trash')) {
return false;
}

return true;
}
}
Loading