From 7ba79cfb8c5c2a0fcb1472ab67bb777999e8e88a Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 4 Mar 2012 03:36:39 -0400 Subject: [PATCH] thread through original key to retrieveEnctypted Allows showing progress bar for this last case of the directory special remote. --- Remote/Bup.hs | 4 ++-- Remote/Directory.hs | 13 +++++++------ Remote/Helper/Encryptable.hs | 4 ++-- Remote/Hook.hs | 4 ++-- Remote/Rsync.hs | 4 ++-- Remote/S3.hs | 4 ++-- 6 files changed, 17 insertions(+), 16 deletions(-) diff --git a/Remote/Bup.hs b/Remote/Bup.hs index a4f43a3f3e..4ac91e945f 100644 --- a/Remote/Bup.hs +++ b/Remote/Bup.hs @@ -129,8 +129,8 @@ retrieve buprepo k f = do retrieveCheap :: BupRepo -> Key -> FilePath -> Annex Bool retrieveCheap _ _ _ = return False -retrieveEncrypted :: BupRepo -> (Cipher, Key) -> FilePath -> Annex Bool -retrieveEncrypted buprepo (cipher, enck) f = do +retrieveEncrypted :: BupRepo -> (Cipher, Key) -> Key -> FilePath -> Annex Bool +retrieveEncrypted buprepo (cipher, enck) _ f = do let params = bupParams "join" buprepo [Param $ show enck] liftIO $ catchBoolIO $ do (pid, h) <- hPipeFrom "bup" $ toCommand params diff --git a/Remote/Directory.hs b/Remote/Directory.hs index 40e6dc72de..e23891e5a4 100644 --- a/Remote/Directory.hs +++ b/Remote/Directory.hs @@ -237,12 +237,13 @@ retrieve d chunksize k f = metered k $ \meterupdate -> (L.concat <$> mapM L.readFile files) return True -retrieveEncrypted :: FilePath -> ChunkSize -> (Cipher, Key) -> FilePath -> Annex Bool -retrieveEncrypted d chunksize (cipher, enck) f = - liftIO $ withStoredFiles chunksize d enck $ \files -> catchBoolIO $ do - withDecryptedContent cipher (L.concat <$> mapM L.readFile files) $ - L.writeFile f - return True +retrieveEncrypted :: FilePath -> ChunkSize -> (Cipher, Key) -> Key -> FilePath -> Annex Bool +retrieveEncrypted d chunksize (cipher, enck) k f = metered k $ \meterupdate -> + liftIO $ withStoredFiles chunksize d enck $ \files -> + catchBoolIO $ do + withDecryptedContent cipher (L.concat <$> mapM L.readFile files) $ + meteredWriteFile meterupdate f + return True retrieveCheap :: FilePath -> ChunkSize -> Key -> FilePath -> Annex Bool retrieveCheap _ (Just _) _ _ = return False -- no cheap retrieval for chunks diff --git a/Remote/Helper/Encryptable.hs b/Remote/Helper/Encryptable.hs index 0569cb5551..bcecb30cc4 100644 --- a/Remote/Helper/Encryptable.hs +++ b/Remote/Helper/Encryptable.hs @@ -40,7 +40,7 @@ encryptionSetup c = encryptableRemote :: Maybe RemoteConfig -> ((Cipher, Key) -> Key -> Annex Bool) - -> ((Cipher, Key) -> FilePath -> Annex Bool) + -> ((Cipher, Key) -> Key -> FilePath -> Annex Bool) -> Remote -> Remote encryptableRemote c storeKeyEncrypted retrieveKeyFileEncrypted r = @@ -58,7 +58,7 @@ encryptableRemote c storeKeyEncrypted retrieveKeyFileEncrypted r = (`storeKeyEncrypted` k) retrieve k f = cip k >>= maybe (retrieveKeyFile r k f) - (`retrieveKeyFileEncrypted` f) + (\enck -> retrieveKeyFileEncrypted enck k f) retrieveCheap k f = cip k >>= maybe (retrieveKeyFileCheap r k f) (\_ -> return False) diff --git a/Remote/Hook.hs b/Remote/Hook.hs index c7d710f196..b37d5e2156 100644 --- a/Remote/Hook.hs +++ b/Remote/Hook.hs @@ -114,8 +114,8 @@ retrieve h k f = runHook h "retrieve" k (Just f) $ return True retrieveCheap :: String -> Key -> FilePath -> Annex Bool retrieveCheap _ _ _ = return False -retrieveEncrypted :: String -> (Cipher, Key) -> FilePath -> Annex Bool -retrieveEncrypted h (cipher, enck) f = withTmp enck $ \tmp -> +retrieveEncrypted :: String -> (Cipher, Key) -> Key -> FilePath -> Annex Bool +retrieveEncrypted h (cipher, enck) _ f = withTmp enck $ \tmp -> runHook h "retrieve" enck (Just tmp) $ liftIO $ catchBoolIO $ do withDecryptedContent cipher (L.readFile tmp) $ L.writeFile f return True diff --git a/Remote/Rsync.hs b/Remote/Rsync.hs index 54fb890cae..577ea0b049 100644 --- a/Remote/Rsync.hs +++ b/Remote/Rsync.hs @@ -119,8 +119,8 @@ retrieveCheap o k f = do then retrieve o k f else return False -retrieveEncrypted :: RsyncOpts -> (Cipher, Key) -> FilePath -> Annex Bool -retrieveEncrypted o (cipher, enck) f = withTmp enck $ \tmp -> do +retrieveEncrypted :: RsyncOpts -> (Cipher, Key) -> Key -> FilePath -> Annex Bool +retrieveEncrypted o (cipher, enck) _ f = withTmp enck $ \tmp -> do res <- retrieve o enck tmp if res then liftIO $ catchBoolIO $ do diff --git a/Remote/S3.hs b/Remote/S3.hs index 523edef65e..a688ffcf34 100644 --- a/Remote/S3.hs +++ b/Remote/S3.hs @@ -161,8 +161,8 @@ retrieve r k f = s3Action r False $ \(conn, bucket) -> do retrieveCheap :: Remote -> Key -> FilePath -> Annex Bool retrieveCheap _ _ _ = return False -retrieveEncrypted :: Remote -> (Cipher, Key) -> FilePath -> Annex Bool -retrieveEncrypted r (cipher, enck) f = s3Action r False $ \(conn, bucket) -> do +retrieveEncrypted :: Remote -> (Cipher, Key) -> Key -> FilePath -> Annex Bool +retrieveEncrypted r (cipher, enck) _ f = s3Action r False $ \(conn, bucket) -> do res <- liftIO $ getObject conn $ bucketKey r bucket enck case res of Right o -> liftIO $