From 8587f72f81178adf6f63fed5d5ee2b90770a174d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E5=9B=BD=E9=94=8B?= Date: Sun, 8 Feb 2026 14:19:13 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix(update):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=9B=B4=E6=96=B0=E4=B8=8B=E8=BD=BD=E6=97=B6=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E8=A2=AB=E5=8D=A0=E7=94=A8=E5=AF=BC=E8=87=B4=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/app/methods_update.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/app/methods_update.go b/internal/app/methods_update.go index 893e3aa..d9f4f75 100644 --- a/internal/app/methods_update.go +++ b/internal/app/methods_update.go @@ -221,14 +221,18 @@ func (a *App) downloadAndStageUpdate(info UpdateInfo) connection.QueryResult { return connection.QueryResult{Success: false, Message: errMsg} } - stagedDir, err := os.MkdirTemp(workspaceDir, ".gonavi-update-work-") - if err != nil { - errMsg := fmt.Sprintf("无法在应用目录创建更新工作目录:%s", workspaceDir) + // 使用版本号命名的工作目录,便于识别和调试 + stagedDir := filepath.Join(workspaceDir, fmt.Sprintf(".gonavi-update-%s-%s", stdRuntime.GOOS, info.LatestVersion)) + // 清理可能残留的旧目录(上次下载失败后未清理) + _ = os.RemoveAll(stagedDir) + if err := os.MkdirAll(stagedDir, 0o755); err != nil { + errMsg := fmt.Sprintf("无法在应用目录创建更新工作目录:%s", stagedDir) a.emitUpdateDownloadProgress("error", 0, info.AssetSize, errMsg) return connection.QueryResult{Success: false, Message: errMsg} } - assetPath := filepath.Join(workspaceDir, info.AssetName) + // 下载到 staging 目录,避免覆盖正在运行的可执行文件 + assetPath := filepath.Join(stagedDir, info.AssetName) actualHash, err := downloadFileWithHash(info.AssetURL, assetPath, func(downloaded, total int64) { reportTotal := total if reportTotal <= 0 {