2013-12-19 20:48:55 +00:00
|
|
|
{- git-annex plumbing command (for use by old assistant, and users)
|
2012-08-24 21:23:58 +00:00
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2012 Joey Hess <id@joeyh.name>
|
2012-08-24 21:23:58 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.TransferKey where
|
|
|
|
|
|
|
|
import Command
|
|
|
|
import Annex.Content
|
|
|
|
import Logs.Location
|
2014-03-22 14:42:38 +00:00
|
|
|
import Annex.Transfer
|
2012-08-24 21:23:58 +00:00
|
|
|
import qualified Remote
|
|
|
|
import Types.Remote
|
|
|
|
|
2015-07-08 16:33:27 +00:00
|
|
|
cmd :: Command
|
2015-07-09 20:05:45 +00:00
|
|
|
cmd = noCommit $
|
2015-07-08 19:08:02 +00:00
|
|
|
command "transferkey" SectionPlumbing
|
2015-07-08 16:33:27 +00:00
|
|
|
"transfers a key from or to a remote"
|
2015-07-09 20:05:45 +00:00
|
|
|
paramKey (seek <--< optParser)
|
|
|
|
|
|
|
|
data TransferKeyOptions = TransferKeyOptions
|
|
|
|
{ keyOptions :: CmdParams
|
|
|
|
, fromToOptions :: FromToOptions
|
|
|
|
, fileOption :: AssociatedFile
|
|
|
|
}
|
|
|
|
|
|
|
|
optParser :: CmdParamsDesc -> Parser TransferKeyOptions
|
|
|
|
optParser desc = TransferKeyOptions
|
|
|
|
<$> cmdParams desc
|
|
|
|
<*> parseFromToOptions
|
2017-03-10 17:12:24 +00:00
|
|
|
<*> (AssociatedFile <$> optional (strOption
|
2015-07-09 20:05:45 +00:00
|
|
|
( long "file" <> metavar paramFile
|
|
|
|
<> help "the associated file"
|
2017-03-10 17:12:24 +00:00
|
|
|
)))
|
2015-07-09 20:05:45 +00:00
|
|
|
|
|
|
|
instance DeferredParseClass TransferKeyOptions where
|
|
|
|
finishParse v = TransferKeyOptions
|
|
|
|
<$> pure (keyOptions v)
|
|
|
|
<*> finishParse (fromToOptions v)
|
|
|
|
<*> pure (fileOption v)
|
|
|
|
|
|
|
|
seek :: TransferKeyOptions -> CommandSeek
|
|
|
|
seek o = withKeys (start o) (keyOptions o)
|
|
|
|
|
|
|
|
start :: TransferKeyOptions -> Key -> CommandStart
|
|
|
|
start o key = case fromToOptions o of
|
|
|
|
ToRemote dest -> next $ toPerform key (fileOption o) =<< getParsed dest
|
|
|
|
FromRemote src -> next $ fromPerform key (fileOption o) =<< getParsed src
|
|
|
|
|
|
|
|
toPerform :: Key -> AssociatedFile -> Remote -> CommandPerform
|
|
|
|
toPerform key file remote = go Upload file $
|
2018-03-29 17:04:07 +00:00
|
|
|
upload (uuid remote) key file stdRetry $ \p -> do
|
2012-09-19 20:08:37 +00:00
|
|
|
ok <- Remote.storeKey remote key file p
|
2012-08-24 21:23:58 +00:00
|
|
|
when ok $
|
|
|
|
Remote.logStatus remote key InfoPresent
|
|
|
|
return ok
|
|
|
|
|
2015-07-09 20:05:45 +00:00
|
|
|
fromPerform :: Key -> AssociatedFile -> Remote -> CommandPerform
|
|
|
|
fromPerform key file remote = go Upload file $
|
2018-03-29 17:04:07 +00:00
|
|
|
download (uuid remote) key file stdRetry $ \p ->
|
2018-06-21 17:34:11 +00:00
|
|
|
getViaTmp (retrievalSecurityPolicy remote) (RemoteVerify remote) key $
|
Do verification of checksums of annex objects downloaded from remotes.
* When annex objects are received into git repositories, their checksums are
verified then too.
* To get the old, faster, behavior of not verifying checksums, set
annex.verify=false, or remote.<name>.annex-verify=false.
* setkey, rekey: These commands also now verify that the provided file
matches the key, unless annex.verify=false.
* reinject: Already verified content; this can now be disabled by
setting annex.verify=false.
recvkey and reinject already did verification, so removed now duplicate
code from them. fsck still does its own verification, which is ok since it
does not use getViaTmp, so verification doesn't happen twice when using fsck
--from.
2015-10-01 19:54:37 +00:00
|
|
|
\t -> Remote.retrieveKeyFile remote key file t p
|
2012-09-24 17:36:05 +00:00
|
|
|
|
2014-03-22 14:42:38 +00:00
|
|
|
go :: Direction -> AssociatedFile -> (NotifyWitness -> Annex Bool) -> CommandPerform
|
|
|
|
go direction file a = notifyTransfer direction file a >>= liftIO . exitBool
|