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); + } }