From 8fc128e89b14602d062a649c7aa0d6f83ca023a0 Mon Sep 17 00:00:00 2001 From: Arjun Kathuria Date: Sun, 12 Sep 2021 09:24:04 +0530 Subject: [PATCH] move some code around for better consistency --- app/ghcup/Main.hs | 13 ++++++----- lib/GHCup.hs | 55 +++++++++++++++++++++++------------------------ 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/app/ghcup/Main.hs b/app/ghcup/Main.hs index 75d6e13..452f336 100644 --- a/app/ghcup/Main.hs +++ b/app/ghcup/Main.hs @@ -1783,17 +1783,20 @@ Report bugs at |] (case instBindist of Nothing -> runInstTool instPlatform $ do (v, vi) <- liftE $ fromVersion instVer Cabal - liftE $ installCabalBin (_tvVersion v) isolateDir forceInstall + liftE $ installCabalBin + (_tvVersion v) + isolateDir + forceInstall pure vi Just uri -> do s' <- appState runInstTool' s'{ settings = settings { noVerify = True}} instPlatform $ do (v, vi) <- liftE $ fromVersion instVer Cabal liftE $ installCabalBindist - (DownloadInfo uri Nothing "") - (_tvVersion v) - isolateDir - forceInstall + (DownloadInfo uri Nothing "") + (_tvVersion v) + isolateDir + forceInstall pure vi ) >>= \case diff --git a/lib/GHCup.hs b/lib/GHCup.hs index 92bc402..99e4cba 100644 --- a/lib/GHCup.hs +++ b/lib/GHCup.hs @@ -441,17 +441,17 @@ installCabalBindist dlinfo ver isoFilepath forceInstall = do regularCabalInstalled <- lift $ checkIfToolInstalled Cabal ver if + | not forceInstall + , regularCabalInstalled + , Nothing <- isoFilepath -> do + throwE $ AlreadyInstalled Cabal ver + | forceInstall , regularCabalInstalled , Nothing <- isoFilepath -> do lift $ logInfo $ "Removing the currently installed version first!" liftE $ rmCabalVer ver - | not forceInstall - , regularCabalInstalled - , Nothing <- isoFilepath -> do - throwE $ AlreadyInstalled Cabal ver - | otherwise -> pure () @@ -479,22 +479,6 @@ installCabalBindist dlinfo ver isoFilepath forceInstall = do let lInstCabal = headMay . reverse . sort $ cVers when (maybe True (ver >=) lInstCabal) $ liftE $ setCabal ver -checkIfToolInstalled :: ( MonadIO m - , MonadReader env m - , HasDirs env - , MonadCatch m) => - Tool -> - Version -> - m Bool - -checkIfToolInstalled tool ver = - case tool of - Cabal -> cabalInstalled ver - HLS -> hlsInstalled ver - Stack -> stackInstalled ver - GHC -> ghcInstalled $ mkTVer ver - _ -> pure False - -- | Install an unpacked cabal distribution.Symbol installCabalUnpacked :: (MonadCatch m, HasLog env, MonadIO m, MonadReader env m) => FilePath -- ^ Path to the unpacked cabal bindist (where the executable resides) @@ -598,17 +582,17 @@ installHLSBindist dlinfo ver isoFilepath forceInstall = do regularHLSInstalled <- lift $ checkIfToolInstalled HLS ver if - | forceInstall - , regularHLSInstalled - , Nothing <- isoFilepath -> do -- regular forced install - lift $ logInfo "Removing the currently installed version of HLS before force installing!" - liftE $ rmHLSVer ver - | not forceInstall , regularHLSInstalled - , Nothing <- isoFilepath -> do -- regular install + , Nothing <- isoFilepath -> do -- regular install throwE $ AlreadyInstalled HLS ver + | forceInstall + , regularHLSInstalled + , Nothing <- isoFilepath -> do -- regular forced install + lift $ logInfo "Removing the currently installed version of HLS before force installing!" + liftE $ rmHLSVer ver + | otherwise -> pure () -- download (or use cached version) @@ -2421,6 +2405,21 @@ whereIsTool tool ver@GHCTargetVersion {..} = do currentRunningExecPath <- liftIO getExecutablePath liftIO $ canonicalizePath currentRunningExecPath +checkIfToolInstalled :: ( MonadIO m + , MonadReader env m + , HasDirs env + , MonadCatch m) => + Tool -> + Version -> + m Bool + +checkIfToolInstalled tool ver = + case tool of + Cabal -> cabalInstalled ver + HLS -> hlsInstalled ver + Stack -> stackInstalled ver + GHC -> ghcInstalled $ mkTVer ver + _ -> pure False throwIfFileAlreadyExists :: ( MonadIO m ) => FilePath ->