From 0f78b4db09c3b8ca6bf3895783f134e002c3c699 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 21 Apr 2019 10:35:08 -0400 Subject: [PATCH] distinguish between feed download and parse failures --- Command/ImportFeed.hs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Command/ImportFeed.hs b/Command/ImportFeed.hs index 7a7f3bd07d..c082fcfaff 100644 --- a/Command/ImportFeed.hs +++ b/Command/ImportFeed.hs @@ -77,13 +77,15 @@ perform :: ImportFeedOptions -> Cache -> URLString -> CommandPerform perform opts cache url = go =<< downloadFeed url where go Nothing = next $ feedProblem url "downloading the feed failed" - go (Just f) = case findDownloads url f of - [] -> next $ - feedProblem url "bad feed content; no enclosures to download" - l -> do - showOutput - ok <- and <$> mapM (performDownload opts cache) l - next $ cleanup url ok + go (Just feedcontent) = case parseFeedString feedcontent of + Nothing -> next $ feedProblem url "parsing the feed failed" + Just f -> case findDownloads url f of + [] -> next $ + feedProblem url "bad feed content; no enclosures to download" + l -> do + showOutput + ok <- and <$> mapM (performDownload opts cache) l + next $ cleanup url ok cleanup :: URLString -> Bool -> CommandCleanup cleanup url True = do @@ -142,14 +144,14 @@ findDownloads u f = catMaybes $ map mk (feedItems f) Nothing -> Nothing {- Feeds change, so a feed download cannot be resumed. -} -downloadFeed :: URLString -> Annex (Maybe Feed) +downloadFeed :: URLString -> Annex (Maybe String) downloadFeed url | Url.parseURIRelaxed url == Nothing = giveup "invalid feed url" | otherwise = Url.withUrlOptions $ \uo -> liftIO $ withTmpFile "feed" $ \f h -> do hClose h ifM (Url.download nullMeterUpdate url f uo) - ( parseFeedString <$> readFileStrict f + ( Just <$> readFileStrict f , return Nothing )