Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix(desktop): 卸载助手清场时进程路径只读一次,删除用例走静默模式

longmeidaoa202b8651af5
diff --git a/src/peach/desktop_uninstall.py b/src/peach/desktop_uninstall.py
index c55fa316f..6ce4fef50 100644
--- a/src/peach/desktop_uninstall.py
+++ b/src/peach/desktop_uninstall.py
@@ -112,8 +112,11 @@ function Stop-PeachProgramProcesses {
# 托盘退出时被硬杀的服务会留下自己的子进程:扫描、转码用的可执行文件可能就在
# `_internal` 里。按镜像路径清场,只匹配程序目录前缀加一个分隔符,不误伤名字
# 相近的其它解压目录。
+ # `Path` 每读一次都现查一次进程:判空和比前缀各读一次的话,进程恰好在两次之间退出,
+ # 第二次读到的就是 Null。只读一次。
$peachStrays = @(Get-Process -ErrorAction SilentlyContinue | Where-Object {
- $_.Path -and $_.Path.StartsWith($peachProgram + [IO.Path]::DirectorySeparatorChar, [StringComparison]::OrdinalIgnoreCase)
+ $peachImage = $_.Path
+ $peachImage -and $peachImage.StartsWith($peachProgram + [IO.Path]::DirectorySeparatorChar, [StringComparison]::OrdinalIgnoreCase)
})
foreach ($peachStray in $peachStrays) {
Stop-Process -Id $peachStray.Id -Force -ErrorAction SilentlyContinue
@@ -154,10 +157,12 @@ try {
}
} catch {
$peachReason = $_.Exception.Message
+ # 弹窗只说原因;日志另记出错的那一行,「不能对 Null 值表达式调用方法」单看查不出是哪一步。
+ $peachWhere = $_.InvocationInfo.PositionMessage
$peachLog = if ($peachJob.log) { $peachJob.log } else { Join-Path ([IO.Path]::GetTempPath()) 'peach-uninstall.log' }
$peachDetail = '原因:' + $peachReason
try {
- Add-Content -LiteralPath $peachLog -Value ((Get-Date -Format s) + ' ' + $peachReason) -Encoding UTF8
+ Add-Content -LiteralPath $peachLog -Value ((Get-Date -Format s) + ' ' + $peachReason + [Environment]::NewLine + $peachWhere) -Encoding UTF8
$peachDetail += [Environment]::NewLine + '详情记录在 ' + $peachLog
} catch { }
if (-not $peachJob.quiet) {
diff --git a/tests/test_desktop_settings.py b/tests/test_desktop_settings.py
index 6cb204fff..cf2e5fabc 100644
--- a/tests/test_desktop_settings.py
+++ b/tests/test_desktop_settings.py
@@ -361,13 +361,13 @@ class DesktopSettingsTests(unittest.TestCase):
media = self.root / 'media'
media.mkdir()
(media / 'video.mp4').write_text('preserve')
- job = desktop_uninstall.plan(self.config, delete_data=True, program=self.program)
- shell = Path(os.environ.get('SystemRoot', r'C:\Windows')) / 'System32/WindowsPowerShell/v1.0/powershell.exe'
- result = subprocess.run([str(shell), '-NoProfile', '-NonInteractive', '-EncodedCommand',
- base64.b64encode(desktop_uninstall._SCRIPT.encode('utf-16-le')).decode('ascii')],
- input=json.dumps(dict(job, pid=2147483647)).encode('utf-8'), capture_output=True, timeout=25,
- creationflags=subprocess.CREATE_NO_WINDOW)
- self.assertEqual(result.returncode, 0, result.stderr)
+ # 走带 `quiet` 的那条:脚本一旦进 catch,不带它就在桌面上弹一个真的模态框。
+ log = self.root / 'uninstall.log'
+ result = self._run_native_uninstall(
+ desktop_uninstall.plan(self.config, delete_data=True, program=self.program), log=log)
+ self.assertEqual(result.returncode, 0,
+ result.stderr.decode(errors='replace')
+ + (log.read_text(encoding='utf-8') if log.exists() else ''))
self.assertFalse(self.program.exists())
self.assertFalse(self.config.path.exists())
self.assertFalse(generated_backup.exists())