- 启动链路 P1-P7 修复:预算对齐、完成事件推送、端口占用提示、前端阶段文案接管 - 静态缓存按 IS_FROZEN 区分开发/打包态,bootPhaseOwned 竞态修复 - 一键执行与参数配置统一收口到插件界面,定时任务引用 config_id - 环境包迁移到 %LOCALAPPDATA%\37duAutomation\python-env,重装零解压 - shell-updater:缓存包 sha256 校验、静默升级后自动拉起新版、自动清理旧安装包 - after-pack 钩子生成 shell.version 修复打包态版本识别 - 插件 xq0031/xq0045 迁移至 plugins/XQ0001-0100/ 号段分桶中文目录
67 lines
2.1 KiB
JavaScript
67 lines
2.1 KiB
JavaScript
// 环境包解压工作子进程(utilityProcess.fork 启动)。
|
||
// AdmZip.extractAllTo 是同步 API,294MB 环境包若在主进程解压会阻塞事件循环几十秒,
|
||
// 期间窗口点击必现"未响应"。故将【解压+校验+原子切换】整体下沉到子进程,主进程保持响应。
|
||
"use strict";
|
||
|
||
const fs = require("fs");
|
||
const path = require("path");
|
||
const AdmZip = require("adm-zip");
|
||
|
||
const { parentPort } = process;
|
||
|
||
function rm(p) {
|
||
try { fs.rmSync(p, { recursive: true, force: true }); } catch (e) { /* 忽略 */ }
|
||
}
|
||
|
||
function sleep(ms) {
|
||
const end = Date.now() + ms;
|
||
while (Date.now() < end) { /* 忙等(子进程内允许,避免阻塞主进程) */ }
|
||
}
|
||
|
||
// 入参:process.argv = [modulePath, zip, tmp, target]
|
||
async function main() {
|
||
const zip = process.argv[2];
|
||
const tmp = process.argv[3];
|
||
const target = process.argv[4];
|
||
try {
|
||
rm(tmp);
|
||
rm(target);
|
||
fs.mkdirSync(tmp, { recursive: true });
|
||
|
||
// 防路径穿越
|
||
const az = new AdmZip(zip);
|
||
for (const en of az.getEntries()) {
|
||
const name = en.entryName.replace(/\\/g, "/");
|
||
if (name.startsWith("/") || name.split("/").includes("..")) {
|
||
throw new Error(`环境包含非法路径: ${name}`);
|
||
}
|
||
}
|
||
// 同步解压(本进程阻塞无所谓)
|
||
az.extractAllTo(tmp, true);
|
||
|
||
// 冒烟校验:必须含 python.exe + plugin_runner.py
|
||
if (!fs.existsSync(path.join(tmp, "python.exe"))) throw new Error("环境包缺少 python.exe");
|
||
if (!fs.existsSync(path.join(tmp, "webhost", "backend", "core", "plugin_runner.py"))) {
|
||
throw new Error("环境包缺少 plugin_runner.py");
|
||
}
|
||
|
||
// 原子切换(带重试:杀软可能短暂占用新解压文件导致 rename EPERM)
|
||
let lastErr = null;
|
||
for (let i = 0; i < 3; i++) {
|
||
try {
|
||
fs.renameSync(tmp, target);
|
||
parentPort.postMessage({ ok: true, target });
|
||
return;
|
||
} catch (e) {
|
||
lastErr = e;
|
||
sleep(500 * (i + 1));
|
||
}
|
||
}
|
||
throw lastErr || new Error("环境包切换失败");
|
||
} catch (e) {
|
||
parentPort.postMessage({ ok: false, error: (e && e.message) || String(e) });
|
||
}
|
||
}
|
||
|
||
main();
|