implements checking if file already exists for Cabal installs

This commit is contained in:
Arjun Kathuria 2021-08-11 10:33:08 +05:30
parent ce6fb0bb1e
commit c2c5625685
3 changed files with 8 additions and 1 deletions

View File

@ -442,6 +442,7 @@ install' _ (_, ListResult {..}) = do
, DownloadFailed
, NoUpdate
, TarDirDoesNotExist
, FileAlreadyExistsError
]
run (do

View File

@ -1478,6 +1478,7 @@ Report bugs at <https://gitlab.haskell.org/haskell/ghcup-hs/issues>|]
, TarDirDoesNotExist
, NextVerNotFound
, NoToolVersionSet
, FileAlreadyExistsError
]
let runInstTool mInstPlatform action' = do

View File

@ -405,6 +405,7 @@ installCabalBindist :: ( MonadMask m
#if !defined(TAR)
, ArchiveResult
#endif
, FileAlreadyExistsError
]
m
()
@ -456,13 +457,16 @@ installCabalUnpacked :: (MonadLogger m, MonadCatch m, MonadIO m)
=> FilePath -- ^ Path to the unpacked cabal bindist (where the executable resides)
-> FilePath -- ^ Path to install to
-> Version
-> Excepts '[CopyError] m ()
-> Excepts '[CopyError, FileAlreadyExistsError] m ()
installCabalUnpacked path inst ver = do
lift $ $(logInfo) "Installing cabal"
let cabalFile = "cabal"
liftIO $ createDirRecursive' inst
let destFileName = cabalFile <> "-" <> T.unpack (prettyVer ver) <> exeExt
let destPath = inst </> destFileName
whenM
(liftIO $ doesFileExist destPath)
(throwE $ FileAlreadyExistsError destPath)
handleIO (throwE . CopyError . show) $ liftIO $ copyFile
(path </> cabalFile <> exeExt)
destPath
@ -498,6 +502,7 @@ installCabalBin :: ( MonadMask m
#if !defined(TAR)
, ArchiveResult
#endif
, FileAlreadyExistsError
]
m
()