Skip to content

Commit 8de6f5b

Browse files
committed
fix gpg2||gpg fallback
1 parent cd73bc9 commit 8de6f5b

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

src/Stack/Sig/GPG.hs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE RankNTypes #-}
3+
{-# LANGUAGE TemplateHaskell #-}
4+
{-# LANGUAGE TupleSections #-}
25

36
{-|
47
Module : Stack.Sig.GPG
@@ -16,6 +19,7 @@ module Stack.Sig.GPG (signPackage, verifyFile) where
1619
import Control.Applicative ((<$>))
1720
#endif
1821

22+
import Control.Exception (catch, SomeException)
1923
import Control.Monad.Catch (MonadThrow, throwM)
2024
import Control.Monad.IO.Class (MonadIO, liftIO)
2125
import qualified Data.ByteString.Char8 as C
@@ -70,11 +74,14 @@ verifyFile (Signature signature) path = do
7074
gpg
7175
:: (Monad m, MonadIO m)
7276
=> [String] -> String -> m (ExitCode, String, String)
73-
gpg args stdin = do
74-
(code,out,err) <- liftIO (readProcessWithExitCode "gpg2" args stdin)
75-
if code == ExitSuccess
76-
then return (code, out, err)
77-
else liftIO (readProcessWithExitCode "gpg" args stdin)
78-
79-
-- TODO test on Windows (package?)
80-
-- TODO test on Mac (w/ GnuPG Suite & homebrew gnupg & gnupg2)
77+
gpg args stdin =
78+
liftIO
79+
(catch
80+
(readProcessWithExitCode "gpg2" args stdin)
81+
(oops
82+
(catch
83+
(readProcessWithExitCode "gpg" args stdin)
84+
(return . (, [], [])))))
85+
where
86+
oops :: IO a -> SomeException -> IO a
87+
oops = const

0 commit comments

Comments
 (0)