hackage-db 1.7 → 1.8
raw patch · 2 files changed
+26/−32 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Distribution.Hackage.DB: hackagePath :: IO FilePath
Files
- hackage-db.cabal +2/−4
- src/Distribution/Hackage/DB.hs +24/−28
hackage-db.cabal view
@@ -1,5 +1,5 @@ Name: hackage-db-Version: 1.7+Version: 1.8 Copyright: Peter Simons License: BSD3 License-File: LICENSE@@ -10,7 +10,7 @@ Synopsis: provide access to the Hackage database via Data.Map Cabal-Version: >= 1.6 Build-Type: Simple-Tested-With: GHC >= 6.12.3 && <= 7.6.3+Tested-With: GHC >= 6.10.4 && <= 7.8.3 Description: This module provides simple access to the Hackage database by means of @Data.Map@. Suppose you wanted to implement a utility that queries@@ -51,5 +51,3 @@ hs-source-dirs: src Ghc-Options: -Wall Exposed-Modules: Distribution.Hackage.DB- if os(darwin)- Cpp-Options: -DIS_DARWIN
src/Distribution/Hackage/DB.hs view
@@ -1,20 +1,16 @@-{-# LANGUAGE CPP #-} {- | Module : Distribution.Hackage.DB License : BSD3- Maintainer : simons@cryp.to Stability : provisional Portability : portable This module provides simple access to the Hackage database by means- of 'Map'. Note that once the database has been parsed, it can be- accessed quickly, but the inital cost of reading @00-index.tar@ is- fairly high.+ of 'Map'. -} module Distribution.Hackage.DB- ( Hackage, readHackage, readHackage', parseHackage+ ( Hackage, readHackage, readHackage', parseHackage, hackagePath , module Data.Map , module Data.Version , module Distribution.Package@@ -22,19 +18,20 @@ ) where -import qualified Codec.Archive.Tar as Tar-import Data.ByteString.Lazy.Char8 ( ByteString )-import qualified Data.ByteString.Lazy.Char8 as BS8-import qualified Data.ByteString.Lazy as BSC-import Data.String.UTF8 ( toString, fromRep ) import Data.Map-import Data.Maybe import Data.Version-import System.Directory-import System.FilePath import Distribution.Package-import Distribution.Text import Distribution.PackageDescription++import qualified Codec.Archive.Tar as Tar+import Data.ByteString.Lazy.Char8 ( ByteString )+import qualified Data.ByteString.Lazy.Char8 as BS8 ( readFile )+import qualified Data.ByteString.Lazy as BSC ( unpack )+import Data.String.UTF8 ( toString, fromRep )+import Data.Maybe ( fromMaybe )+import System.Directory ( getHomeDirectory )+import System.FilePath ( joinPath, splitDirectories )+import Distribution.Text ( simpleParse ) import Distribution.PackageDescription.Parse ( parsePackageDescription, ParseResult(..) ) -- | A 'Map' representation of the Hackage database. For sake of@@ -43,21 +40,11 @@ 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.@@ -91,3 +78,12 @@ 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"]