swap checkFileAlreadyExists with throwIfFileAlreadyExists

This commit is contained in:
Arjun Kathuria 2021-08-24 20:39:07 +05:30
parent 8c486e8d46
commit df758d828b

View File

@ -484,8 +484,7 @@ installCabalUnpacked path inst mver' = do
<> exeExt <> exeExt
let destPath = inst </> destFileName let destPath = inst </> destFileName
whenM (checkFileAlreadyExists destPath) liftE $ throwIfFileAlreadyExists destPath
(throwE $ FileAlreadyExistsError destPath)
handleIO (throwE . CopyError . show) $ liftIO $ copyFile handleIO (throwE . CopyError . show) $ liftIO $ copyFile
(path </> cabalFile <> exeExt) (path </> cabalFile <> exeExt)
@ -628,8 +627,7 @@ installHLSUnpacked path inst mver' = do
let srcPath = path </> f let srcPath = path </> f
let destPath = inst </> toF let destPath = inst </> toF
whenM (checkFileAlreadyExists destPath) liftE $ throwIfFileAlreadyExists destPath
(throwE $ FileAlreadyExistsError destPath)
handleIO (throwE . CopyError . show) $ liftIO $ copyFile handleIO (throwE . CopyError . show) $ liftIO $ copyFile
srcPath srcPath
@ -644,8 +642,7 @@ installHLSUnpacked path inst mver' = do
srcWrapperPath = path </> wrapper <> exeExt srcWrapperPath = path </> wrapper <> exeExt
destWrapperPath = inst </> toF destWrapperPath = inst </> toF
whenM (checkFileAlreadyExists destWrapperPath) liftE $ throwIfFileAlreadyExists destWrapperPath
(throwE $ FileAlreadyExistsError destWrapperPath)
handleIO (throwE . CopyError . show) $ liftIO $ copyFile handleIO (throwE . CopyError . show) $ liftIO $ copyFile
srcWrapperPath srcWrapperPath
@ -815,8 +812,7 @@ installStackUnpacked path inst mver' = do
<> exeExt <> exeExt
destPath = inst </> destFileName destPath = inst </> destFileName
whenM (checkFileAlreadyExists destPath) liftE $ throwIfFileAlreadyExists destPath
(throwE $ FileAlreadyExistsError destPath)
handleIO (throwE . CopyError . show) $ liftIO $ copyFile handleIO (throwE . CopyError . show) $ liftIO $ copyFile
(path </> stackFile <> exeExt) (path </> stackFile <> exeExt)
@ -2380,4 +2376,10 @@ whereIsTool tool ver@GHCTargetVersion {..} = do
liftIO $ canonicalizePath currentRunningExecPath liftIO $ canonicalizePath currentRunningExecPath
throwIfFileAlreadyExists :: ( MonadIO m ) =>
FilePath ->
Excepts '[FileAlreadyExistsError] m ()
throwIfFileAlreadyExists fp = whenM (checkFileAlreadyExists fp)
(throwE $ FileAlreadyExistsError fp)