use parseFeedFromFile to avoid mojibake
As mentioned in commit 2bd778a46e
, there
was mojibake when LANG=C.
Looking at parseFeedFromFile, it is very particular to read the file as
unicode. parseFeedString looks like it will accept any old String,
but a String that was read using the filesystem encoding will not in
fact have the right encoding.
I think this is a bug in the feed library and will file one.
Sponsored-by: Svenne Krap on Patreon
This commit is contained in:
parent
2bd778a46e
commit
332385a117
1 changed files with 26 additions and 23 deletions
|
@ -78,22 +78,29 @@ seek o = do
|
||||||
getFeed :: AddUnlockedMatcher -> ImportFeedOptions -> Cache -> URLString -> CommandSeek
|
getFeed :: AddUnlockedMatcher -> ImportFeedOptions -> Cache -> URLString -> CommandSeek
|
||||||
getFeed addunlockedmatcher opts cache url = do
|
getFeed addunlockedmatcher opts cache url = do
|
||||||
showStartOther "importfeed" (Just url) (SeekInput [])
|
showStartOther "importfeed" (Just url) (SeekInput [])
|
||||||
downloadFeed url >>= \case
|
withTmpFile "feed" $ \tmpf h -> do
|
||||||
Nothing -> showEndResult =<< feedProblem url
|
liftIO $ hClose h
|
||||||
"downloading the feed failed"
|
ifM (downloadFeed url tmpf)
|
||||||
Just feedcontent -> case parseFeedString feedcontent of
|
( go tmpf
|
||||||
Nothing -> debugfeedcontent feedcontent "parsing the feed failed"
|
, showEndResult =<< feedProblem url
|
||||||
Just f -> case findDownloads url f of
|
"downloading the feed failed"
|
||||||
[] -> debugfeedcontent feedcontent "bad feed content; no enclosures to download"
|
)
|
||||||
l -> do
|
|
||||||
showEndOk
|
|
||||||
ifM (and <$> mapM (performDownload addunlockedmatcher opts cache) l)
|
|
||||||
( clearFeedProblem url
|
|
||||||
, void $ feedProblem url
|
|
||||||
"problem downloading some item(s) from feed"
|
|
||||||
)
|
|
||||||
where
|
where
|
||||||
debugfeedcontent feedcontent msg = do
|
-- Use parseFeedFromFile rather than reading the file
|
||||||
|
-- ourselves because it goes out of its way to handle encodings.
|
||||||
|
go tmpf = liftIO (parseFeedFromFile tmpf) >>= \case
|
||||||
|
Nothing -> debugfeedcontent tmpf "parsing the feed failed"
|
||||||
|
Just f -> case findDownloads url f of
|
||||||
|
[] -> debugfeedcontent tmpf "bad feed content; no enclosures to download"
|
||||||
|
l -> do
|
||||||
|
showEndOk
|
||||||
|
ifM (and <$> mapM (performDownload addunlockedmatcher opts cache) l)
|
||||||
|
( clearFeedProblem url
|
||||||
|
, void $ feedProblem url
|
||||||
|
"problem downloading some item(s) from feed"
|
||||||
|
)
|
||||||
|
debugfeedcontent tmpf msg = do
|
||||||
|
feedcontent <- liftIO $ readFile tmpf
|
||||||
fastDebug "Command.ImportFeed" $ unlines
|
fastDebug "Command.ImportFeed" $ unlines
|
||||||
[ "start of feed content"
|
[ "start of feed content"
|
||||||
, feedcontent
|
, feedcontent
|
||||||
|
@ -170,15 +177,11 @@ findDownloads u f = catMaybes $ map mk (feedItems f)
|
||||||
Nothing -> Nothing
|
Nothing -> Nothing
|
||||||
|
|
||||||
{- Feeds change, so a feed download cannot be resumed. -}
|
{- Feeds change, so a feed download cannot be resumed. -}
|
||||||
downloadFeed :: URLString -> Annex (Maybe String)
|
downloadFeed :: URLString -> FilePath -> Annex Bool
|
||||||
downloadFeed url
|
downloadFeed url f
|
||||||
| Url.parseURIRelaxed url == Nothing = giveup "invalid feed url"
|
| Url.parseURIRelaxed url == Nothing = giveup "invalid feed url"
|
||||||
| otherwise = withTmpFile "feed" $ \f h -> do
|
| otherwise = Url.withUrlOptions $
|
||||||
liftIO $ hClose h
|
Url.download nullMeterUpdate Nothing url f
|
||||||
ifM (Url.withUrlOptions $ Url.download nullMeterUpdate Nothing url f)
|
|
||||||
( Just <$> liftIO (readFileStrict f)
|
|
||||||
, return Nothing
|
|
||||||
)
|
|
||||||
|
|
||||||
performDownload :: AddUnlockedMatcher -> ImportFeedOptions -> Cache -> ToDownload -> Annex Bool
|
performDownload :: AddUnlockedMatcher -> ImportFeedOptions -> Cache -> ToDownload -> Annex Bool
|
||||||
performDownload addunlockedmatcher opts cache todownload = case location todownload of
|
performDownload addunlockedmatcher opts cache todownload = case location todownload of
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue