diff --git a/ChangeLog.md b/ChangeLog.md index 4a54b9bf72..57592f7434 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -19,6 +19,8 @@ Behavior changes: up Stack's environment. * The `init` command initialises `stack.yaml` with a `snapshot` key rather than a `resolver` key. +* After installing GHC or another tool, Stack deletes the archive file which + provided the tool. Other enhancements: diff --git a/src/Stack/Setup.hs b/src/Stack/Setup.hs index a2be754b6e..45376e26d5 100644 --- a/src/Stack/Setup.hs +++ b/src/Stack/Setup.hs @@ -78,7 +78,8 @@ import Path.Extra ( toFilePathNoTrailingSep ) import Path.IO ( canonicalizePath, doesFileExist, ensureDir, executable , getPermissions, ignoringAbsence, listDir, removeDirRecur - , renameDir, renameFile, resolveFile', withTempDir + , removeFile, renameDir, renameFile, resolveFile' + , withTempDir ) import RIO.List ( headMaybe, intercalate, intersperse, isPrefixOf @@ -1934,17 +1935,28 @@ getInstalledTool :: getInstalledTool installed name goodVersion = Tool <$> maximumByMaybe (comparing pkgVersion) (filterTools name goodVersion installed) +-- | Obtain and install the specified tool, using the specified download +-- information and installer. Also deletes the archive file for the tool after +-- installation. downloadAndInstallTool :: (HasTerm env, HasBuildConfig env) => Path Abs Dir + -- ^ Location of the directory for tools. -> DownloadInfo + -- ^ Information about the file to obtain. -> Tool + -- ^ The tool in question. -> ( Path Abs File + -- Location of archive file. -> ArchiveType + -- Type of archive file. -> Path Abs Dir + -- Tempory directory to use. -> Path Abs Dir + -- Destination directory for installed tool. -> RIO env () ) + -- ^ Installer. -> RIO env Tool downloadAndInstallTool programsDir downloadInfo tool installer = do ensureDir programsDir @@ -1957,6 +1969,7 @@ downloadAndInstallTool programsDir downloadInfo tool installer = do installer file at tempDir dir markInstalled programsDir tool liftIO $ ignoringAbsence (removeDirRecur tempDir) + liftIO $ ignoringAbsence (removeFile file) pure tool -- Exceptions thrown by this function are caught by diff --git a/src/Stack/Types/CompilerBuild.hs b/src/Stack/Types/CompilerBuild.hs index 225827aed6..4a17234aeb 100644 --- a/src/Stack/Types/CompilerBuild.hs +++ b/src/Stack/Types/CompilerBuild.hs @@ -11,6 +11,7 @@ import Data.Aeson.Types ( FromJSON, parseJSON, withText ) import Data.Text as T import Stack.Prelude +-- | Build of the compiler distribution (e.g. standard, gmp4, tinfo6) data CompilerBuild = CompilerBuildStandard | CompilerBuildSpecialized String diff --git a/src/Stack/Types/DownloadInfo.hs b/src/Stack/Types/DownloadInfo.hs index bd35445660..2a97b2dd45 100644 --- a/src/Stack/Types/DownloadInfo.hs +++ b/src/Stack/Types/DownloadInfo.hs @@ -14,7 +14,6 @@ import Data.Aeson.WarningParser ) import Stack.Prelude --- | Build of the compiler distribution (e.g. standard, gmp4, tinfo6) -- | Information for a file to download. data DownloadInfo = DownloadInfo { url :: Text