2010-12-31 17:39:30 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2012-07-02 05:31:10 +00:00
|
|
|
- Copyright 2010,2012 Joey Hess <joey@kitenet.net>
|
2010-12-31 17:39:30 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.SendKey where
|
|
|
|
|
2011-10-05 20:02:51 +00:00
|
|
|
import Common.Annex
|
2010-12-31 17:39:30 +00:00
|
|
|
import Command
|
2011-10-04 04:40:47 +00:00
|
|
|
import Annex.Content
|
2012-09-19 18:28:32 +00:00
|
|
|
import Utility.Rsync
|
2012-07-02 05:31:10 +00:00
|
|
|
import Logs.Transfer
|
2012-09-19 20:08:37 +00:00
|
|
|
import Types.Remote
|
2012-08-23 19:22:23 +00:00
|
|
|
import qualified Fields
|
2010-12-31 17:39:30 +00:00
|
|
|
|
2011-10-29 19:19:05 +00:00
|
|
|
def :: [Command]
|
2012-09-16 00:46:38 +00:00
|
|
|
def = [noCommit $ command "sendkey" paramKey seek
|
2010-12-31 17:39:30 +00:00
|
|
|
"runs rsync in server mode to send content"]
|
|
|
|
|
|
|
|
seek :: [CommandSeek]
|
|
|
|
seek = [withKeys start]
|
|
|
|
|
2011-09-15 20:50:49 +00:00
|
|
|
start :: Key -> CommandStart
|
2012-07-02 05:31:10 +00:00
|
|
|
start key = ifM (inAnnex key)
|
2012-09-23 17:27:13 +00:00
|
|
|
( fieldTransfer Upload key $ \_p -> do
|
2012-07-02 05:31:10 +00:00
|
|
|
file <- inRepo $ gitAnnexLocation key
|
2012-08-23 19:22:23 +00:00
|
|
|
liftIO $ rsyncServerSend file
|
2012-07-02 05:31:10 +00:00
|
|
|
, do
|
|
|
|
warning "requested key is not present"
|
|
|
|
liftIO exitFailure
|
|
|
|
)
|
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
|
|
|
|
afile <- Fields.getField Fields.associatedFile
|
2012-09-19 20:08:37 +00:00
|
|
|
ok <- maybe (a $ const noop)
|
2012-09-23 17:27:13 +00:00
|
|
|
(\u -> runTransfer (Transfer direction (toUUID u) key) afile noRetry a)
|
2012-08-23 19:22:23 +00:00
|
|
|
=<< Fields.getField Fields.remoteUUID
|
|
|
|
if ok
|
|
|
|
then liftIO exitSuccess
|
|
|
|
else liftIO exitFailure
|