Skip to content

Commit

Permalink
Tidy up the preferred-versions file parser
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoutts committed Oct 10, 2008
1 parent 06cb3a9 commit 38e211f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Distribution/Client/IndexUtils.hs
Expand Up @@ -45,6 +45,7 @@ import Distribution.Verbosity (Verbosity)
import Distribution.Simple.Utils (die, warn, info, intercalate, fromUTF8)

import Data.Maybe (catMaybes, fromMaybe)
import Data.List (isPrefixOf)
import Data.Monoid (Monoid(..))
import qualified Data.Map as Map
import Control.Monad (MonadPlus(mplus))
Expand Down Expand Up @@ -113,7 +114,7 @@ readRepoIndex verbosity repo = handleNotFound $ do
extractPrefs :: Tar.Entry -> Maybe [Dependency]
extractPrefs entry
| takeFileName (Tar.fileName entry) == "preferred-versions"
= Just . catMaybes . map simpleParse . lines
= Just . parsePreferredVersions
. BS.Char8.unpack . Tar.fileContent $ entry
| otherwise = Nothing

Expand All @@ -129,6 +130,12 @@ readRepoIndex verbosity repo = handleNotFound $ do
return mempty
else ioError e

parsePreferredVersions :: String -> [Dependency]
parsePreferredVersions = catMaybes
. map simpleParse
. filter (not . isPrefixOf "--")
. lines

-- | Read a compressed \"00-index.tar.gz\" file into a 'PackageIndex'.
--
-- This is supposed to be an \"all in one\" way to easily get at the info in
Expand Down

0 comments on commit 38e211f

Please sign in to comment.