From d82e189c0170b71789c80fd09419ee2060aaf58c Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Tue, 16 Feb 2021 14:37:17 +0100 Subject: [PATCH] Fix failed ghcup upgrade if destination dir doesn't exist Fixes #109 --- lib/GHCup.hs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/GHCup.hs b/lib/GHCup.hs index 661edbc..89cec6d 100644 --- a/lib/GHCup.hs +++ b/lib/GHCup.hs @@ -1314,12 +1314,17 @@ upgradeGHCup dls mtarget force pfreq = do tmp <- lift withGHCupTmpDir let fn = [rel|ghcup|] p <- liftE $ download dli tmp (Just fn) - let fullDest = fromMaybe (binDir fn) mtarget - liftIO $ hideError NoSuchThing $ deleteFile fullDest + let destDir = dirname destFile + destFile = fromMaybe (binDir fn) mtarget + lift $ $(logDebug) [i|mkdir -p #{toFilePath destDir}|] + liftIO $ createDirRecursive' destDir + lift $ $(logDebug) [i|rm -f #{toFilePath destFile}|] + liftIO $ hideError NoSuchThing $ deleteFile destFile + lift $ $(logDebug) [i|cp #{toFilePath p} #{toFilePath destFile}|] handleIO (throwE . CopyError . show) $ liftIO $ copyFile p - fullDest + destFile Overwrite - lift $ chmod_755 fullDest + lift $ chmod_755 destFile pure latestVer