add readFileStrictAnyEncoding
This commit is contained in:
parent
beaa7cb757
commit
94251de91e
3 changed files with 12 additions and 6 deletions
|
@ -67,9 +67,5 @@ getLogR :: Handler Html
|
||||||
getLogR = page "Logs" Nothing $ do
|
getLogR = page "Logs" Nothing $ do
|
||||||
logfile <- liftAnnex $ fromRepo gitAnnexLogFile
|
logfile <- liftAnnex $ fromRepo gitAnnexLogFile
|
||||||
logs <- liftIO $ listLogs logfile
|
logs <- liftIO $ listLogs logfile
|
||||||
logcontent <- liftIO $ concat <$> mapM readlog logs
|
logcontent <- liftIO $ concat <$> mapM readFileStrictAnyEncoding logs
|
||||||
$(widgetFile "control/log")
|
$(widgetFile "control/log")
|
||||||
where
|
|
||||||
readlog f = withFile f ReadMode $ \h -> do
|
|
||||||
fileEncoding h -- log may contain invalid utf-8
|
|
||||||
hClose h `after` hGetContentsStrict h
|
|
||||||
|
|
|
@ -106,7 +106,7 @@ downloadFeed url = do
|
||||||
liftIO $ withTmpFile "feed" $ \f h -> do
|
liftIO $ withTmpFile "feed" $ \f h -> do
|
||||||
fileEncoding h
|
fileEncoding h
|
||||||
ifM (Url.download url [] [] f ua)
|
ifM (Url.download url [] [] f ua)
|
||||||
( liftIO $ parseFeedString <$> hGetContentsStrict h
|
( parseFeedString <$> hGetContentsStrict h
|
||||||
, return Nothing
|
, return Nothing
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,9 @@ import System.Posix.Process (getAnyProcessStatus)
|
||||||
import Utility.Exception
|
import Utility.Exception
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
import Utility.FileSystemEncoding
|
||||||
|
import Utility.Monad
|
||||||
|
|
||||||
{- A version of hgetContents that is not lazy. Ensures file is
|
{- A version of hgetContents that is not lazy. Ensures file is
|
||||||
- all read before it gets closed. -}
|
- all read before it gets closed. -}
|
||||||
hGetContentsStrict :: Handle -> IO String
|
hGetContentsStrict :: Handle -> IO String
|
||||||
|
@ -30,6 +33,13 @@ hGetContentsStrict = hGetContents >=> \s -> length s `seq` return s
|
||||||
readFileStrict :: FilePath -> IO String
|
readFileStrict :: FilePath -> IO String
|
||||||
readFileStrict = readFile >=> \s -> length s `seq` return s
|
readFileStrict = readFile >=> \s -> length s `seq` return s
|
||||||
|
|
||||||
|
{- Reads a file strictly, and using the FileSystemEncofing, so it will
|
||||||
|
- never crash on a badly encoded file. -}
|
||||||
|
readFileStrictAnyEncoding :: FilePath -> IO String
|
||||||
|
readFileStrictAnyEncoding f = withFile f ReadMode $ \h -> do
|
||||||
|
fileEncoding h
|
||||||
|
hClose h `after` hGetContentsStrict h
|
||||||
|
|
||||||
{- Like break, but the item matching the condition is not included
|
{- Like break, but the item matching the condition is not included
|
||||||
- in the second result list.
|
- in the second result list.
|
||||||
-
|
-
|
||||||
|
|
Loading…
Reference in a new issue