Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Distribution.Hackage.DB: re-factor the code that finds the "00-index.…
…tar" file into a separate function, hackagePath, and export it

Suggested in <#3>.
  • Loading branch information
peti committed Jul 31, 2014
1 parent 599acad commit 62190d6
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/Distribution/Hackage/DB.hs
Expand Up @@ -13,7 +13,7 @@
-}

module Distribution.Hackage.DB
( Hackage, readHackage, readHackage', parseHackage
( Hackage, readHackage, readHackage', parseHackage, hackagePath
, module Data.Map
, module Data.Version
, module Distribution.Package
Expand Down Expand Up @@ -42,21 +42,11 @@ import Distribution.PackageDescription.Parse ( parsePackageDescription, ParseRes

type Hackage = Map String (Map Version GenericPackageDescription)

-- | Read the Hackage database from
-- @$HOME\/@/<package database path>/@\/hackage.haskell.org\/00-index.tar@ and
-- return a 'Map' that provides fast access to its contents. That @tar@
-- file is typically created by running the command @\"cabal update\"@.
-- | Read the Hackage database from the location determined by 'hackagePath'
-- and return a 'Map' that provides fast access to its contents.

readHackage :: IO Hackage
readHackage = do
homedir <- getHomeDirectory
readHackage' (joinPath [ homedir,
#ifdef IS_DARWIN
"Library", "Haskell", "repo-cache"
#else
".cabal", "packages"
#endif
, "hackage.haskell.org", "00-index.tar" ])
readHackage = hackagePath >>= readHackage'

-- | Read the Hackage database from the given 'FilePath' and return a
-- 'Hackage' map that provides fast access to its contents.
Expand Down Expand Up @@ -90,3 +80,12 @@ parseHackage = Tar.foldEntries addEntry empty (error . show) . Tar.read

pVersion :: String -> Version
pVersion str = fromMaybe (error $ "Hackage.DB.parseHackage: cannot parse version " ++ show str) (simpleParse str)

-- | Determine the default path of the Hackage database, which typically
-- resides at @"$HOME\/.cabal\/packages\/hackage.haskell.org\/00-index.tar"@.
-- Running the command @"cabal update"@ will keep that file up-to-date.

hackagePath :: IO FilePath
hackagePath = do
homedir <- getHomeDirectory
return $ joinPath [homedir, ".cabal", "packages", "hackage.haskell.org", "00-index.tar"]

0 comments on commit 62190d6

Please sign in to comment.