@@ -19,7 +19,6 @@ module Stack.Sig.GPG (signPackage, verifyFile) where
1919import Control.Applicative ((<$>) )
2020#endif
2121
22- import Control.Exception (catch , SomeException )
2322import Control.Monad.Catch (MonadThrow , throwM )
2423import Control.Monad.IO.Class (MonadIO , liftIO )
2524import qualified Data.ByteString.Char8 as C
@@ -28,6 +27,7 @@ import Data.Monoid ((<>))
2827import qualified Data.Text as T
2928import Path
3029import Stack.Types
30+ import System.Directory (findExecutable )
3131import System.Exit (ExitCode (.. ))
3232import System.Process (readProcessWithExitCode )
3333
@@ -72,16 +72,14 @@ verifyFile (Signature signature) path = do
7272
7373-- | Try to execute `gpg2` but fallback to `gpg` (as a backup)
7474gpg
75- :: (Monad m , MonadIO m )
75+ :: (Monad m , MonadIO m , MonadThrow m )
7676 => [String ] -> String -> m (ExitCode , String , String )
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
77+ gpg args stdin = do
78+ mGpg2Path <- liftIO (findExecutable " gpg2" )
79+ case mGpg2Path of
80+ Just _ -> liftIO (readProcessWithExitCode " gpg2" args stdin)
81+ Nothing -> do
82+ mGpgPath <- liftIO (findExecutable " gpg" )
83+ case mGpgPath of
84+ Just _ -> liftIO (readProcessWithExitCode " gpg" args stdin)
85+ Nothing -> throwM GPGNotFoundException
0 commit comments