From 7f93ab046bc3c4bf74d38684709966dbb831133d Mon Sep 17 00:00:00 2001 From: xl Date: Mon, 18 Nov 2024 13:53:50 +0800 Subject: [PATCH] eee --- Abstracts/HotReload.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/Abstracts/HotReload.php b/Abstracts/HotReload.php index 133c370..46586e3 100644 --- a/Abstracts/HotReload.php +++ b/Abstracts/HotReload.php @@ -70,17 +70,14 @@ class HotReload extends AbstractProcess public function process(Process|null $process): void { $this->pipe = inotify_init(); - foreach (config('reload.listen') as $value) { $this->readDirectory($value); } while (!$this->isStop()) { $read = inotify_read($this->pipe); - foreach ($read as $item) { - $this->reWatch($item['wd']); + if (!empty($read)) { + $this->reload(); } - - $this->reload(); } } @@ -95,10 +92,18 @@ class HotReload extends AbstractProcess } $this->reloading = true; + foreach ($this->watches as $key => $watch) { + inotify_rm_watch($this->pipe, $key); + } + \Kiri::getLogger()->info('reloading server, please waite.'); di(ServerInterface::class)->reload(); + foreach (config('reload.listen') as $value) { + $this->readDirectory($value); + } + $this->reloading = false; } @@ -126,7 +131,12 @@ class HotReload extends AbstractProcess if (isset($this->watches[$directory])) { inotify_rm_watch($this->pipe, $directory); - inotify_add_watch($this->pipe, $this->watches[$directory], IN_MODIFY | IN_MOVE | IN_CREATE | IN_DELETE); + $path = $this->watches[$directory]; + unset($this->watches[$directory]); + + $data = inotify_add_watch($this->pipe, $path, IN_MODIFY | IN_MOVE | IN_CREATE | IN_DELETE); + + $this->watches[$data] = $path; } }