From 77419ea41d7d6d00b390e913d3099f3e0b14c015 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Tue, 15 Nov 2022 21:30:19 +0800 Subject: [PATCH] Fix nuke bug on windows --- lib/GHCup.hs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/GHCup.hs b/lib/GHCup.hs index 2a3b248..f5d40b8 100644 --- a/lib/GHCup.hs +++ b/lib/GHCup.hs @@ -73,6 +73,7 @@ import Prelude hiding ( abs import System.Environment import System.FilePath import System.IO.Error +import System.IO.Temp import Text.Regex.Posix import qualified Data.Text as T @@ -133,6 +134,7 @@ rmTool :: ( MonadReader env m => ListResult -> Excepts '[NotInstalled, UninstallFailed] m () rmTool ListResult {lVer, lTool, lCross} = do + logInfo $ "removing " <> T.pack (show lTool) <> " version " <> prettyVer lVer case lTool of GHC -> let ghcTargetVersion = GHCTargetVersion lCross lVer @@ -364,11 +366,12 @@ rmGhcup = do if isWindows then do -- since it doesn't seem possible to delete a running exe on windows - -- we move it to temp dir, to be deleted at next reboot - tempFilepath <- mkGhcupTmpDir + -- we move it to system temp dir, to be deleted at next reboot + tmp <- liftIO $ getCanonicalTemporaryDirectory >>= \t -> createTempDirectory t "ghcup" + logDebug $ "mv " <> T.pack ghcupFilepath <> " " <> T.pack (tmp "ghcup") hideError UnsupportedOperation $ liftIO $ hideError NoSuchThing $ - moveFile ghcupFilepath (fromGHCupPath tempFilepath "ghcup") + moveFile ghcupFilepath (tmp "ghcup") else -- delete it. hideError doesNotExistErrorType $ rmFile ghcupFilepath