diff --git a/packaging/windows/installer.nsh b/packaging/windows/installer.nsh index ddd97de..8911994 100644 --- a/packaging/windows/installer.nsh +++ b/packaging/windows/installer.nsh @@ -127,6 +127,10 @@ Var FinalInstDir !insertmacro progressStatus "Replacing Farm Control with the new version..." DetailPrint "Replacing Farm Control with staged update..." + ; The install section ran SetOutPath into the install tree; a directory that + ; is any process's working directory cannot be renamed, so move out first. + SetOutPath "$TEMP" + ; Clear a leftover .old from a previous interrupted update. ${If} ${FileExists} "$FinalInstDir.old" DetailPrint "Removing leftover Farm Control.old..." @@ -137,34 +141,46 @@ Var FinalInstDir !insertmacro progressStatus "Waiting for Farm Control to release install files..." DetailPrint "Waiting to rename install directory to Farm Control.old..." + ; Retry every 500ms; success is verified on disk rather than via the + ; error flag, which Rename does not set reliably. StrCpy $R7 0 swap_rename_old_retry: - ClearErrors Rename "$FinalInstDir" "$FinalInstDir.old" - ${If} ${Errors} - IntOp $R7 $R7 + 1 - ${If} $R7 < 60 - Sleep 500 - Goto swap_rename_old_retry - ${EndIf} - !insertmacro progressFailure "Could not move the previous Farm Control installation aside." - Abort + ${IfNot} ${FileExists} "$FinalInstDir" + Goto swap_rename_old_done ${EndIf} + IntOp $R7 $R7 + 1 + ${If} $R7 < 120 + Sleep 500 + Goto swap_rename_old_retry + ${EndIf} + !insertmacro progressFailure "Could not move the previous Farm Control installation aside." + Abort + swap_rename_old_done: + DetailPrint "Install directory renamed to Farm Control.old" ${EndIf} !insertmacro progressStatus "Activating new Farm Control installation..." DetailPrint "Renaming Farm Control.new to Farm Control..." - ClearErrors - Rename "$INSTDIR" "$FinalInstDir" - ${If} ${Errors} + StrCpy $R7 0 + swap_rename_new_retry: + Rename "$INSTDIR" "$FinalInstDir" + ${If} ${FileExists} "$FinalInstDir" + Goto swap_rename_new_done + ${EndIf} + IntOp $R7 $R7 + 1 + ${If} $R7 < 20 + Sleep 500 + Goto swap_rename_new_retry + ${EndIf} ; Best-effort rollback so the previous install is usable again. ${If} ${FileExists} "$FinalInstDir.old" Rename "$FinalInstDir.old" "$FinalInstDir" ${EndIf} !insertmacro progressFailure "Could not activate the new Farm Control installation." Abort - ${EndIf} + swap_rename_new_done: StrCpy $INSTDIR $FinalInstDir !insertmacro progressLog "installer:STATUS:Update files activated"