diff --git a/extend/base/admin/service/AdminUpdateServiceBase.php b/extend/base/admin/service/AdminUpdateServiceBase.php index 6291ab2..7e39057 100644 --- a/extend/base/admin/service/AdminUpdateServiceBase.php +++ b/extend/base/admin/service/AdminUpdateServiceBase.php @@ -126,37 +126,14 @@ class AdminUpdateServiceBase '.git', ]; - $filter_files_function = function (StorageAttributes $attributes) use ($ignore_prefix) { - if ($attributes->isDir()) { - return false; - } - - foreach ($ignore_prefix as $prefix) { - if (str_starts_with($attributes->path(), $prefix)) { - return false; - } - } - - return true; - }; - // 当前版本的应该被处理所有文件 - $current_version_files = $current_version_filesystem->listContents('/', true) - ->filter($filter_files_function) - ->map(fn (StorageAttributes $attributes) => $attributes->path()) - ->toArray(); + $current_version_files = $this->collectTrackedFiles($current_version_filesystem, $ignore_prefix); // 最新版本的所有文件 - $last_version_files = $last_version_filesystem->listContents('/', true) - ->filter($filter_files_function) - ->map(fn (StorageAttributes $attributes) => $attributes->path()) - ->toArray(); + $last_version_files = $this->collectTrackedFiles($last_version_filesystem, $ignore_prefix); // 本身的所有文件 - $now_files = $now_filesystem->listContents('/', true) - ->filter($filter_files_function) - ->map(fn (StorageAttributes $attributes) => $attributes->path()) - ->toArray(); + $now_files = $this->collectTrackedFiles($now_filesystem, $ignore_prefix); $changed_files = []; @@ -393,6 +370,37 @@ class AdminUpdateServiceBase return false; } + protected function collectTrackedFiles(Filesystem $filesystem, array $ignore_prefix, string $path = '/') + { + $files = []; + + foreach ($filesystem->listContents($path, false) as $attributes) { + if ($this->isIgnoredPath($attributes->path(), $ignore_prefix)) { + continue; + } + + if ($attributes->isDir()) { + $files = array_merge($files, $this->collectTrackedFiles($filesystem, $ignore_prefix, $attributes->path())); + continue; + } + + $files[] = $attributes->path(); + } + + return $files; + } + + protected function isIgnoredPath(string $path, array $ignore_prefix) + { + foreach ($ignore_prefix as $prefix) { + if (str_starts_with($path, $prefix)) { + return true; + } + } + + return false; + } + protected function cleanWorkpaceDir() { $dir = App::getRuntimePath() . '/update/';