hook: use ChunkedEncryptable

This commit is contained in:
Joey Hess 2014-08-02 17:25:16 -04:00
parent d4dc1bce75
commit 7f5cd868d7
3 changed files with 16 additions and 29 deletions

View file

@ -7,7 +7,6 @@
module Remote.Hook (remote) where
import qualified Data.ByteString.Lazy as L
import qualified Data.Map as M
import Common.Annex
@ -17,12 +16,9 @@ import Types.Creds
import qualified Git
import Config
import Config.Cost
import Annex.Content
import Annex.UUID
import Remote.Helper.Special
import Remote.Helper.Encryptable
import Crypto
import Utility.Metered
import Remote.Helper.ChunkedEncryptable
import Utility.Env
type Action = String
@ -39,15 +35,15 @@ remote = RemoteType {
gen :: Git.Repo -> UUID -> RemoteConfig -> RemoteGitConfig -> Annex (Maybe Remote)
gen r u c gc = do
cst <- remoteCost gc expensiveRemoteCost
return $ Just $ encryptableRemote c
(storeEncrypted hooktype $ getGpgEncParams (c,gc))
(retrieveEncrypted hooktype)
return $ Just $ chunkedEncryptableRemote c
(simplyPrepare $ store hooktype)
(simplyPrepare $ retrieve hooktype)
Remote {
uuid = u,
cost = cst,
name = Git.repoDescribe r,
storeKey = store hooktype,
retrieveKeyFile = retrieve hooktype,
storeKey = storeKeyDummy,
retrieveKeyFile = retreiveKeyFileDummy,
retrieveKeyFileCheap = retrieveCheap hooktype,
removeKey = remove hooktype,
hasKey = checkPresent r hooktype,
@ -118,30 +114,18 @@ runHook hook action k f a = maybe (return False) run =<< lookupHook hook action
return False
)
store :: HookName -> Key -> AssociatedFile -> MeterUpdate -> Annex Bool
store h k _f _p = sendAnnex k (void $ remove h k) $ \src ->
store :: HookName -> Storer
store h = fileStorer $ \k src _p ->
runHook h "store" k (Just src) $ return True
storeEncrypted :: HookName -> [CommandParam] -> (Cipher, Key) -> Key -> MeterUpdate -> Annex Bool
storeEncrypted h gpgOpts (cipher, enck) k _p = withTmp enck $ \tmp ->
sendAnnex k (void $ remove h enck) $ \src -> do
liftIO $ encrypt gpgOpts cipher (feedFile src) $
readBytes $ L.writeFile tmp
runHook h "store" enck (Just tmp) $ return True
retrieve :: HookName -> Key -> AssociatedFile -> FilePath -> MeterUpdate -> Annex Bool
retrieve h k _f d _p = runHook h "retrieve" k (Just d) $ return True
retrieve :: HookName -> Retriever
retrieve h = fileRetriever $ \d k _p ->
unlessM (runHook h "retrieve" k (Just d) $ return True) $
error "failed to retrieve content"
retrieveCheap :: HookName -> Key -> FilePath -> Annex Bool
retrieveCheap _ _ _ = return False
retrieveEncrypted :: HookName -> (Cipher, Key) -> Key -> FilePath -> MeterUpdate -> Annex Bool
retrieveEncrypted h (cipher, enck) _ f _p = withTmp enck $ \tmp ->
runHook h "retrieve" enck (Just tmp) $ liftIO $ catchBoolIO $ do
decrypt cipher (feedFile tmp) $
readBytes $ L.writeFile f
return True
remove :: HookName -> Key -> Annex Bool
remove h k = runHook h "remove" k Nothing $ return True

3
debian/changelog vendored
View file

@ -1,7 +1,8 @@
git-annex (5.20140718) UNRELEASED; urgency=medium
* New chunk= option to chunk files stored in special remotes.
Currently supported by: directory, S3, and all external special remotes.
Currently supported by: directory, S3, and all external and hook
special remotes.
* Partially transferred files are automatically resumed when using
chunked remotes!
* The old chunksize= option is deprecated. Do not use for new remotes.

View file

@ -36,6 +36,8 @@ These parameters can be passed to `git annex initremote`:
* `keyid` - Specifies the gpg key to use for [[encryption]].
* `chunk` - Enables [[chunking]] when storing large files.
## hooks
Each type of hook remote is specified by a collection of hook commands.