factor out `checkIfCabalInstalled` to `checkIfToolInstalled`

This commit is contained in:
Arjun Kathuria 2021-08-30 15:20:33 +05:30
parent f8d0243146
commit be82565775
1 changed files with 19 additions and 11 deletions

View File

@ -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