Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions bin/stop-emrg.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ REM fallback), excludes the daemon (pythonw.exe -m emrg.server)
REM 3. daemon: `emrg server stop` protocol shutdown via the OLD install's CLI
REM (present since #364 -- version-safe), emrgd.pid poll (<=10s), then
REM taskkill /F /PID fallback
REM 4. bundled git: GUILT-BY-ASSOCIATION force-kill via stop-git.ps1
REM (host 2026-08-11T19:47:44 FINAL decision OVERRIDES #689: install success
REM 4. bundled git: INLINE guilt-by-association force-kill (single file,
REM rant 2026-08-12T14:00:05 -- stop-git.ps1 merged into this script).
REM Host 2026-08-11T19:47:44 FINAL decision OVERRIDES #689: install success
REM has priority -- if sh/vim hold msys-2.0.dll and block the git-tree kill,
REM they are killed too; only the install\git\ prefix is touched, system Git
REM in Program Files is never affected). stop-git.ps1 is a standalone script
REM (no cmd inline-PowerShell quoting escapes). The installer passes the
REM {tmp}-extracted copy as %~1 when the OLD install lacks it.
REM in Program Files is never affected. Step 4 runs PowerShell inline (same
REM \" escaping as the TUI/verify snippets below, proven on v0.2.25-v0.2.27);
REM every pass re-queries Get-CimInstance (no stale snapshot) and residual
REM processes are reported truthfully via exit 1 (rant 2026-08-12T12:30:41).
REM
REM Returns 0 when nothing EMRG-related survives; 1 if a process could not be
REM stopped (installer aborts with a clear message instead of hanging).
Expand Down Expand Up @@ -69,19 +71,19 @@ set "DPID="
for /f "usebackq delims=" %%p in ("%EMRG_DIR%\emrgd.pid") do set "DPID=%%p"
if defined DPID taskkill /F /PID %DPID% >nul 2>&1

REM --- 4. bundled git: guilt-by-association force-kill via stop-git.ps1 ---
REM --- 4. bundled git: inline guilt-by-association force-kill (single file) ---
REM (host 2026-08-11T19:47:44 FINAL decision OVERRIDES #689's snapshot-only
REM approach -- "如果杀死git时,发现sh/vim导致杀不掉,则一起杀": install success
REM has priority; sh/vim holding msys-2.0.dll under install\git\ are killed too.
REM Only the install\git\ prefix is touched; system Git (Program Files) is never
REM matched. 0.2.26's cmd inline-PowerShell quoting escape is avoided by calling
REM the standalone stop-git.ps1 via -File.)
set "GITSTOP=%INSTALL%\bin\stop-git.ps1"
if not exist "%GITSTOP%" set "GITSTOP=%~1"
if exist "%GITSTOP%" (
powershell -NoProfile -ExecutionPolicy Bypass -File "%GITSTOP%" >nul 2>&1
if errorlevel 1 set "EXIT_CODE=1"
)
REM approach: install success has priority -- if sh/vim hold msys-2.0.dll under
REM install\git\ and block the git-tree kill, they are killed too; only the
REM install\git\ prefix is touched, system Git (Program Files) is never matched.
REM Rant 2026-08-12T14:00:05: stop-git.ps1 deleted, logic inlined below.
REM Each pass re-queries Get-CimInstance (no stale snapshot); the survivor
REM check uses the latest snapshot; residual -> exit 1 (truthful failure #701).
REM The \" escaping matches the TUI/verify inline snippets proven on real
REM Windows in v0.2.25-v0.2.27.)
powershell -NoProfile -ExecutionPolicy Bypass -Command "$ErrorActionPreference='SilentlyContinue'; $prefix=\"$env:USERPROFILE\.emrg\install\git\*\"; Get-CimInstance Win32_Process | Where-Object { $_.ExecutablePath -like $prefix -and $_.Name -in @('git.exe','ssh.exe','plink.exe','bash.exe') } | ForEach-Object { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue }; Start-Sleep -Milliseconds 300; Get-CimInstance Win32_Process | Where-Object { $_.ExecutablePath -like $prefix } | ForEach-Object { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue }; Start-Sleep -Milliseconds 300; $left = @(Get-CimInstance Win32_Process | Where-Object { $_.ExecutablePath -like $prefix }); if ($left.Count -gt 0) { $left | ForEach-Object { Write-Host (\"still running: {0} (pid {1})\" -f $_.Name, $_.ProcessId) }; exit 1 }; exit 0" >nul 2>&1
if errorlevel 1 set "EXIT_CODE=1"


:verify
tasklist /FI "IMAGENAME eq EMRG.exe" 2>nul | findstr /i "EMRG.exe" >nul && set "EXIT_CODE=1"
Expand All @@ -95,9 +97,9 @@ if exist "%EMRG_DIR%\emrgd.pid" (
)
)
REM Bundled-git survival check (plain prefix; guilt-by-association semantics):
REM any process still under install\git\ -> exit 1 (installer aborts). This is the
REM same condition stop-git.ps1 reports; kept as belt-and-braces for the case the
REM script file could not be located (no old install, no {tmp} arg).
REM any process still under install\git\ -> exit 1 (installer aborts). Same
REM condition as step 4's inline PowerShell; kept as belt-and-braces in case the
REM PowerShell invocation itself fails.
powershell -NoProfile -Command "$p = Get-CimInstance Win32_Process | Where-Object { $_.ExecutablePath -like \"$env:USERPROFILE\.emrg\install\git\*\" }; if ($p) { exit 1 }" >nul 2>&1
if errorlevel 1 set "EXIT_CODE=1"
endlocal & exit /b %EXIT_CODE%
42 changes: 0 additions & 42 deletions bin/stop-git.ps1

This file was deleted.

1 change: 0 additions & 1 deletion packaging/build-runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ cp -R "$PY_ROOT/." "$DIST/bin/python-dist/"
cp "$ROOT/bin/emrg.cmd" emrg.cmd 2>/dev/null || true
cp "$ROOT/bin/emrgd.cmd" emrgd.cmd 2>/dev/null || true
cp "$ROOT/bin/stop-emrg.cmd" stop-emrg.cmd 2>/dev/null || true
cp "$ROOT/bin/stop-git.ps1" stop-git.ps1 2>/dev/null || true
cp "$ROOT/bin/emrg-uninstall" emrg-uninstall
chmod +x emrg emrgd emrg-uninstall
)
Expand Down
17 changes: 5 additions & 12 deletions packaging/make-installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,6 @@ Source: "$STAGE_WIN/payload\\*"; DestDir: "{app}"; Flags: recursesubdirs createa
; pythonw daemon 锁文件导致卡在"停止已有进程")。正常安装时该文件仍由上方通配符
; 装入 {app}\bin\stop-emrg.cmd。
Source: "$STAGE_WIN/payload\\bin\\stop-emrg.cmd"; DestDir: "{tmp}"; Flags: dontcopy
; R128: dontcopy — 供 [Code] PrepareToInstall 在覆盖文件前 ExtractTemporaryFile 取出并
; 作为 %~1 传给 stop-emrg.cmd step 4(连坐强杀 bundled git,宿主 2026-08-11T19:47:44
; 拍板覆盖 #689:旧安装 %INSTALL%\bin\stop-git.ps1 不存在时用 {tmp} 提取版)。
Source: "$STAGE_WIN/payload\\bin\\stop-git.ps1"; DestDir: "{tmp}"; Flags: dontcopy
[Icons]
Name: "{userprograms}\\EMRG"; Filename: "{app}\\emrg-gui\\EMRG\\EMRG.exe"; IconFilename: "{app}\\emrg-gui\\EMRG\\EMRG.exe"
[UninstallRun]
Expand Down Expand Up @@ -376,26 +372,23 @@ end;
// -m emrg.server 常驻锁文件),覆盖 ~/.emrg\install 时卡在"停止已有进程"。
// PrepareToInstall 在安装开始前运行 bin\stop-emrg.cmd:taskkill EMRG.exe
// 优雅→/F 兜底、wmic/PowerShell 命令行过滤 TUI、emrg server stop 协议关闭
// daemon + emrgd.pid 轮询兜底、step 4 调 stop-git.ps1 连坐强杀 bundled git
// daemon + emrgd.pid 轮询兜底、step 4 内联 PowerShell 连坐强杀 bundled git
// (宿主 2026-08-11T19:47:44 拍板覆盖 #689:sh/vim 锁 install\git\usr\bin\
// msys-2.0.dll 导致 Inno DeleteFile code 5 时一并强杀,安装成功优先;只碰
// install\git\ 前缀,系统 Git 不受影响)。旧安装可能没有 stop-git.ps1 →
// {tmp} dontcopy 提取版作为 %~1 传入(cmd 内先查 %INSTALL%\bin,缺失才用
// 参数)。干净安装(无旧 install)脚本自行跳过。返回非空字符串 = 中止安装
// install\git\ 前缀,系统 Git 不受影响;rant 2026-08-12T14:00:05 合并为
// 单文件——stop-git.ps1 已删除,逻辑内联进 stop-emrg.cmd step 4)。
// 干净安装(无旧 install)脚本自行跳过。返回非空字符串 = 中止安装
// 并显示该消息(宁可中止也不卡死)。
// {cmd} = cmd.exe(Inno 预定义常量,批处理文件须经 cmd 启动)。
function PrepareToInstall(var NeedsRestart: Boolean): String;
var
ResultCode: Integer;
StopScript: string;
GitStopScript: string;
begin
Result := '';
ExtractTemporaryFile('stop-emrg.cmd');
ExtractTemporaryFile('stop-git.ps1');
StopScript := ExpandConstant('{tmp}\\stop-emrg.cmd');
GitStopScript := ExpandConstant('{tmp}\\stop-git.ps1');
if Exec(ExpandConstant('{cmd}'), '/c "' + StopScript + '" "' + GitStopScript + '"', '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then
if Exec(ExpandConstant('{cmd}'), '/c "' + StopScript + '"', '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then
begin
if ResultCode <> 0 then
Result := 'EMRG could not stop all running processes (stop-emrg.cmd exit code ' + IntToStr(ResultCode) + '). Please close EMRG (GUI/TUI) and retry the install, or restart the computer and retry (a helper process such as the bundled Git may still hold a file lock).';
Expand Down
Loading
Loading