Skip to content

The only downloader you need. 下载器的集大成者。

fix(updater): 全量更新解压到 STAGING_DIR 解决 Program Files 权限

XiaoYouChR60cb7adb688a
diff --git a/app/services/update_service.py b/app/services/update_service.py
index b74d80d1..b57b506a 100644
--- a/app/services/update_service.py
+++ b/app/services/update_service.py
@@ -238,8 +238,7 @@ class UpdateService(QObject):
self._emit("app", UpdateState.FAILED, error="校验失败")
return
- appDir = executableDir.parent.parent if sys.platform == "darwin" else executableDir
- newDir = appDir.parent / f"{appDir.name}_new"
+ newDir = STAGING_DIR / "app_new"
if newDir.exists():
await asyncio.to_thread(shutil.rmtree, newDir)
@@ -289,12 +288,14 @@ class UpdateService(QObject):
appDir = executableDir.parent.parent if sys.platform == "darwin" else executableDir
patchPath = STAGING_DIR / "patch.hdiff"
- newDir = appDir.parent / f"{appDir.name}_new"
+ stagingNewDir = STAGING_DIR / "app_new"
args = [str(updaterPath), str(os.getpid()), str(appDir), sys.executable]
if patchPath.is_file():
args.append(str(patchPath))
- elif not newDir.is_dir():
+ elif stagingNewDir.is_dir():
+ args.append(str(stagingNewDir))
+ else:
logger.error("no patch or newDir found for update")
return
diff --git a/tools/updater/updater.c b/tools/updater/updater.c
index 62b04f10..e677555a 100644
--- a/tools/updater/updater.c
+++ b/tools/updater/updater.c
@@ -857,8 +857,19 @@ int main(int argc, char *argv[]) {
deleteDir(backupDir);
+ int isStagedDir = patchFile && hasDir(patchFile);
+
if (patchFile) {
- if (hasDir(newDir)) {
+ if (isStagedDir) {
+ if (!hasDir(newDir)) {
+ logMsg("moving staged dir " PFMT " -> " PFMT, patchFile, newDir);
+ if (moveDir(patchFile, newDir) != 0) {
+ logMsg("move staged dir failed");
+ closeLog();
+ return EXIT_RENAME_FAILED;
+ }
+ }
+ } else if (hasDir(newDir)) {
logMsg("reusing " PFMT, newDir);
} else if (runHpatchz(updaterDir, appDir, patchFile, newDir) != 0) {
logMsg("hpatchz failed");
@@ -872,7 +883,7 @@ int main(int argc, char *argv[]) {
/* Windows cannot MoveFile a directory while updater.log is open inside it. */
closeLog();
- if (patchFile) {
+ if (patchFile && !isStagedDir) {
#ifdef _WIN32
_wremove(patchFile);
#else