2010-12-31 17:39:30 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2010,2012 Joey Hess <id@joeyh.name>
|
2010-12-31 17:39:30 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.SendKey where
|
|
|
|
|
|
|
|
import Command
|
2011-10-04 04:40:47 +00:00
|
|
|
import Annex.Content
|
2013-03-29 00:34:07 +00:00
|
|
|
import Annex
|
2012-09-19 18:28:32 +00:00
|
|
|
import Utility.Rsync
|
2014-03-22 14:42:38 +00:00
|
|
|
import Annex.Transfer
|
2014-01-26 20:32:55 +00:00
|
|
|
import qualified CmdLine.GitAnnexShell.Fields as Fields
|
2013-03-28 21:03:04 +00:00
|
|
|
import Utility.Metered
|
2010-12-31 17:39:30 +00:00
|
|
|
|
2015-08-13 20:13:16 +00:00
|
|
|
import System.Log.Logger
|
|
|
|
|
2015-07-08 16:33:27 +00:00
|
|
|
cmd :: Command
|
2015-07-08 19:08:02 +00:00
|
|
|
cmd = noCommit $
|
|
|
|
command "sendkey" SectionPlumbing
|
|
|
|
"runs rsync in server mode to send content"
|
|
|
|
paramKey (withParams seek)
|
2010-12-31 17:39:30 +00:00
|
|
|
|
2015-07-08 16:33:27 +00:00
|
|
|
seek :: CmdParams -> CommandSeek
|
2018-10-01 18:12:06 +00:00
|
|
|
seek = withKeys (commandAction . start)
|
2010-12-31 17:39:30 +00:00
|
|
|
|
2011-09-15 20:50:49 +00:00
|
|
|
start :: Key -> CommandStart
|
2013-03-29 00:34:07 +00:00
|
|
|
start key = do
|
2013-03-30 23:05:51 +00:00
|
|
|
opts <- filterRsyncSafeOptions . maybe [] words
|
|
|
|
<$> getField "RsyncOptions"
|
2013-03-29 00:34:07 +00:00
|
|
|
ifM (inAnnex key)
|
|
|
|
( fieldTransfer Upload key $ \_p ->
|
|
|
|
sendAnnex key rollback $ liftIO . rsyncServerSend (map Param opts)
|
|
|
|
, do
|
|
|
|
warning "requested key is not present"
|
|
|
|
liftIO exitFailure
|
|
|
|
)
|
2013-01-09 22:42:29 +00:00
|
|
|
where
|
|
|
|
{- No need to do any rollback; when sendAnnex fails, a nonzero
|
|
|
|
- exit will be propigated, and the remote will know the transfer
|
|
|
|
- failed. -}
|
|
|
|
rollback = noop
|
2012-08-23 19:22:23 +00:00
|
|
|
|
2012-09-21 18:50:14 +00:00
|
|
|
fieldTransfer :: Direction -> Key -> (MeterUpdate -> Annex Bool) -> CommandStart
|
2012-08-23 19:22:23 +00:00
|
|
|
fieldTransfer direction key a = do
|
2015-08-13 20:13:16 +00:00
|
|
|
liftIO $ debugM "fieldTransfer" "transfer start"
|
2017-03-10 17:12:24 +00:00
|
|
|
afile <- AssociatedFile <$> Fields.getField Fields.associatedFile
|
2012-09-19 20:08:37 +00:00
|
|
|
ok <- maybe (a $ const noop)
|
2016-10-26 19:38:22 +00:00
|
|
|
-- Using noRetry here because we're the sender.
|
2016-08-03 17:46:20 +00:00
|
|
|
(\u -> runner (Transfer direction (toUUID u) key) afile noRetry a)
|
2012-08-23 19:22:23 +00:00
|
|
|
=<< Fields.getField Fields.remoteUUID
|
2015-08-13 20:13:16 +00:00
|
|
|
liftIO $ debugM "fieldTransfer" "transfer done"
|
2013-11-19 21:08:57 +00:00
|
|
|
liftIO $ exitBool ok
|
2014-08-15 18:17:05 +00:00
|
|
|
where
|
|
|
|
{- Allow the key to be sent to the remote even if there seems to be
|
|
|
|
- another transfer of that key going on to that remote.
|
|
|
|
- That one may be stale, etc.
|
|
|
|
-}
|
|
|
|
runner
|
|
|
|
| direction == Upload = alwaysRunTransfer
|
|
|
|
| otherwise = runTransfer
|