Watcher plugin fixes

* com.noccy.watcher: Initial inotify support
* ScriptRunner now accepts an array of local vars for expansion
  when evaluating scripts
This commit is contained in:
2021-12-15 03:47:39 +01:00
parent 30dfd4889b
commit 1125ccb82d
5 changed files with 135 additions and 12 deletions

View File

@ -17,10 +17,12 @@ class FileWatcher {
public function __construct()
{
if (extension_loaded('inotify')) {
$this->monitor = new MtimeMonitor();
//$this->monitor = new InotifyMonitor();
if (extension_loaded('inotify') && !getenv("SPARK_NO_INOTIFY")) {
//$this->monitor = new MtimeMonitor();
printf("Enabling inotify support, watching directories\n");
$this->monitor = new InotifyMonitor();
} else {
printf("No inotify support, watching file mtimes\n");
$this->monitor = new MtimeMonitor();
}
$this->scriptRunner = get_environment()->getScriptRunner();
@ -38,7 +40,11 @@ class FileWatcher {
private function triggerRule(Rule $rule)
{
$actions = $rule->getActions();
$this->scriptRunner->evaluate($actions);
$locals = [
'WATCHER_RULE' => $rule->getName(),
'WATCHER_FILES' => join(" ",$rule->getWatchedFiles()),
];
$this->scriptRunner->evaluate($actions, $locals);
}
public function loop()