Browse Source

CPack/NSIS: Fix installer not waiting for uninstaller to finish

In commit b795c96727 (CPack/NSIS: Fix uninstall command when run from
installer, 2022-03-21, v3.23.0-rc5~9^2~1) we incorrectly removed the
`_?` parameter when calling the uninstaller during installation.
This parameter is however essential for ExecWait to actually wait for
the uninstaller to finish.  Without it, the uninstaller is started in
the background and installer and uninstaller run at the same time.

See https://nsis.sourceforge.io/Docs/Chapter3.html#installerusageuninstaller

Add back the `_?` parameter to fix this regression.  Use another
approach to solve the problem motivating the original change.

Fixes: #24041
Mika Fischer 3 years ago
parent
commit
8721658959
1 changed files with 14 additions and 5 deletions
  1. 14 5
      Modules/Internal/CPack/NSIS.template.in

+ 14 - 5
Modules/Internal/CPack/NSIS.template.in

@@ -931,11 +931,20 @@ Function .onInit
 ;Run the uninstaller
 uninst:
   ClearErrors
-  StrCpy $2 $0 1
-  StrCmp '"' $2 0 +3 ; checks if string is quoted (CPack before v3.20.6 did not quote it)
-  ExecWait '$0 /S'
-  Goto +2
-  ExecWait '"$0" /S'
+  # $0 should _always_ be quoted, however older versions of CMake did not
+  # do this.  We'll conditionally remove the begin/end quotes.
+  # Remove first char if quote
+  StrCpy $2 $0 1 0      # copy first char
+  StrCmp $2 "$\"" 0 +2  # if char is quote
+  StrCpy $0 $0 "" 1     # remove first char
+  # Remove last char if quote
+  StrCpy $2 $0 1 -1     # copy last char
+  StrCmp $2 "$\"" 0 +2  # if char is quote
+  StrCpy $0 $0 -1       # remove last char
+
+  StrLen $2 "\@[email protected]"
+  StrCpy $3 $0 -$2 # remove "\@[email protected]" from UninstallString to get path
+  ExecWait '"$0" /S _?=$3' ;Do not copy the uninstaller to a temp file
 
   IfErrors uninst_failed inst
 uninst_failed: