From ab1a18a886f0c783710021955a61227d83270f0b Mon Sep 17 00:00:00 2001 From: xl Date: Mon, 18 Nov 2024 12:19:26 +0800 Subject: [PATCH] eee --- Abstracts/HotReload.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Abstracts/HotReload.php b/Abstracts/HotReload.php index 31f259b..cc29102 100644 --- a/Abstracts/HotReload.php +++ b/Abstracts/HotReload.php @@ -22,6 +22,12 @@ class HotReload extends AbstractProcess protected bool $enable_coroutine = false; + /** + * @var array + */ + protected array $watches = []; + + /** * @var bool */ @@ -64,16 +70,14 @@ class HotReload extends AbstractProcess public function process(Process|null $process): void { $this->pipe = inotify_init(); - - foreach (config('reload.listen') as $key => $value) { - $this->readDirectory($value); + foreach (config('reload.listen') as $value) { + $this->readFile($value); } while (!$this->isStop()) { $read = inotify_read($this->pipe); - var_dump($read); foreach ($read as $item) { - $this->reWatch($item['name']); + $this->reWatch($this->watches[$item['wd']]); } $this->reload(); @@ -105,9 +109,10 @@ class HotReload extends AbstractProcess */ public function readFile(string $directory): void { - var_dump($directory); if (str_ends_with($directory, '.php') === true) { - inotify_add_watch($this->pipe, $directory, IN_MODIFY | IN_MOVE | IN_CREATE | IN_DELETE); + $wd = inotify_add_watch($this->pipe, $directory, IN_MODIFY | IN_MOVE | IN_CREATE | IN_DELETE); + + $this->watches[$wd] = $directory; } }