Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1768 Remove tool archive file after installation #6507

Merged
merged 1 commit into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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