Skip to content

Commit

Permalink
listInstalled: move side-effects away
Browse files Browse the repository at this point in the history
It's odd to create an empty directory just to list it, from a
function that merely lists the installed programs. Better to
have that directory created at the same place we may be writing
to it.
  • Loading branch information
da-x committed May 27, 2016
1 parent f627710 commit 2fda7a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/Stack/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ downloadAndInstallTool :: (MonadIO m, MonadMask m, MonadLogger m, MonadReader en
-> (SetupInfo -> Path Abs File -> ArchiveType -> Path Abs Dir -> m ())
-> m Tool
downloadAndInstallTool programsDir si downloadInfo tool installer = do
ensureDir programsDir
(file, at) <- downloadFromInfo programsDir downloadInfo tool
dir <- installDir programsDir tool
unmarkInstalled programsDir tool
Expand Down Expand Up @@ -749,6 +750,7 @@ downloadFromInfo programsDir downloadInfo tool = do
_ -> error $ "Unknown extension for url: " ++ T.unpack url
relfile <- parseRelFile $ toolString tool ++ extension
let path = programsDir </> relfile
ensureDir programsDir
chattyDownload (T.pack (toolString tool)) downloadInfo path
return (path, at)
where
Expand Down Expand Up @@ -1168,6 +1170,7 @@ setup7z :: (MonadReader env m, HasHttpManager env, HasConfig env, MonadThrow m,
-> m (Path Abs Dir -> Path Abs File -> n ())
setup7z si = do
dir <- asks $ configLocalPrograms . getConfig
ensureDir dir
let exe = dir </> $(mkRelFile "7z.exe")
dll = dir </> $(mkRelFile "7z.dll")
case (siSevenzDll si, siSevenzExe si) of
Expand Down
9 changes: 6 additions & 3 deletions src/Stack/Setup/Installed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE LambdaCase #-}

module Stack.Setup.Installed
( getCompilerVersion
, markInstalled
Expand Down Expand Up @@ -78,9 +80,10 @@ listInstalled :: (MonadIO m, MonadThrow m)
=> Path Abs Dir
-> m [Tool]
listInstalled programsPath = do
ensureDir programsPath
(_, files) <- listDir programsPath
return $ mapMaybe toTool files
doesDirExist programsPath >>= \case
False -> return []
True -> do (_, files) <- listDir programsPath
return $ mapMaybe toTool files
where
toTool fp = do
x <- T.stripSuffix ".installed" $ T.pack $ toFilePath $ filename fp
Expand Down

0 comments on commit 2fda7a8

Please sign in to comment.