aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFélix Sipma <felix.sipma@no-log.org>2019-08-08 17:57:08 +0200
committerFélix Sipma <felix.sipma@no-log.org>2019-08-08 17:57:08 +0200
commit840162a7e6c5107c1e52c60aac487e3c5f83ae47 (patch)
treeffc087f38d3c29959db537ebdb955ed7c968011b
parent2bdd2fe95c6f7fa85c290bae8fe4eaeecdccb643 (diff)
Filter: use Text instead of String for filter command line arguments
-rw-r--r--src/Filter.hs18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/Filter.hs b/src/Filter.hs
index 9284c11..aba3bfd 100644
--- a/src/Filter.hs
+++ b/src/Filter.hs
@@ -16,7 +16,6 @@ import Control.Monad ( fail )
import Control.Monad.Fail ( MonadFail )
import Data.Aeson
import Data.Aeson.Types
-import Data.String ( words, unwords )
import Text.XML.Cursor ( Cursor )
import qualified Control.Exception as E
import System.Process ( createProcess, proc, std_in, std_out, std_err, StdStream (..), waitForProcess )
@@ -24,6 +23,7 @@ import System.IO ( hClose )
import Control.Concurrent ( forkIO, putMVar, takeMVar, newEmptyMVar )
import qualified Data.ByteString.Lazy as LBS
import qualified Data.ByteString as B
+import qualified Data.Text as T
import System.Exit ( ExitCode (..) )
import Data.List ( partition )
import Control.Monad.IO.Class ( MonadIO, liftIO )
@@ -37,7 +37,7 @@ getCursorFilter s = fail $ "Invalid filter \"" <> toS s <> "\""
data FeedFilter
= CursorFilter Text (Cursor -> Cursor)
- | ExternalFilter FilePath [String]
+ | ExternalFilter FilePath [Text]
instance FromJSON FeedFilter where
parseJSON (Object o) =
@@ -45,14 +45,14 @@ instance FromJSON FeedFilter where
<|> parseExternalFilter <$> o .: "external"
parseJSON _ = mzero
-parseExternalFilter :: String -> FeedFilter
-parseExternalFilter s = case words s of
+parseExternalFilter :: Text -> FeedFilter
+parseExternalFilter s = case T.words s of
[] -> ExternalFilter "" []
- (c : opts) -> ExternalFilter (c :: FilePath) opts
+ (c : opts) -> ExternalFilter (toS c :: FilePath) opts
instance ToJSON FeedFilter where
toJSON (CursorFilter n _) = object [ "internal" .= n ]
- toJSON (ExternalFilter p opts) = object [ "external" .= unwords (p : opts) ]
+ toJSON (ExternalFilter p opts) = object [ "external" .= T.unwords (toS p : opts) ]
data FeedInfo
= FeedInfo
@@ -93,9 +93,9 @@ applyExternalFilters fs lbs = foldM (\ms f -> maybe (return Nothing) (applyExter
applyExternalFilter (ExternalFilter fp opts) lbs' = applyExternalFilter' fp opts lbs'
applyExternalFilter (CursorFilter _ _) lbs' = return $ Just lbs'
-applyExternalFilter' :: (MonadIO m, MonadLogger m, MonadFail m) => FilePath -> [String] -> LBS.ByteString -> m (Maybe LBS.ByteString)
+applyExternalFilter' :: (MonadIO m, MonadLogger m, MonadFail m) => FilePath -> [Text] -> LBS.ByteString -> m (Maybe LBS.ByteString)
applyExternalFilter' fp opts lbs = do
- (Just hin, mHOut, mHErr, phandle) <- liftIO $ createProcess (proc fp opts)
+ (Just hin, mHOut, mHErr, phandle) <- liftIO $ createProcess (proc fp (map toS opts))
{ std_in = CreatePipe
, std_out = CreatePipe
, std_err = CreatePipe
@@ -106,7 +106,7 @@ applyExternalFilter' fp opts lbs = do
(Right <$> LBS.hPut hin lbs) `E.catch` \(ex :: E.IOException) -> return $ Left ex
case eresult of
Right _ -> return ()
- Left ex -> $logError $ "external filter \"" <> toS fp <> toS (unwords opts) <> "\" failed: " <> show ex
+ Left ex -> $logError $ "external filter \"" <> toS fp <> toS (T.unwords opts) <> "\" failed: " <> show ex
ecloseresult <- liftIO $
(Right <$> hClose hin) `E.catch` \(ex :: E.SomeException) -> return $ Left ex
case ecloseresult of