From be82565775f398d0f8aa1f6edb412cf90528ead3 Mon Sep 17 00:00:00 2001 From: Arjun Kathuria Date: Mon, 30 Aug 2021 15:20:33 +0530 Subject: [PATCH] factor out `checkIfCabalInstalled` to `checkIfToolInstalled` --- lib/GHCup.hs | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/GHCup.hs b/lib/GHCup.hs index bc0ead8..07c6f7d 100644 --- a/lib/GHCup.hs +++ b/lib/GHCup.hs @@ -423,9 +423,6 @@ installCabalBindist dlinfo ver isoFilepath forceInstall = do PlatformRequest {..} <- lift getPlatformReq Dirs {..} <- lift getDirs - -- check if we already have a regular cabal already installed - regularCabalInstalled <- checkIfCabalInstalled ver binDir exeExt - -- check if we already have a regular cabal already installed regularCabalInstalled <- lift $ checkIfToolInstalled Cabal ver @@ -468,17 +465,28 @@ installCabalBindist dlinfo ver isoFilepath forceInstall = do let lInstCabal = headMay . reverse . sort $ cVers when (maybe True (ver >=) lInstCabal) $ liftE $ setCabal ver - where +checkIfToolInstalled :: ( MonadIO m + , MonadLogger m + , MonadReader env m + , HasDirs env + , MonadCatch m) => + Tool -> + Version -> + m Bool - checkIfCabalInstalled ver binDir exeExt = (lift (cabalInstalled ver) >>= \a -> liftIO $ - handleIO (\_ -> pure False) - $ fmap (\x -> a && x) - -- ignore when the installation is a legacy cabal (binary, not symlink) - $ pathIsLink (binDir "cabal" <> exeExt) - ) +checkIfToolInstalled tool ver = do + Dirs { binDir } <- getDirs + case tool of + Cabal -> do + v <- cabalInstalled ver + liftIO $ handleIO (\_ -> pure False) + $ fmap (\x -> v && x) + $ pathIsLink (binDir "cabal" <> exeExt) --- | Install an unpacked cabal distribution. + _ -> pure False + +-- | Install an unpacked cabal distribution.Symbol installCabalUnpacked :: (MonadLogger m, MonadCatch m, MonadIO m) => FilePath -- ^ Path to the unpacked cabal bindist (where the executable resides) -> FilePath -- ^ Path to install to