summaryrefslogtreecommitdiff
path: root/KeyRing.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2014-04-14 22:35:15 -0400
committerjoe <joe@jerkface.net>2014-04-14 22:35:15 -0400
commit0d205c06b6577b9b7f24f084a7371f2ee7d8b616 (patch)
tree1b6a82c82edb58d05f2a035df6dca09ec8b6965a /KeyRing.hs
parent6b3ecc5010905d42c0a3c33e6850210a8cf615fc (diff)
CantFindHome error
Diffstat (limited to 'KeyRing.hs')
-rw-r--r--KeyRing.hs22
1 files changed, 15 insertions, 7 deletions
diff --git a/KeyRing.hs b/KeyRing.hs
index a2485c4..995afe6 100644
--- a/KeyRing.hs
+++ b/KeyRing.hs
@@ -166,7 +166,11 @@ data RSAPrivateKey = RSAPrivateKey
166 deriving Show 166 deriving Show
167 167
168 168
169data KikiCondition a = KikiSuccess a | FailedToLock [FilePath] | BadPassphrase | FailedToMakeSignature 169data KikiCondition a = KikiSuccess a
170 | FailedToLock [FilePath]
171 | BadPassphrase
172 | FailedToMakeSignature
173 | CantFindHome
170 174
171#define TRIVIAL(OP) fmap _ (OP) = OP 175#define TRIVIAL(OP) fmap _ (OP) = OP
172instance Functor KikiCondition where 176instance Functor KikiCondition where
@@ -582,7 +586,13 @@ doImportG doDecrypt db m0 tag fname key = do
582 586
583runKeyRing :: KeyRingData -> (KeyRingRuntime -> a) -> IO (KikiResult a) 587runKeyRing :: KeyRingData -> (KeyRingRuntime -> a) -> IO (KikiResult a)
584runKeyRing keyring op = do 588runKeyRing keyring op = do
585 (homedir,secring,pubring,grip0) <- getHomeDir (homeSpec keyring) 589 homedir <- getHomeDir (homeSpec keyring)
590 let try' :: KikiCondition a -> (a -> IO (KikiResult b)) -> IO (KikiResult b)
591 try' v body =
592 case functorToEither v of
593 Left e -> return $ KikiResult e []
594 Right wkun -> body wkun
595 try' homedir $ \(homedir,secring,pubring,grip0) -> do
586 let tolocks = filesToLock keyring secring pubring 596 let tolocks = filesToLock keyring secring pubring
587 lks <- forM tolocks $ \f -> do 597 lks <- forM tolocks $ \f -> do
588 lk <- dotlock_create f 0 598 lk <- dotlock_create f 0
@@ -596,9 +606,7 @@ runKeyRing keyring op = do
596 ret <- case functorToEither ret of 606 ret <- case functorToEither ret of
597 Right {} -> do 607 Right {} -> do
598 bresult <- buildKeyDB secring pubring grip0 keyring -- build db 608 bresult <- buildKeyDB secring pubring grip0 keyring -- build db
599 case functorToEither bresult of 609 try' bresult $ \((db,grip),report1) -> do
600 Left e -> return $ KikiResult e []
601 Right ((db,grip), report1) -> do
602 a <- return $ op KeyRingRuntime 610 a <- return $ op KeyRingRuntime
603 { rtPubring = pubring 611 { rtPubring = pubring
604 , rtSecring = secring 612 , rtSecring = secring
@@ -627,14 +635,14 @@ parseOptionFile fname = do
627 635
628getHomeDir protohome = do 636getHomeDir protohome = do
629 homedir <- envhomedir protohome 637 homedir <- envhomedir protohome
630 flip (maybe (error "Could not determine home directory.")) 638 flip (maybe (return CantFindHome))
631 homedir $ \homedir -> do 639 homedir $ \homedir -> do
632 -- putStrLn $ "homedir = " ++show homedir 640 -- putStrLn $ "homedir = " ++show homedir
633 let secring = homedir ++ "/" ++ "secring.gpg" 641 let secring = homedir ++ "/" ++ "secring.gpg"
634 pubring = homedir ++ "/" ++ "pubring.gpg" 642 pubring = homedir ++ "/" ++ "pubring.gpg"
635 -- putStrLn $ "secring = " ++ show secring 643 -- putStrLn $ "secring = " ++ show secring
636 workingkey <- getWorkingKey homedir 644 workingkey <- getWorkingKey homedir
637 return (homedir,secring,pubring,workingkey) 645 return $ KikiSuccess (homedir,secring,pubring,workingkey)
638 where 646 where
639 envhomedir opt = do 647 envhomedir opt = do
640 gnupghome <- lookupEnv (homevar home) >>= 648 gnupghome <- lookupEnv (homevar home) >>=