From ef0c94fddd79a0e748fbc75461ead48459c50873 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Sun, 13 Jun 2021 10:15:34 +0200 Subject: [PATCH] Fix windows upgrade for good --- ghcup-0.0.5.yaml | 2 +- lib/GHCup.hs | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ghcup-0.0.5.yaml b/ghcup-0.0.5.yaml index e8c90d5..9ab4d87 100644 --- a/ghcup-0.0.5.yaml +++ b/ghcup-0.0.5.yaml @@ -2047,7 +2047,7 @@ ghcupDownloads: Windows: unknown_versioning: dlUri: https://downloads.haskell.org/~ghcup/0.1.15.1/x86_64-mingw64-ghcup-0.1.15.1.exe - dlHash: 8fad2fb67b044ebd5075ee01fad6682a6f20791352c9ad1145189819b40b2383 + dlHash: 045bac4620fc9d1119ed4961aeba46b616ed572dd11b7d35b48caf58eea08d0f Linux_Alpine: unknown_versioning: *ghcup-64 A_32: diff --git a/lib/GHCup.hs b/lib/GHCup.hs index 7532b1a..a301d94 100644 --- a/lib/GHCup.hs +++ b/lib/GHCup.hs @@ -84,6 +84,9 @@ import qualified Data.ByteString.Lazy as BL import qualified Data.Map.Strict as Map import qualified Data.Text as T import qualified Data.Text.Encoding as E +#if defined(IS_WINDOWS) +import qualified System.Win32.File as Win32 +#endif import qualified Text.Megaparsec as MP import GHCup.Utils.MegaParsec import Control.Concurrent (threadDelay) @@ -1637,14 +1640,25 @@ upgradeGHCup mtarget force = do let fn = "ghcup" <> exeExt p <- liftE $ download settings dli tmp (Just fn) let destDir = takeDirectory destFile - destFile = fromMaybe (binDir (fn <> exeExt)) mtarget + destFile = fromMaybe (binDir fn <> exeExt) mtarget lift $ $(logDebug) [i|mkdir -p #{destDir}|] liftIO $ createDirRecursive' destDir +#if defined(IS_WINDOWS) + let tempGhcup = cacheDir "ghcup.old" + liftIO $ hideError NoSuchThing $ rmFile tempGhcup + + lift $ $(logDebug) [i|mv #{destFile} #{tempGhcup}|] + liftIO $ Win32.moveFileEx destFile (Just tempGhcup) 0 + lift $ $(logDebug) [i|cp #{p} #{destFile}|] + handleIO (throwE . CopyError . show) $ liftIO $ copyFile p + destFile +#else lift $ $(logDebug) [i|rm -f #{destFile}|] liftIO $ hideError NoSuchThing $ rmFile destFile lift $ $(logDebug) [i|cp #{p} #{destFile}|] handleIO (throwE . CopyError . show) $ liftIO $ copyFile p destFile +#endif lift $ chmod_755 destFile liftIO (isInPath destFile) >>= \b -> unless b $