From c2c562568592f165c179e53d6f15b361429eedcc Mon Sep 17 00:00:00 2001 From: Arjun Kathuria Date: Wed, 11 Aug 2021 10:33:08 +0530 Subject: [PATCH] implements checking if file already exists for Cabal installs --- app/ghcup/BrickMain.hs | 1 + app/ghcup/Main.hs | 1 + lib/GHCup.hs | 7 ++++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/ghcup/BrickMain.hs b/app/ghcup/BrickMain.hs index e23724f..e79a9ea 100644 --- a/app/ghcup/BrickMain.hs +++ b/app/ghcup/BrickMain.hs @@ -442,6 +442,7 @@ install' _ (_, ListResult {..}) = do , DownloadFailed , NoUpdate , TarDirDoesNotExist + , FileAlreadyExistsError ] run (do diff --git a/app/ghcup/Main.hs b/app/ghcup/Main.hs index aef3ed7..183e257 100644 --- a/app/ghcup/Main.hs +++ b/app/ghcup/Main.hs @@ -1478,6 +1478,7 @@ Report bugs at |] , TarDirDoesNotExist , NextVerNotFound , NoToolVersionSet + , FileAlreadyExistsError ] let runInstTool mInstPlatform action' = do diff --git a/lib/GHCup.hs b/lib/GHCup.hs index da07ff2..8872e29 100644 --- a/lib/GHCup.hs +++ b/lib/GHCup.hs @@ -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 ()