From 9f5df9db1009fe8d21ff85c94bf3605aa63fba6f Mon Sep 17 00:00:00 2001 From: Arjun Kathuria Date: Fri, 25 Jun 2021 15:06:02 +0530 Subject: [PATCH] Adds conditional windows ghcup bin removal code. Todo: test it, add more exception handling if required. --- lib/GHCup.hs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/GHCup.hs b/lib/GHCup.hs index d9f3e3a..3aa0138 100644 --- a/lib/GHCup.hs +++ b/lib/GHCup.hs @@ -1284,14 +1284,24 @@ rmStackVer ver = do -- assuming the current scheme of having just 1 ghcup bin, no version info is required. rmGhcup :: ( MonadReader AppState m - , MonadIO m + , MonadIO m, + MonadCatch m ) => Excepts '[NotInstalled] m () rmGhcup = do AppState {dirs = Dirs {binDir}} <- lift ask - let ghcupFile = "ghcup" <> exeExt - liftIO $ hideError doesNotExistErrorType $ rmFile (binDir ghcupFile) + let ghcupFilename = "ghcup" <> exeExt + let ghcupFilepath = binDir ghcupFilename +#if defined(IS_WINDOWS) + -- since it doesn't seem possible to delete a running exec in windows + -- we move it to temp dir, to be deleted at next reboot + tempDir <- liftIO $ getTemporaryDirectory + tempFilepath = tempDir ghcupFilename + hideError doesNotExistErrorType $ liftIO $ renameFile ghcupFilepath tempFilepath +#else + hideError doesNotExistErrorType $ liftIO $ rmFile ghcupFilepath +#endif rmTool :: ( MonadReader AppState m , MonadLogger m