summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-09-08 13:00:48 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-09-08 13:00:48 -0400
commit37e41beadce0660d0abcead87de34552d8163417 (patch)
treef9db8d406e43b2d9c003cceb03fc84e9926e7e3a
parenta1b0f833049228861f96f3edcf97d1aeda515ac4 (diff)
local gcrypt fully working!
-rw-r--r--Remote/GCrypt.hs36
1 files changed, 29 insertions, 7 deletions
diff --git a/Remote/GCrypt.hs b/Remote/GCrypt.hs
index f839f6647..396cb367e 100644
--- a/Remote/GCrypt.hs
+++ b/Remote/GCrypt.hs
@@ -8,6 +8,7 @@
module Remote.GCrypt (remote, gen) where
import qualified Data.Map as M
+import qualified Data.ByteString.Lazy as L
import Common.Annex
import Types.Remote
@@ -66,7 +67,7 @@ gen' r u c gc = new <$> remoteCost gc defcst
, storeKey = \_ _ _ -> noCrypto
, retrieveKeyFile = \_ _ _ _ -> noCrypto
, retrieveKeyFileCheap = \_ _ -> return False
- , removeKey = remove
+ , removeKey = remove this
, hasKey = checkPresent this
, hasKeyCheap = repoCheap r
, whereisKey = Nothing
@@ -82,6 +83,9 @@ gen' r u c gc = new <$> remoteCost gc defcst
noCrypto :: Annex a
noCrypto = error "cannot use gcrypt remote without encryption enabled"
+unsupportedUrl :: Annex a
+unsupportedUrl = error "using non-ssh remote repo url with gcrypt is not supported"
+
gCryptSetup :: Maybe UUID -> RemoteConfig -> Annex (RemoteConfig, UUID)
gCryptSetup mu c = go $ M.lookup "gitrepo" c
where
@@ -134,8 +138,8 @@ store r (cipher, enck) k p
createDirectoryIfMissing True $ parentDir dest
readBytes (meteredWriteFile meterupdate dest) h
return True
- | Git.repoIsSsh (repo r) = sendwith $ \h -> undefined
- | otherwise = error "storing on non-ssh remote repo not supported"
+ | Git.repoIsSsh (repo r) = sendwith $ \meterupdate h -> undefined
+ | otherwise = unsupportedUrl
where
dest = gCryptLocation r enck
sendwith a = metered (Just p) k $ \meterupdate ->
@@ -144,10 +148,28 @@ store r (cipher, enck) k p
encrypt (getGpgEncParams r) cipher (feedFile src) (a meterupdate)
retrieve :: Remote -> (Cipher, Key) -> Key -> FilePath -> MeterUpdate -> Annex Bool
-retrieve r (cipher, enck) k d p = undefined
+retrieve r (cipher, enck) k d p
+ | not $ Git.repoIsUrl (repo r) = guardUsable (repo r) False $ do
+ retrievewith $ L.readFile src
+ return True
+ | Git.repoIsSsh (repo r) = undefined
+ | otherwise = unsupportedUrl
+ where
+ src = gCryptLocation r enck
+ retrievewith a = metered (Just p) k $ \meterupdate -> liftIO $
+ a >>= \b ->
+ decrypt cipher (feedBytes b)
+ (readBytes $ meteredWriteFile meterupdate d)
-remove :: Key -> Annex Bool
-remove k = undefined
+remove :: Remote -> Key -> Annex Bool
+remove r k
+ | not $ Git.repoIsUrl (repo r) = guardUsable (repo r) False $ do
+ liftIO $ removeDirectoryRecursive (parentDir dest)
+ return True
+ | Git.repoIsSsh (repo r) = undefined
+ | otherwise = unsupportedUrl
+ where
+ dest = gCryptLocation r k
checkPresent :: Remote -> Key -> Annex (Either String Bool)
checkPresent r k
@@ -156,7 +178,7 @@ checkPresent r k
liftIO $ catchDefaultIO unknown $
Right <$> doesFileExist (gCryptLocation r k)
| Git.repoIsSsh (repo r) = undefined
- | otherwise = error "storing on non-ssh remote repo not supported"
+ | otherwise = unsupportedUrl
where
unknown = Left $ "unable to check " ++ Git.repoDescribe (repo r) ++ show (repo r)