From 340ebbd92574145c9010ec680b64c16845a5e427 Mon Sep 17 00:00:00 2001 From: Tommaso Piazza Date: Wed, 5 Apr 2017 01:27:24 +0200 Subject: [PATCH] Skipping malformed lines in Cartfile.resolved --- Rome.cabal | 2 +- app/Main.hs | 2 +- src/Configuration.hs | 2 +- src/Data/Carthage/Cartfile.hs | 15 +++++++++++---- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Rome.cabal b/Rome.cabal index 429514d..3dfc8a5 100644 --- a/Rome.cabal +++ b/Rome.cabal @@ -1,5 +1,5 @@ name: Rome -version: 0.10.1.22 +version: 0.10.2.23 synopsis: An S3 cache for Carthage description: Please see README.md homepage: https://github.com/blender/Rome diff --git a/app/Main.hs b/app/Main.hs index 2b23b12..be08704 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -9,7 +9,7 @@ import Options.Applicative as Opts romeVersion :: String -romeVersion = "0.10.1.22" +romeVersion = "0.10.2.23" diff --git a/src/Configuration.hs b/src/Configuration.hs index 4b30a0f..5c95c18 100644 --- a/src/Configuration.hs +++ b/src/Configuration.hs @@ -12,7 +12,7 @@ import Types getCartfileEntires :: RomeMonad [CartfileEntry] getCartfileEntires = do - eitherCartfileEntries <- liftIO $ parseCartfileResolved cartfileResolved + eitherCartfileEntries <- parseCartfileResolved cartfileResolved case eitherCartfileEntries of Left e -> throwError $ "Carfile.resolved parse error: " ++ show e Right cartfileEntries -> return cartfileEntries diff --git a/src/Data/Carthage/Cartfile.hs b/src/Data/Carthage/Cartfile.hs index e9f47ad..0b0cae6 100644 --- a/src/Data/Carthage/Cartfile.hs +++ b/src/Data/Carthage/Cartfile.hs @@ -16,7 +16,10 @@ import qualified Text.Parsec as Parsec import qualified Text.Parsec.String as Parsec import qualified Text.Parsec.Utils as Parsec +import Control.Monad.Trans (MonadIO, liftIO) import Data.Carthage.Common +import Data.Maybe (fromJust, isJust) + newtype Location = Location { unLocation :: String } deriving (Eq, Show, Ord) @@ -45,7 +48,7 @@ parseGit :: Parsec.Parsec String () RepoHosting parseGit = Parsec.string "git" >> Parsec.many1 Parsec.space >> pure Git repoHosting :: Parsec.Parsec String () RepoHosting -repoHosting = Parsec.try parseGit <|> parseGitHub +repoHosting = Parsec.try parseGit <|> Parsec.try parseGitHub quotedContent :: Parsec.Parsec String () String quotedContent = do @@ -60,8 +63,12 @@ parseCartfileResolvedLine = do location <- fmap Location quotedContent Parsec.many1 Parsec.space version <- fmap Version quotedContent - Parsec.endOfLine return CartfileEntry {..} -parseCartfileResolved :: String -> IO (Either Parsec.ParseError [CartfileEntry]) -parseCartfileResolved = Parsec.parseFromFile (Parsec.many1 (Parsec.optional Parsec.spaces >> parseCartfileResolvedLine)) +parseCartfileResolved :: MonadIO m => String -> m (Either Parsec.ParseError [CartfileEntry]) +parseCartfileResolved f = liftIO $ do + parseResult <- Parsec.parseFromFile (Parsec.many1 (Parsec.optional Parsec.spaces + >> Parsec.optionMaybe parseCartfileResolvedLine + >>= \cartFileLines -> Parsec.manyTill Parsec.anyChar Parsec.endOfLine + >> return cartFileLines)) f + return $ parseResult >>= \r -> pure [fromJust x | x <- r, isJust x]