Skip to content

Commit 137d18b

Browse files
authored
Merge pull request #3017 from input-output-hk/chore/wait-30s-for-lockfile-in-windows-installer
Wait 30 s for the `daedalus_lockfile` to unlock in the Windows installer
2 parents 3fe4086 + 92ecac2 commit 137d18b

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

installers/common/WindowsInstaller.hs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import Development.NSIS (Attrib (IconFile, IconIndex, RebootOK, Recurs
2020
name, nsis, onPagePre, onError, outFile, page, readRegStr,
2121
requestExecutionLevel, rmdir, section, setOutPath, str,
2222
strLength, uninstall, unsafeInject, unsafeInjectGlobal,
23-
loadLanguage,
23+
loadLanguage, sleep, (@=), detailPrint, (%<), (%&&),
24+
not_, mutableInt_, mutable_, while, false, true, strShow, (&),
2425
writeRegDWORD, writeRegStr, (%/=), fileExists)
2526
import Prelude ((!!))
2627
import qualified System.IO as IO
@@ -185,9 +186,30 @@ writeInstallerNSIS outName (Version fullVersion') InstallerConfig{installDirecto
185186
createDirectory "$APPDATA\\$InstallDir\\Secrets-1.0"
186187
createDirectory "$APPDATA\\$InstallDir\\Logs"
187188
createDirectory "$APPDATA\\$InstallDir\\Logs\\pub"
188-
onError (delete [] "$APPDATA\\$InstallDir\\daedalus_lockfile") $
189-
--abort "$SpacedName $(AlreadyRunning)"
190-
unsafeInject $ T.unpack $ "Abort \" " <> installDirectory <> "$(AlreadyRunning)\""
189+
190+
-- XXX: sometimes during auto-update, it takes longer for Daedalus to exit,
191+
-- and cardano-launcher.exe’s lockfile to be unlocked (deletable), so
192+
-- let’s loop waiting for this to happen:
193+
let waitSeconds = 30
194+
lockfileCounter <- mutableInt_ 0
195+
lockfileDeleted <- mutable_ false
196+
while ((lockfileCounter %< waitSeconds) %&& (not_ lockfileDeleted)) $ do
197+
detailPrint (
198+
"Checking if Daedalus is not running ("
199+
Development.NSIS.& strShow (lockfileCounter + 1)
200+
Development.NSIS.& "/"
201+
Development.NSIS.& strShow waitSeconds
202+
Development.NSIS.& ")..."
203+
)
204+
lockfileDeleted @= true
205+
onError (delete [] "$APPDATA\\$InstallDir\\daedalus_lockfile") $ do
206+
lockfileDeleted @= false
207+
iff_ (not_ lockfileDeleted) $ do
208+
sleep 1000 -- milliseconds
209+
lockfileCounter @= lockfileCounter + 1
210+
iff_ (not_ (lockfileDeleted)) $ do
211+
unsafeInject $ T.unpack $ "Abort \"" <> installDirectory <> " $(AlreadyRunning)\""
212+
191213
iff_ (fileExists "$APPDATA\\$InstallDir\\Wallet-1.0\\open\\*.*") $
192214
rmdir [] "$APPDATA\\$InstallDir\\Wallet-1.0\\open"
193215
case oBackend of

0 commit comments

Comments
 (0)