Skip to content

Commit

Permalink
Merge branch 'fix-pacman-output-parsing' of https://github.com/koterp…
Browse files Browse the repository at this point in the history
…illar/aura into koterpillar-fix-pacman-output-parsing
  • Loading branch information
fosskers committed Jan 26, 2020
2 parents 212d3b7 + 3377522 commit 716cfb1
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions aura/lib/Aura/Pacman.hs
Expand Up @@ -36,7 +36,7 @@ module Aura.Pacman
import Aura.Languages
import Aura.Types
import Aura.Utils (strictText)
import BasePrelude hiding (some, try)
import BasePrelude hiding (setEnv, some, try)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy.Char8 as BL
import qualified Data.Map.Strict as M
Expand Down Expand Up @@ -127,19 +127,24 @@ getLogFilePath (Config c) = c ^? at "LogFile" . _Just . _head . to (fromAbsolute
----------
-- ACTIONS
----------

-- | Create a pacman process to run.
pacmanProc :: [String] -> ProcessConfig () () ()
pacmanProc args = setEnv [("LC_ALL", "C")] $ proc "pacman" args

-- | Run a pacman action that may fail. Will never throw an IO exception.
pacman :: [T.Text] -> IO (Either Failure ())
pacman (map T.unpack -> args) = do
ec <- runProcess $ proc "pacman" args
ec <- runProcess $ pacmanProc args
pure . bool (Left $ Failure pacmanFailure_1) (Right ()) $ ec == ExitSuccess

-- | Run some `pacman` process, but only care about whether it succeeded.
pacmanSuccess :: [T.Text] -> IO Bool
pacmanSuccess = fmap (== ExitSuccess) . runProcess . setStderr closed . setStdout closed . proc "pacman" . map T.unpack
pacmanSuccess = fmap (== ExitSuccess) . runProcess . setStderr closed . setStdout closed . pacmanProc . map T.unpack

-- | Runs pacman silently and returns only the stdout.
pacmanOutput :: [T.Text] -> IO BL.ByteString
pacmanOutput = fmap (^. _2) . readProcess . proc "pacman" . map T.unpack
pacmanOutput = fmap (^. _2) . readProcess . pacmanProc . map T.unpack

-- | Runs pacman silently and returns the stdout as UTF8-decoded `Text` lines.
pacmanLines :: [T.Text] -> IO [T.Text]
Expand Down

0 comments on commit 716cfb1

Please sign in to comment.