From 76fe865274c6bb127830cb52f72d9010865de05b Mon Sep 17 00:00:00 2001 From: augushong Date: Mon, 25 May 2026 21:28:21 +0800 Subject: [PATCH] =?UTF-8?q?perf(update):=20clone=20=E4=B8=80=E6=AC=A1?= =?UTF-8?q?=E4=BB=93=E5=BA=93=E5=B9=B6=E6=9C=AC=E5=9C=B0=E5=A4=8D=E5=88=B6?= =?UTF-8?q?=E6=9B=BF=E4=BB=A3=E7=AC=AC=E4=BA=8C=E6=AC=A1=E7=BD=91=E7=BB=9C?= =?UTF-8?q?=20clone;=20=E6=8E=92=E9=99=A4=20public/storage=20=E5=92=8C=20p?= =?UTF-8?q?ublic/build?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/service/AdminUpdateServiceBase.php | 49 ++++++++++++++++--- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/extend/base/admin/service/AdminUpdateServiceBase.php b/extend/base/admin/service/AdminUpdateServiceBase.php index d0ad575..b44882f 100644 --- a/extend/base/admin/service/AdminUpdateServiceBase.php +++ b/extend/base/admin/service/AdminUpdateServiceBase.php @@ -55,8 +55,8 @@ class AdminUpdateServiceBase $current_version = $this->useVersion; - $current_version_dir = App::getRuntimePath() . '/update/' . $current_version; - $last_version_dir = App::getRuntimePath() . '/update/last'; + $current_version_dir = App::getRuntimePath() . '/update/current'; + $last_version_dir = App::getRuntimePath() . '/update/repo'; $now_dir = App::getRootPath(); $output->writeln('获取最新代码'); @@ -118,11 +118,12 @@ class AdminUpdateServiceBase $last_version_repo->checkout($last_version); } - $current_version_git = new Git(); - $output->writeln('获取当前版本代码'); - $current_version_repo = $current_version_git->cloneRepository($this->useRepo, $current_version_dir); - $output->writeln('切换版本' . $current_version); - $current_version_repo->checkout($current_version); + $output->writeln('复制当前版本代码'); + $output->writeln('切换到当前版本' . $current_version); + $last_version_repo->checkout($current_version); + $this->copyDirectory($last_version_dir, $current_version_dir); + $output->writeln('切换回最新版本' . $last_version); + $last_version_repo->checkout($last_version); $output->writeln('开始比较版本差异'); @@ -142,6 +143,8 @@ class AdminUpdateServiceBase 'runtime', 'vendor', '.git', + 'public/storage', + 'public/build', ]; // 当前版本的应该被处理所有文件 @@ -426,4 +429,36 @@ class AdminUpdateServiceBase $this->output->writeln('清理目录 ' . $dir); PathTools::removeDir($dir); } + + /** + * 递归复制目录 + * Windows 兼容,使用 PHP 原生 opendir/readdir 实现 + */ + protected function copyDirectory(string $src, string $dst): void + { + if (!is_dir($src)) { + return; + } + + if (!is_dir($dst)) { + mkdir($dst, 0755, true); + } + + $handle = opendir($src); + while (false !== ($file = readdir($handle))) { + if ($file === '.' || $file === '..') { + continue; + } + + $srcPath = $src . '/' . $file; + $dstPath = $dst . '/' . $file; + + if (is_dir($srcPath)) { + $this->copyDirectory($srcPath, $dstPath); + } else { + copy($srcPath, $dstPath); + } + } + closedir($handle); + } }