2013-03-19 20:58:36 +00:00
|
|
|
{- git-annex command, used internally by old versions of assistant;
|
|
|
|
- kept around for now so running daemons don't break when upgraded
|
2012-08-24 21:23:58 +00:00
|
|
|
-
|
|
|
|
- Copyright 2012 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.TransferKey where
|
|
|
|
|
|
|
|
import Common.Annex
|
|
|
|
import Command
|
|
|
|
import Annex.Content
|
|
|
|
import Logs.Location
|
|
|
|
import Logs.Transfer
|
|
|
|
import qualified Remote
|
|
|
|
import Types.Remote
|
|
|
|
import qualified Command.Move
|
|
|
|
import qualified Option
|
|
|
|
|
|
|
|
def :: [Command]
|
|
|
|
def = [withOptions options $
|
2013-03-24 22:28:21 +00:00
|
|
|
noCommit $ command "transferkey" paramKey seek SectionPlumbing
|
2012-08-24 21:23:58 +00:00
|
|
|
"transfers a key from or to a remote"]
|
|
|
|
|
|
|
|
options :: [Option]
|
2013-07-03 17:55:50 +00:00
|
|
|
options = [fileOption, Command.Move.fromOption, Command.Move.toOption]
|
2012-08-24 21:23:58 +00:00
|
|
|
|
|
|
|
fileOption :: Option
|
|
|
|
fileOption = Option.field [] "file" paramFile "the associated file"
|
|
|
|
|
|
|
|
seek :: [CommandSeek]
|
2013-03-05 19:39:42 +00:00
|
|
|
seek = [withField Command.Move.toOption Remote.byNameWithUUID $ \to ->
|
|
|
|
withField Command.Move.fromOption Remote.byNameWithUUID $ \from ->
|
2012-08-24 21:23:58 +00:00
|
|
|
withField fileOption return $ \file ->
|
|
|
|
withKeys $ start to from file]
|
|
|
|
|
|
|
|
start :: Maybe Remote -> Maybe Remote -> AssociatedFile -> Key -> CommandStart
|
|
|
|
start to from file key =
|
|
|
|
case (from, to) of
|
|
|
|
(Nothing, Just dest) -> next $ toPerform dest key file
|
|
|
|
(Just src, Nothing) -> next $ fromPerform src key file
|
|
|
|
_ -> error "specify either --from or --to"
|
|
|
|
|
|
|
|
toPerform :: Remote -> Key -> AssociatedFile -> CommandPerform
|
2012-09-24 17:36:05 +00:00
|
|
|
toPerform remote key file = go $
|
2012-09-23 17:27:13 +00:00
|
|
|
upload (uuid remote) key file forwardRetry $ \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
|
|
|
|
|
|
|
|
fromPerform :: Remote -> Key -> AssociatedFile -> CommandPerform
|
2012-09-24 17:36:05 +00:00
|
|
|
fromPerform remote key file = go $
|
2013-04-11 21:15:45 +00:00
|
|
|
download (uuid remote) key file forwardRetry $ \p ->
|
|
|
|
getViaTmp key $ \t -> Remote.retrieveKeyFile remote key file t p
|
2012-09-24 17:36:05 +00:00
|
|
|
|
|
|
|
go :: Annex Bool -> CommandPerform
|
|
|
|
go a = ifM a ( liftIO exitSuccess, liftIO exitFailure)
|