From 5c625b7a073eb51d43241d7b3bfd97caa3bff839 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 25 Apr 2025 20:23:28 +0200 Subject: [PATCH] feat: add an option to filter what paths get checked for updates Signed-off-by: Robin Appelman --- lib/private/Files/Cache/Watcher.php | 12 ++++++++++++ lib/private/Files/Storage/Common.php | 1 + lib/public/Files/Cache/IWatcher.php | 11 +++++++++++ 3 files changed, 24 insertions(+) diff --git a/lib/private/Files/Cache/Watcher.php b/lib/private/Files/Cache/Watcher.php index dfab51be38b..a1d4e787d74 100644 --- a/lib/private/Files/Cache/Watcher.php +++ b/lib/private/Files/Cache/Watcher.php @@ -36,6 +36,8 @@ class Watcher implements IWatcher { /** @var callable[] */ protected $onUpdate = []; + protected ?string $checkFilter = null; + /** * @param \OC\Files\Storage\Storage $storage */ @@ -52,6 +54,10 @@ class Watcher implements IWatcher { $this->watchPolicy = $policy; } + public function setCheckFilter(?string $filter): void { + $this->checkFilter = $filter; + } + /** * @return int either \OC\Files\Cache\Watcher::CHECK_NEVER, \OC\Files\Cache\Watcher::CHECK_ONCE, \OC\Files\Cache\Watcher::CHECK_ALWAYS */ @@ -116,6 +122,12 @@ class Watcher implements IWatcher { * @return bool */ public function needsUpdate($path, $cachedData) { + if ($this->checkFilter !== null) { + if (!preg_match($this->checkFilter, $path)) { + return false; + } + } + if ($this->watchPolicy === self::CHECK_ALWAYS || ($this->watchPolicy === self::CHECK_ONCE && !in_array($path, $this->checkedPaths))) { $this->checkedPaths[] = $path; return $cachedData['storage_mtime'] === null || $this->storage->hasUpdated($path, $cachedData['storage_mtime']); diff --git a/lib/private/Files/Storage/Common.php b/lib/private/Files/Storage/Common.php index 1a2aeb0e021..bea7430bd1e 100644 --- a/lib/private/Files/Storage/Common.php +++ b/lib/private/Files/Storage/Common.php @@ -331,6 +331,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, $this->watcher = new Watcher($storage); $globalPolicy = Server::get(IConfig::class)->getSystemValueInt('filesystem_check_changes', Watcher::CHECK_NEVER); $this->watcher->setPolicy((int)$this->getMountOption('filesystem_check_changes', $globalPolicy)); + $this->watcher->setCheckFilter($this->getMountOption('filesystem_check_filter')); } return $this->watcher; } diff --git a/lib/public/Files/Cache/IWatcher.php b/lib/public/Files/Cache/IWatcher.php index 62b90f672c6..55063eec817 100644 --- a/lib/public/Files/Cache/IWatcher.php +++ b/lib/public/Files/Cache/IWatcher.php @@ -34,6 +34,17 @@ interface IWatcher { */ public function setPolicy($policy); + /** + * Set a filter regex, only paths matching the regex will be checked for updates. + * + * When set to `null`, every path will be checked for updates + * + * @param ?string $filter + * @return void + * @since 33.0.0 + */ + public function setCheckFilter(?string $filter): void; + /** * @return int either IWatcher::CHECK_NEVER, IWatcher::CHECK_ONCE, IWatcher::CHECK_ALWAYS * @since 9.0.0