From 3d0adf1e9c14ac40232e938a3b61bce4d4c4aa3c Mon Sep 17 00:00:00 2001 From: libiao320-cmd Date: Mon, 31 Aug 2026 15:06:21 +0800 Subject: [PATCH] =?UTF-8?q?fix(hostupdate):=20Windows=20=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=20-=20=E7=A3=81=E7=9B=98=E7=A9=BA=E9=97=B4?= =?UTF-8?q?=E9=A2=84=E6=A3=80=E6=8B=86=E5=88=86=E4=B8=BA=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=20(#363)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: libiao320-cmd <280725528+libiao320-cmd@users.noreply.github.com> --- backend/internal/hostupdate/disk_unix.go | 21 +++++++++++++++++++++ backend/internal/hostupdate/disk_windows.go | 9 +++++++++ backend/internal/hostupdate/manager_ops.go | 10 ++-------- 3 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 backend/internal/hostupdate/disk_unix.go create mode 100644 backend/internal/hostupdate/disk_windows.go diff --git a/backend/internal/hostupdate/disk_unix.go b/backend/internal/hostupdate/disk_unix.go new file mode 100644 index 000000000..adf3e94be --- /dev/null +++ b/backend/internal/hostupdate/disk_unix.go @@ -0,0 +1,21 @@ +//go:build !windows + +package hostupdate + +import ( + "fmt" + "syscall" +) + +// checkBackupDiskSpace 确保备份目录至少有 2 GiB 可用空间。 +func checkBackupDiskSpace(directory string) error { + var disk syscall.Statfs_t + if err := syscall.Statfs(directory, &disk); err != nil { + return fmt.Errorf("检查备份磁盘空间:%w", err) + } + available := int64(disk.Bavail) * int64(disk.Bsize) + if available < 2<<30 { + return fmt.Errorf("备份目录可用空间不足 2 GiB:当前 %d MiB", available>>20) + } + return nil +} diff --git a/backend/internal/hostupdate/disk_windows.go b/backend/internal/hostupdate/disk_windows.go new file mode 100644 index 000000000..6ba7a004c --- /dev/null +++ b/backend/internal/hostupdate/disk_windows.go @@ -0,0 +1,9 @@ +//go:build windows + +package hostupdate + +// checkBackupDiskSpace 在 Windows 本地开发环境跳过磁盘空间预检。 +// 磁盘预检仅服务 Linux 服务器部署时的在线更新器,Windows 本地开发用不到。 +func checkBackupDiskSpace(directory string) error { + return nil +} diff --git a/backend/internal/hostupdate/manager_ops.go b/backend/internal/hostupdate/manager_ops.go index 61cfe8426..4ce73b7b2 100644 --- a/backend/internal/hostupdate/manager_ops.go +++ b/backend/internal/hostupdate/manager_ops.go @@ -17,7 +17,6 @@ import ( "runtime" "sort" "strings" - "syscall" "time" ) @@ -131,13 +130,8 @@ func (m *Manager) preflight(composePath, targetVersion string) error { return fmt.Errorf("检查 Host Updater 安装目录:%w", err) } } - var disk syscall.Statfs_t - if err := syscall.Statfs(m.config.BackupDir, &disk); err != nil { - return fmt.Errorf("检查备份磁盘空间:%w", err) - } - available := int64(disk.Bavail) * int64(disk.Bsize) - if available < 2<<30 { - return fmt.Errorf("备份目录可用空间不足 2 GiB:当前 %d MiB", available>>20) + if err := checkBackupDiskSpace(m.config.BackupDir); err != nil { + return err } if err := m.compose(composePath, targetVersion, 2*time.Minute, nil, "config", "--quiet"); err != nil { return fmt.Errorf("目标 Compose 校验失败:%w", err)