From f801c8adb3f6216092d7f2278f16c48dbdff419c Mon Sep 17 00:00:00 2001 From: hex2077 Date: Sat, 10 Jan 2026 18:50:13 +0800 Subject: [PATCH] =?UTF-8?q?fix(update-api):=20=E5=9C=A8=E8=A7=A3=E5=8E=8B?= =?UTF-8?q?=E5=89=8D=E6=B8=85=E7=90=86=E6=97=A7=E4=BB=A3=E7=A0=81=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E4=BB=A5=E7=A1=AE=E4=BF=9D=E5=AE=8C=E5=85=A8=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在performTarballUpdate函数中添加清理src/和static/目录的逻辑,防止旧代码残留影响更新完整性 --- src/ui-modules/update-api.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/ui-modules/update-api.js b/src/ui-modules/update-api.js index 43db3d8..ef2329f 100644 --- a/src/ui-modules/update-api.js +++ b/src/ui-modules/update-api.js @@ -344,6 +344,17 @@ async function performTarballUpdate(localVersion, latestTag) { ? readFileSync(path.join(appDir, 'package.json'), 'utf-8') : null; + // 5.5 在解压前删除 src/ 和 static/ 目录,确保旧代码被完全清除 + const dirsToClean = ['src', 'static']; + for (const dirName of dirsToClean) { + const dirPath = path.join(appDir, dirName); + if (existsSync(dirPath)) { + console.log(`[Update] Removing old ${dirName}/ directory before extraction...`); + await fs.rm(dirPath, { recursive: true, force: true }); + console.log(`[Update] Old ${dirName}/ directory removed`); + } + } + // 6. 定义需要保留的目录和文件(不被覆盖) const preservePaths = [ 'configs', // 用户配置目录