From e3f1568e0ff7dc872f3782115c74b9e7d8c291b2 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 8 Dec 2011 16:01:46 -0400 Subject: Fix caching of decrypted ciphers, which failed when drop had to check multiple different encrypted special remotes. --- Remote/Helper/Encryptable.hs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'Remote') diff --git a/Remote/Helper/Encryptable.hs b/Remote/Helper/Encryptable.hs index 85d269a21..99f48fe7b 100644 --- a/Remote/Helper/Encryptable.hs +++ b/Remote/Helper/Encryptable.hs @@ -61,19 +61,22 @@ encryptableRemote c storeKeyEncrypted retrieveKeyFileEncrypted r = withkey a k = cip k >>= maybe (a k) (a . snd) cip = cipherKey c -{- Gets encryption Cipher. The decrypted Cipher is cached in the Annex +{- Gets encryption Cipher. The decrypted Ciphers are cached in the Annex - state. -} remoteCipher :: RemoteConfig -> Annex (Maybe Cipher) -remoteCipher c = maybe expensive cached =<< Annex.getState Annex.cipher +remoteCipher c = go $ extractCipher c where - cached cipher = return $ Just cipher - expensive = case extractCipher c of - Nothing -> return Nothing - Just encipher -> do - showNote "gpg" - cipher <- liftIO $ decryptCipher c encipher - Annex.changeState (\s -> s { Annex.cipher = Just cipher }) - return $ Just cipher + go Nothing = return Nothing + go (Just encipher) = do + cache <- Annex.getState Annex.ciphers + case M.lookup encipher cache of + Just cipher -> return $ Just cipher + Nothing -> decrypt encipher cache + decrypt encipher cache = do + showNote "gpg" + cipher <- liftIO $ decryptCipher c encipher + Annex.changeState (\s -> s { Annex.ciphers = M.insert encipher cipher cache }) + return $ Just cipher {- Gets encryption Cipher, and encrypted version of Key. -} cipherKey :: Maybe RemoteConfig -> Key -> Annex (Maybe (Cipher, Key)) -- cgit v1.2.3