summaryrefslogtreecommitdiff
path: root/Remote/Helper
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-12-08 16:01:46 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-12-08 16:01:46 -0400
commite3f1568e0ff7dc872f3782115c74b9e7d8c291b2 (patch)
treedab3d9797fe1ff96d22baf88c45d9e66b827c905 /Remote/Helper
parent2568beee07928d1bd462d631372881f146b190ee (diff)
Fix caching of decrypted ciphers, which failed when drop had to check multiple different encrypted special remotes.
Diffstat (limited to 'Remote/Helper')
-rw-r--r--Remote/Helper/Encryptable.hs23
1 files changed, 13 insertions, 10 deletions
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))