modify plugin name

This commit is contained in:
2022-06-23 13:44:32 +08:00
parent 7077095f7a
commit 93ae880902
@@ -11,7 +11,7 @@ use Kiri\Server\ServerInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Swoole\Process; use Swoole\Process;
class Scaner extends BaseProcess class Scanner extends BaseProcess
{ {
private array $md5Map = []; private array $md5Map = [];
@@ -49,38 +49,51 @@ class Scaner extends BaseProcess
*/ */
private function loadDirs(bool $isReload = FALSE) private function loadDirs(bool $isReload = FALSE)
{ {
foreach ($this->dirs as $value) { try {
$value = new DirectoryIterator($value); foreach ($this->dirs as $value) {
if ($value->isDot() || str_starts_with($value->getFilename(), '.')) { $value = new DirectoryIterator($value);
continue; if ($value->isDir()) {
} $this->loadByDir($value, $isReload);
if ($value->isDir()) { }
$this->loadByDir($value, $isReload);
} }
} catch (\Throwable $throwable) {
$this->logger->error($throwable->getMessage(), [$throwable]);
} }
} }
/** /**
* @param DirectoryIterator $path * @param DirectoryIterator $iterator
* @param bool $isReload * @param bool $isReload
* @return void * @return void
* @throws Exception * @throws Exception
*/ */
private function loadByDir(DirectoryIterator $path, bool $isReload = FALSE): void private function loadByDir(DirectoryIterator $iterator, bool $isReload = FALSE): void
{ {
if ($path->isDir()) { foreach ($iterator as $path) {
$this->loadByDir(new DirectoryIterator($path->getRealPath()), $isReload);
}
if (!str_ends_with($path->getFilename(), '.php')) {
return;
}
if ($this->checkFile($path, $isReload)) {
if ($this->isReloading) { if ($this->isReloading) {
return; return;
} }
$this->isReloading = TRUE; /** @var DirectoryIterator $path */
sleep(2);
if ($path->isDot() || str_starts_with($path->getFilename(), '.')) {
continue;
}
if ($path->getExtension() !== 'php') {
continue;
}
if ($path->isDir()) {
$this->loadByDir(new DirectoryIterator($path->getRealPath()), $isReload);
}
if ($this->checkFile($path, $isReload)) {
$this->isReloading = TRUE;
break;
}
}
if ($this->isReloading) {
$this->timerReload(); $this->timerReload();
} }
} }
@@ -93,8 +106,8 @@ class Scaner extends BaseProcess
*/ */
private function checkFile(DirectoryIterator $value, $isReload): bool private function checkFile(DirectoryIterator $value, $isReload): bool
{ {
$md5 = md5_file($value->getRealPath()); $md5 = md5($value->getRealPath());
$mTime = $value->getCTime(); $mTime = filectime($value->getRealPath());
if (!isset($this->md5Map[$md5])) { if (!isset($this->md5Map[$md5])) {
if ($isReload) { if ($isReload) {
return TRUE; return TRUE;
@@ -125,10 +138,10 @@ class Scaner extends BaseProcess
$swow->reload(); $swow->reload();
$this->loadDirs();
$this->isReloading = FALSE; $this->isReloading = FALSE;
$this->loadDirs();
$this->tick(); $this->tick();
} }