diff options
-rw-r--r-- | hakyll.cabal | 17 | ||||
-rw-r--r-- | src/Hakyll.hs | 4 | ||||
-rw-r--r-- | src/Hakyll/Core/UnixFilter.hs | 31 |
3 files changed, 10 insertions, 42 deletions
diff --git a/hakyll.cabal b/hakyll.cabal index 1159e7b..f33aa69 100644 --- a/hakyll.cabal +++ b/hakyll.cabal @@ -75,10 +75,6 @@ Flag previewServer Description: Include the preview server Default: True -Flag unixFilter - Description: Include the UnixFilter module - Default: True - Library Ghc-Options: -Wall Ghc-Prof-Options: -auto-all -caf-all @@ -125,6 +121,7 @@ Library Hakyll.Core.Metadata Hakyll.Core.Routes Hakyll.Core.Rules + Hakyll.Core.UnixFilter Hakyll.Core.Util.String Hakyll.Core.Writable Hakyll.Main @@ -170,14 +167,6 @@ Library Hakyll.Preview.Poll Hakyll.Preview.Server - If flag(unixFilter) - Build-depends: - unix >= 2.4 && < 2.7 - Cpp-options: - -DUNIX_FILTER - Exposed-modules: - Hakyll.Core.UnixFilter - Test-suite hakyll-tests Type: exitcode-stdio-1.0 Hs-source-dirs: src tests @@ -217,9 +206,7 @@ Test-suite hakyll-tests regex-tdfa >= 1.1 && < 1.2, tagsoup >= 0.12.6 && < 0.13, text >= 0.11 && < 1.12, - time >= 1.1 && < 1.5, - -- Bonus copypasta - unix >= 2.4 && < 2.7 + time >= 1.1 && < 1.5 Other-modules: Hakyll.Core.Dependencies.Tests diff --git a/src/Hakyll.hs b/src/Hakyll.hs index 90b56f9..3d7fb91 100644 --- a/src/Hakyll.hs +++ b/src/Hakyll.hs @@ -11,9 +11,7 @@ module Hakyll , module Hakyll.Core.Metadata , module Hakyll.Core.Routes , module Hakyll.Core.Rules -#ifdef UNIX_FILTER , module Hakyll.Core.UnixFilter -#endif , module Hakyll.Core.Util.File , module Hakyll.Core.Util.String , module Hakyll.Core.Writable @@ -43,9 +41,7 @@ import Hakyll.Core.Item import Hakyll.Core.Metadata import Hakyll.Core.Routes import Hakyll.Core.Rules -#ifdef UNIX_FILTER import Hakyll.Core.UnixFilter -#endif import Hakyll.Core.Util.File import Hakyll.Core.Util.String import Hakyll.Core.Writable diff --git a/src/Hakyll/Core/UnixFilter.hs b/src/Hakyll/Core/UnixFilter.hs index dbc5e95..2a2f394 100644 --- a/src/Hakyll/Core/UnixFilter.hs +++ b/src/Hakyll/Core/UnixFilter.hs @@ -12,9 +12,7 @@ import Data.ByteString.Lazy (ByteString) import qualified Data.ByteString.Lazy as LB import System.IO (Handle, hClose, hGetContents, hPutStr, hSetEncoding, localeEncoding) -import System.Posix.IO (closeFd, createPipe, dupTo, fdToHandle, - stdInput, stdOutput) -import System.Posix.Process (executeFile, forkProcess) +import System.Process -------------------------------------------------------------------------------- @@ -89,32 +87,19 @@ unixFilterIO :: (Handle -> i -> IO ()) -> i -> IO o unixFilterIO writer reader programName args input = do - -- Create pipes - (stdinRead, stdinWrite) <- createPipe - (stdoutRead, stdoutWrite) <- createPipe + let process = (proc programName args) + { std_in = CreatePipe + , std_out = CreatePipe + , close_fds = True + } - -- Fork the child - _ <- forkProcess $ do - -- Copy our pipes over the regular stdin/stdout - _ <- dupTo stdinRead stdInput - _ <- dupTo stdoutWrite stdOutput - - -- Close the now unneeded file descriptors in the child - mapM_ closeFd [stdinWrite, stdoutRead, stdinRead, stdoutWrite] - - -- Execute the program - _ <- executeFile programName True args Nothing - return () - - -- On the parent side, close the client-side FDs. - mapM_ closeFd [stdinRead, stdoutWrite] + (Just stdinWriteHandle, Just stdoutReadHandle, _, _) <- + createProcess process -- Write the input to the child pipe _ <- forkIO $ do - stdinWriteHandle <- fdToHandle stdinWrite writer stdinWriteHandle input hClose stdinWriteHandle -- Receive the output from the child - stdoutReadHandle <- fdToHandle stdoutRead reader stdoutReadHandle |