mirror of
https://github.com/nextcloud/server.git
synced 2026-02-20 00:12:30 -05:00
feat: add an option to filter what paths get checked for updates
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
f40149f9bc
commit
2948aaf2f9
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 or ($this->watchPolicy === self::CHECK_ONCE and !in_array($path, $this->checkedPaths))) {
|
||||
$this->checkedPaths[] = $path;
|
||||
return $cachedData['storage_mtime'] === null || $this->storage->hasUpdated($path, $cachedData['storage_mtime']);
|
||||
|
|
|
|||
|
|
@ -329,6 +329,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
|
||||
|
|
|
|||
Loading…
Reference in a new issue