Skip to content

Commit

Permalink
When marking exe installed, remove old vers #2175
Browse files Browse the repository at this point in the history
+ Ignore installed exe info when it's ambiguous
  • Loading branch information
mgsloan committed Aug 12, 2016
1 parent 90103f6 commit 41fce01
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/Stack/Build/Cache.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import qualified Data.ByteString.Char8 as S8
import qualified Data.ByteString.Lazy as LBS
import Data.Foldable (forM_)
import Data.Map (Map)
import qualified Data.Map as M
import Data.Maybe (fromMaybe, mapMaybe)
import Data.Monoid ((<>))
import Data.Set (Set)
Expand Down Expand Up @@ -83,16 +84,29 @@ getInstalledExes :: (MonadReader env m, HasEnvConfig env, MonadIO m, MonadThrow
getInstalledExes loc = do
dir <- exeInstalledDir loc
(_, files) <- liftIO $ handleIO (const $ return ([], [])) $ listDir dir
return $ mapMaybe (parsePackageIdentifierFromString . toFilePath . filename) files
return $
concat $
M.elems $
-- If there are multiple install records (from a stack version
-- before https://github.com/commercialhaskell/stack/issues/2373
-- was fixed), then we don't know which is correct - ignore them.
M.fromListWith (\_ _ -> []) $
map (\x -> (packageIdentifierName x, [x])) $
mapMaybe (parsePackageIdentifierFromString . toFilePath . filename) files

-- | Mark the given executable as installed
markExeInstalled :: (MonadReader env m, HasEnvConfig env, MonadIO m, MonadThrow m)
markExeInstalled :: (MonadReader env m, HasEnvConfig env, MonadIO m, MonadCatch m)
=> InstallLocation -> PackageIdentifier -> m ()
markExeInstalled loc ident = do
dir <- exeInstalledDir loc
ensureDir dir
ident' <- parseRelFile $ packageIdentifierString ident
let fp = toFilePath $ dir </> ident'
-- Remove old install records for this package.
-- TODO: This is a bit in-efficient. Put all this metadata into one file?
installed <- getInstalledExes loc
forM_ (filter (\x -> packageIdentifierName ident == packageIdentifierName x) installed)
(markExeNotInstalled loc)
-- TODO consideration for the future: list all of the executables
-- installed, and invalidate this file in getInstalledExes if they no
-- longer exist
Expand Down

1 comment on commit 41fce01

@Blaisorblade
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah #2175 is a typo—the fixed commit is e05e5d8, linking to #2373.

Please sign in to comment.