feat: add an option to filter what paths get checked for updates

Signed-off-by: Robin Appelman <robin@icewind.nl>
pull/52442/head
Robin Appelman 2025-04-25 20:23:28 +07:00
parent b33fdaf085
commit 5c625b7a07
3 changed files with 24 additions and 0 deletions

@ -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']);

@ -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;
}

@ -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