Skip to content

Commit

Permalink
Fix #1768 Remove tool archive file after installation
Browse files Browse the repository at this point in the history
Also corrects some Haddock documentation
  • Loading branch information
mpilgrem committed Mar 3, 2024
1 parent 6a629ac commit 62c733d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
15 changes: 14 additions & 1 deletion src/Stack/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/Stack/Types/CompilerBuild.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/Stack/Types/DownloadInfo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 62c733d

Please sign in to comment.