fix(desktop): handle long paths during upgrade uninstall

This commit is contained in:
winewill committed 2026-11-16 18:25:53 +08:00
1 parent c3bfc6ef85
commit 45d6ae9ff2
7 files changed
+16 -6

No files matched your search

+2 -2
View File
@@ -45,8 +45,8 @@
en: b42f103358d0dfd7
zh: a534164ad9eb00da
/desktop-packaging/runtime-file-selection-and-installation-checks:
en: da4669b98c79ee48
zh: d007e87f13ff54d3
en: 1d153e4ba7528414
zh: cdf15fb80099ce17
/desktop-packaging/desktop-runtime-preparation:
en: 84be38ab3136fff7
zh: bb4ed12ee0e1dfa0
+1 -1
View File
@@ -262,7 +262,7 @@ Windows release qualification also runs [directory and replacement checks](../sc
pwsh -NoProfile -File apps/desktop/scripts/smoke-windows.ps1 -Makensis $Makensis -SevenZip $SevenZip -PluginDir $PluginDir -FrameLibrary apps/desktop/.desktop-build/targets/win-x64/installer-ui/window-frame.dll
```
The Windows installer checks for a running application at startup and after destination selection, before extracting the new version beside the installation directory. It checks again before replacing directories through same-volume renames. A running application blocks installation; update launches allow up to ten seconds for it to exit. Same-path upgrades preserve the old directory until promotion succeeds; extraction failure leaves it intact, and promotion failure attempts to restore it. The installer removes the old backup before launch. Forced termination or power loss can leave `.new-*` or `.old-*` directories; installation-location and scope migrations retain electron-builder's old-uninstaller flow.
The Windows installer checks for a running application at startup and after destination selection, before extracting the new version beside the installation directory. It checks again before replacing directories through same-volume renames. A running application blocks installation; update launches allow up to ten seconds for it to exit. Same-path upgrades preserve the old directory until promotion succeeds; extraction failure leaves it intact, and promotion failure attempts to restore it. The installer removes the old backup before launch. Forced termination or power loss can leave `.new-*` or `.old-*` directories; installation-location and scope migrations retain electron-builder's old-uninstaller flow, using extended paths for both file moves and rollback.
Directory renames, empty-destination removal, and restoration retry Windows errors 5, 32, and 33 up to ten attempts, with 250 ms increasing delays (11.25 seconds of total waiting per operation). Other errors stop immediately. A replacement failure reports the Windows error, affected paths, and restoration outcome in `directory-failure-<timestamp>.log` beside extraction reports. If restoration fails, the installer removes unlocked staging files and preserves the backup. After reporting that failure, exit cleanup does not retry restoration. Keep the backup path named in the report and contact support before reinstalling. Silent installs save the same diagnostic without a dialog.
+1 -1
View File
@@ -262,7 +262,7 @@ Windows 发布验收还需在 Desktop 构建后手动运行[目录和替换检
pwsh -NoProfile -File apps/desktop/scripts/smoke-windows.ps1 -Makensis $Makensis -SevenZip $SevenZip -PluginDir $PluginDir -FrameLibrary apps/desktop/.desktop-build/targets/win-x64/installer-ui/window-frame.dll
```
Windows 安装器在启动时和选定目标目录后检查应用是否正在运行,通过检查后才将新版本解压到安装目录旁边。通过同卷目录改名替换前,安装器会再次检查。运行中的应用会阻止安装;更新启动允许等待应用退出,最长十秒。同路径升级在替换成功前保留旧目录;解压失败时旧版不变,替换失败时尝试恢复旧目录。安装器在启动前清理旧版备份。强制结束安装器或断电可能留下 `.new-*` 或 `.old-*` 目录;不同安装位置或安装范围迁移仍使用 electron-builder 的旧卸载器流程。
Windows 安装器在启动时和选定目标目录后检查应用是否正在运行,通过检查后才将新版本解压到安装目录旁边。通过同卷目录改名替换前,安装器会再次检查。运行中的应用会阻止安装;更新启动允许等待应用退出,最长十秒。同路径升级在替换成功前保留旧目录;解压失败时旧版不变,替换失败时尝试恢复旧目录。安装器在启动前清理旧版备份。强制结束安装器或断电可能留下 `.new-*` 或 `.old-*` 目录;不同安装位置或安装范围迁移仍使用 electron-builder 的旧卸载器流程,文件移动与失败恢复均使用扩展路径。
目录改名、空目标目录删除和旧版恢复遇到 Windows 错误 5、32 或 33 时最多尝试十次,每次等待递增 250 毫秒(每个操作合计等待 11.25 秒)。其他错误立即停止。替换失败时,安装器将 Windows 错误、相关路径和恢复结果写入解压报告旁的 `directory-failure-<时间戳>.log`。如果恢复失败,安装器会清理未被占用的暂存文件并保留备份。上报此失败后,退出清理不再重试恢复。请保留报告所列的备份目录,并在重新安装前联系支持人员。静默安装保存相同的诊断,不显示弹窗。
@@ -17,7 +17,7 @@ export function directoryInstallerExits(source: string): string
/**
* Retain the original uninstall directory, reject another installation owner, and use native data cleanup.
* @param source - Pinned upstream uninstaller source.
* @returns Uninstaller with long-path application removal and no upstream RMDir data removal.
* @returns Uninstaller with long-path removal and upgrade rollback, without upstream RMDir data removal.
*/
export function directoryUninstaller(source: string): string
@@ -87,10 +87,12 @@ export function installWindowsDirectoryInstaller() {
/**
* Retain the original uninstall directory and bypass shared cleanup for directory-only removal.
* @param {string} source - Pinned upstream uninstaller source.
* @returns {string} Uninstaller with long-path application removal and no upstream RMDir data removal.
* @returns {string} Uninstaller with long-path removal and upgrade rollback, without upstream RMDir data removal.
*/
export function directoryUninstaller(source) {
let normalized = source.replaceAll('\r\n', '\n')
normalized = normalized.replaceAll('"$INSTDIR$R0', '"\\\\?\\$INSTDIR$R0')
.replaceAll('"$PLUGINSDIR\\old-install', '"\\\\?\\$PLUGINSDIR\\old-install')
normalized = replaceOnce(normalized, 'Function un.onInit\n', 'Var dshUninstallDirectory\nFunction un.onInit\n StrCpy $dshUninstallDirectory $INSTDIR\n')
normalized = replaceOnce(normalized, ' !insertmacro initMultiUser', ` !insertmacro initMultiUser
StrCpy $INSTDIR $dshUninstallDirectory
@@ -23,6 +23,10 @@ it('keeps data cleanup out of the upstream template while retaining application
expect(adapted).toContain('DeleteRegKey SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY_2}"')
expect(directoryUninstaller(source.replaceAll('\n', '\r\n'))).toBe(adapted)
expect(adapted).toContain('RMDir /r "\\\\?\\$INSTDIR"')
expect(adapted).toContain('Rename "\\\\?\\$INSTDIR$R0\\$R2" "\\\\?\\$PLUGINSDIR\\old-install$R0\\$R2"')
expect(adapted).toContain('Rename "\\\\?\\$PLUGINSDIR\\old-install$R0\\$R2" "\\\\?\\$INSTDIR$R0\\$R2"')
expect(adapted).not.toContain('"$INSTDIR$R0')
expect(adapted).not.toContain('"$PLUGINSDIR\\old-install')
expect(() => directoryUninstaller(source.replace(' # delete the installed files\n', ''))).toThrow('template changed')
expect(() => directoryUninstaller(source.replace(' Var /GLOBAL isDeleteAppData\n', ''))).toThrow('template changed')
expect(() => directoryUninstaller(source.replace(' DeleteRegKey SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY}"', ''))).toThrow('template changed')
@@ -57,6 +57,10 @@ try {
} finally { $setup.Dispose() }
$entry = Get-ItemProperty ('HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\' + $RegistryKey)
if ($entry.InstallLocation.TrimEnd('\') -ne $installPath) { throw 'Uninstall entry lacks InstallLocation' }
$deepAsset = Join-Path $installPath (('nested-' * 20) + '\' + ('asset-' * 15) + '.txt')
if ($deepAsset.Length -le 260) { throw 'Uninstall fixture must exceed MAX_PATH' }
[IO.Directory]::CreateDirectory('\\?\' + [IO.Path]::GetDirectoryName($deepAsset)) | Out-Null
[IO.File]::WriteAllText(('\\?\' + $deepAsset), 'long path payload')
foreach ($path in @($homePath, $productDataPath, $userDataPath, $cachePath, $externalPath)) { New-Item -ItemType Directory -Force -Path $path | Out-Null }
[IO.File]::WriteAllText((Join-Path $externalPath 'keep.txt'), 'outside data root')
if (-not (Test-Path -LiteralPath (Join-Path $userDataPath 'linked-project'))) {