update installCabalBindist to take a "Maybe FilePath" argument for isolated installs

This commit is contained in:
Arjun Kathuria 2021-07-25 21:20:42 +05:30
parent 62d03b776b
commit 1f760af880

View File

@ -397,6 +397,7 @@ installCabalBindist :: ( MonadMask m
)
=> DownloadInfo
-> Version
-> Maybe FilePath -- ^ isolated install filepath, if user provides any.
-> Excepts
'[ AlreadyInstalled
, CopyError
@ -412,12 +413,16 @@ installCabalBindist :: ( MonadMask m
]
m
()
installCabalBindist dlinfo ver = do
installCabalBindist dlinfo ver isoFilepath = do
lift $ $(logDebug) [i|Requested to install cabal version #{ver}|]
PlatformRequest {..} <- lift getPlatformReq
Dirs {..} <- lift getDirs
let isIsolatedInstall = isJust isoFilepath
-- check if cabal already installed in regular (non-isolated) installs
when (not isIsolatedInstall) $
whenM
(lift (cabalInstalled ver) >>= \a -> liftIO $
handleIO (\_ -> pure False)
@ -438,9 +443,18 @@ installCabalBindist dlinfo ver = do
-- the subdir of the archive where we do the work
workdir <- maybe (pure tmpUnpack) (liftE . intoSubdir tmpUnpack) (view dlSubdir dlinfo)
let isoDir = fromJust isoFilepath
if isIsolatedInstall
then do
lift $ $(logInfo) [i|isolated installing Cabal to #{isoDir}|]
liftE $ installCabal' workdir isoDir ver
else do
liftE $ installCabal' workdir binDir ver
-- create symlink if this is the latest version
-- not applicable for isolated installs
whenM (pure $ not isIsolatedInstall) $ do
cVers <- lift $ fmap rights getInstalledCabals
let lInstCabal = headMay . reverse . sort $ cVers
when (maybe True (ver >=) lInstCabal) $ liftE $ setCabal ver