Skip to content

Commit 7872b82

Browse files
committed
feat: add an option to filter what paths get checked for updates
Signed-off-by: Robin Appelman <[email protected]>
1 parent 5f40fad commit 7872b82

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

lib/private/Files/Cache/Watcher.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class Watcher implements IWatcher {
3636
/** @var callable[] */
3737
protected $onUpdate = [];
3838

39+
protected ?string $checkFilter = null;
40+
3941
/**
4042
* @param \OC\Files\Storage\Storage $storage
4143
*/
@@ -52,6 +54,10 @@ public function setPolicy($policy) {
5254
$this->watchPolicy = $policy;
5355
}
5456

57+
public function setCheckFilter(?string $filter): void {
58+
$this->checkFilter = $filter;
59+
}
60+
5561
/**
5662
* @return int either \OC\Files\Cache\Watcher::CHECK_NEVER, \OC\Files\Cache\Watcher::CHECK_ONCE, \OC\Files\Cache\Watcher::CHECK_ALWAYS
5763
*/
@@ -116,6 +122,12 @@ public function update($path, $cachedData) {
116122
* @return bool
117123
*/
118124
public function needsUpdate($path, $cachedData) {
125+
if ($this->checkFilter !== null) {
126+
if (!preg_match($this->checkFilter, $path)) {
127+
return false;
128+
}
129+
}
130+
119131
if ($this->watchPolicy === self::CHECK_ALWAYS or ($this->watchPolicy === self::CHECK_ONCE and !in_array($path, $this->checkedPaths))) {
120132
$this->checkedPaths[] = $path;
121133
return $cachedData['storage_mtime'] === null || $this->storage->hasUpdated($path, $cachedData['storage_mtime']);

lib/private/Files/Storage/Common.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ public function getWatcher(string $path = '', ?IStorage $storage = null): IWatch
329329
$this->watcher = new Watcher($storage);
330330
$globalPolicy = Server::get(IConfig::class)->getSystemValueInt('filesystem_check_changes', Watcher::CHECK_NEVER);
331331
$this->watcher->setPolicy((int)$this->getMountOption('filesystem_check_changes', $globalPolicy));
332+
$this->watcher->setCheckFilter($this->getMountOption('filesystem_check_filter'));
332333
}
333334
return $this->watcher;
334335
}

lib/public/Files/Cache/IWatcher.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ interface IWatcher {
3434
*/
3535
public function setPolicy($policy);
3636

37+
/**
38+
* Set a filter regex, only paths matching the regex will be checked for updates.
39+
*
40+
* When set to `null`, every path will be checked for updates
41+
*
42+
* @param ?string $filter
43+
* @return void
44+
* @since 32.0.0
45+
*/
46+
public function setCheckFilter(?string $filter): void;
47+
3748
/**
3849
* @return int either IWatcher::CHECK_NEVER, IWatcher::CHECK_ONCE, IWatcher::CHECK_ALWAYS
3950
* @since 9.0.0

0 commit comments

Comments
 (0)