From 16d4a28454d92bbe73c87f7e443c5e53fa7da88a Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Tue, 7 Jul 2020 13:39:58 -0400 Subject: [PATCH] Simplify upgrade copying logic --- lib/GHCup.hs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/lib/GHCup.hs b/lib/GHCup.hs index c9adfd0..2a122da 100644 --- a/lib/GHCup.hs +++ b/lib/GHCup.hs @@ -929,20 +929,12 @@ upgradeGHCup dls mtarget force = do `unionFileModes` otherExecuteMode binDir <- liftIO $ ghcupBinDir liftIO $ createDirIfMissing newDirPerms binDir - case mtarget of - Nothing -> do - dest <- liftIO $ ghcupBinDir - liftIO $ hideError NoSuchThing $ deleteFile (dest fn) - handleIO (throwE . CopyError . show) $ liftIO $ copyFile p - (dest fn) - Overwrite - liftIO $ setFileMode (toFilePath (dest fn)) fileMode' - Just fullDest -> do - liftIO $ hideError NoSuchThing $ deleteFile fullDest - handleIO (throwE . CopyError . show) $ liftIO $ copyFile p - fullDest - Overwrite - liftIO $ setFileMode (toFilePath fullDest) fileMode' + let fullDest = fromMaybe (binDir fn) mtarget + liftIO $ hideError NoSuchThing $ deleteFile fullDest + handleIO (throwE . CopyError . show) $ liftIO $ copyFile p + fullDest + Overwrite + liftIO $ setFileMode (toFilePath fullDest) fileMode' pure latestVer