Enhance Windows installer update process with improved file handling and retry mechanisms
All checks were successful
farmcontrol/farmcontrol-ui/pipeline/head This commit looks good

- Added a temporary path change to avoid renaming issues during the update process, ensuring smoother transitions between old and new installations.
- Implemented a retry mechanism for renaming the old installation directory, increasing reliability in scenarios where files are locked.
- Enhanced logging to provide clearer feedback during the installation and renaming steps, improving user experience.
This commit is contained in:
Tom Butcher 2026-08-08 23:41:44 +01:00
parent 2216a28ce3
commit d7a7e798cb

View File

@ -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"