packdeps 0.0.0 → 0.0.1
raw patch · 2 files changed
+24/−5 lines, 2 filesdep +filepath
Dependencies added: filepath
Files
- Distribution/PackDeps.hs +22/−4
- packdeps.cabal +2/−1
Distribution/PackDeps.hs view
@@ -18,10 +18,11 @@ ) where import System.Directory (getAppUserDataDirectory)+import System.FilePath ((</>)) import qualified Data.Map as Map-import Data.List (foldl', group, sort, isInfixOf)+import Data.List (foldl', group, sort, isInfixOf, isPrefixOf) import Data.Time (UTCTime (UTCTime), addUTCTime)-import Data.Maybe (mapMaybe)+import Data.Maybe (mapMaybe, catMaybes) import Distribution.Package import Distribution.PackageDescription@@ -42,9 +43,23 @@ loadNewest :: IO Newest loadNewest = do c <- getAppUserDataDirectory "cabal"- let fn = c ++ "/packages/hackage.haskell.org/00-index.tar"- loadNewestFrom fn+ cfg <- readFile (c </> "config")+ let repos = reposFromConfig cfg+ tarName repo = c </> "packages" </> repo </> "00-index.tar"+ fmap (Map.unionsWith maxVersion) . mapM (loadNewestFrom . tarName) $ repos +reposFromConfig :: String -> [String]+reposFromConfig = map (takeWhile (/= ':'))+ . catMaybes+ . map (dropPrefix "remote-repo: ")+ . lines++dropPrefix :: (Eq a) => [a] -> [a] -> Maybe [a]+dropPrefix prefix s =+ if prefix `isPrefixOf` s+ then Just . drop (length prefix) $ s+ else Nothing+ loadNewestFrom :: FilePath -> IO Newest loadNewestFrom = fmap parseNewest . L.readFile @@ -87,6 +102,9 @@ , piEpoch :: Tar.EpochTime } deriving (Show, Read)++maxVersion :: PackInfo -> PackInfo -> PackInfo+maxVersion pi1 pi2 = if piVersion pi1 <= piVersion pi2 then pi2 else pi1 -- | The newest version of every package. type Newest = Map.Map String PackInfo
packdeps.cabal view
@@ -1,5 +1,5 @@ name: packdeps-version: 0.0.0+version: 0.0.1 license: BSD3 license-file: LICENSE author: Michael Snoyman <michael@snoyman.com>@@ -25,6 +25,7 @@ , time >= 1.1.4 && < 1.3 , containers >= 0.2 && < 0.5 , directory >= 1.0 && < 1.2+ , filepath >= 1.1 && < 1.3 exposed-modules: Distribution.PackDeps ghc-options: -Wall