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 Common.Annex
|
|
|
|
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
|
|
|
|
|
2014-10-14 18:20:10 +00:00
|
|
|
cmd :: [Command]
|
|
|
|
cmd = [withOptions transferKeyOptions $
|
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"]
|
|
|
|
|
2013-08-20 19:46:35 +00:00
|
|
|
transferKeyOptions :: [Option]
|
|
|
|
transferKeyOptions = fileOption : fromToOptions
|
2012-08-24 21:23:58 +00:00
|
|
|
|
|
|
|
fileOption :: Option
|
2014-01-26 20:25:55 +00:00
|
|
|
fileOption = fieldOption [] "file" paramFile "the associated file"
|
2012-08-24 21:23:58 +00:00
|
|
|
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
seek :: CommandSeek
|
|
|
|
seek ps = do
|
|
|
|
to <- getOptionField toOption Remote.byNameWithUUID
|
|
|
|
from <- getOptionField fromOption Remote.byNameWithUUID
|
|
|
|
file <- getOptionField fileOption return
|
|
|
|
withKeys (start to from file) ps
|
2012-08-24 21:23:58 +00:00
|
|
|
|
|
|
|
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
|
2014-03-22 14:42:38 +00:00
|
|
|
toPerform remote key file = go Upload file $
|
2015-05-12 19:50:03 +00:00
|
|
|
upload (uuid remote) key file forwardRetry noObserver $ \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
|
2014-03-22 14:42:38 +00:00
|
|
|
fromPerform remote key file = go Upload file $
|
2015-05-12 19:50:03 +00:00
|
|
|
download (uuid remote) key file forwardRetry noObserver $ \p ->
|
2013-04-11 21:15:45 +00:00
|
|
|
getViaTmp key $ \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
|