Skip to content

Commit

Permalink
Merge pull request #434 from nextcloud/filter-more-paths
Browse files Browse the repository at this point in the history
fix: filter more paths from being sent to the daemon
  • Loading branch information
icewind1991 authored Apr 29, 2024
2 parents 19864d7 + 7782082 commit 4c71d93
Showing 1 changed file with 33 additions and 17 deletions.
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;
}
}

0 comments on commit 4c71d93

Please sign in to comment.