diff --git a/scripts/windows/msi-install.ps1 b/scripts/windows/msi-install.ps1 index d864f19c..9aa7ff5f 100644 --- a/scripts/windows/msi-install.ps1 +++ b/scripts/windows/msi-install.ps1 @@ -5,6 +5,25 @@ param ( [string]$BuildDir = "." ) +# Clean up leftovers of a previous test run that did not complete its +# uninstall (e.g. was killed, or the uninstall failed to remove files). +# A leftover data directory makes the MSI installation fail with +# "data directory exists and is not empty", permanently, until the +# worker is cleaned. +$svc = Get-Service $ServiceName -ErrorAction SilentlyContinue +if ($svc) { + Write-Output "Removing leftover service $ServiceName" + if ($svc.Status -ne 'Stopped') { + Stop-Service $ServiceName -Force -ErrorAction SilentlyContinue + try { $svc.WaitForStatus('Stopped', '00:01:00') } catch {} + } + sc.exe delete $ServiceName | Out-Null +} +if (Test-Path $InstallDir) { + Write-Output "Removing leftover installation directory $InstallDir" + Remove-Item -Recurse -Force $InstallDir +} + # Look for the first MariaDB MSI file in the $BuildDir $msiFile = Get-ChildItem -Path $BuildDir -Filter "mariadb-*.msi" | Select-Object -First 1