Skip to content

Commit bea51d6

Browse files
fix(NSIS): prevent partial overwrites during Nsis7z::Extract (#6547)
`Nsis7z::Extract` ignores the errors when copying the files and thus can leave us with the app that has old asar and bindings, but new assets. In addition to that, the app will firmly believe that it is still running an old version and would attempt to repeatedly auto-update until fixed, leading to excessive bandwidth use and very unhappy customers. This change extracts the contents of 7z archive into a separate directory before attempting to copy them with `CopyFiles` function that (unlike `Nsis7z::Extract`) does detect and report failures. To make our lives easier the `CopyFiles` will also erase all files on a failure so after retrying a few times we will ultimately have to fallback to old 7z extraction directly into output folder.
1 parent 5648e05 commit bea51d6

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

.changeset/nervous-cherries-speak.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"app-builder-lib": patch
3+
---
4+
5+
fix(nsis): Prevent partial updates from happening

packages/app-builder-lib/templates/nsis/include/extractAppPackage.nsh

+41-1
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,45 @@
9090
!macroend
9191

9292
!macro extractUsing7za FILE
93-
Nsis7z::Extract "${FILE}"
93+
Push $OUTDIR
94+
CreateDirectory "$PLUGINSDIR\7z-out"
95+
ClearErrors
96+
SetOutPath "$PLUGINSDIR\7z-out"
97+
Nsis7z::Extract "${FILE}"
98+
Pop $R0
99+
SetOutPath $R0
100+
101+
# Retry counter
102+
StrCpy $R1 0
103+
104+
LoopExtract7za:
105+
IntOp $R1 $R1 + 1
106+
107+
CopyFiles /SILENT "$PLUGINSDIR\7z-out\*" $OUTDIR
108+
IfErrors 0 DoneExtract7za
109+
110+
${if} $R1 > 1
111+
DetailPrint `Can't modify "${PRODUCT_NAME}"'s files.`
112+
${if} $R1 < 5
113+
# Try copying a few times before giving up
114+
Goto LoopExtract7za
115+
${else}
116+
MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "$(appCannotBeClosed)" /SD IDCANCEL IDRETRY RetryExtract7za
117+
${endIf}
118+
119+
# CopyFiles will remove all overwritten files when it encounters an
120+
# issue and make app non-launchable. Extract over from the archive
121+
# ignoring the failures so at least we will partially update and the
122+
# app would start.
123+
Nsis7z::Extract "${FILE}"
124+
Quit
125+
${else}
126+
Goto LoopExtract7za
127+
${endIf}
128+
129+
RetryExtract7za:
130+
Sleep 1000
131+
Goto LoopExtract7za
132+
133+
DoneExtract7za:
94134
!macroend

0 commit comments

Comments
 (0)