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
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2010-12-31 17:39:30 +00:00
|
|
|
-}
|
|
|
|
|
2021-04-05 17:40:31 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
2010-12-31 17:39:30 +00:00
|
|
|
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
|
2015-08-13 20:13:16 +00:00
|
|
|
|
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
|
|
|
|
2020-09-14 20:49:33 +00:00
|
|
|
start :: (SeekInput, Key) -> CommandStart
|
|
|
|
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 ->
|
disk free checking for unsized keys
Improve disk free space checking when transferring unsized keys to
local git remotes. Since the size of the object file is known, can
check that instead.
Getting unsized keys from local git remotes does not check the actual
object size. It would be harder to handle that direction because the size
check is run locally, before anything involving the remote is done. So it
doesn't know the size of the file on the remote.
Also, transferring unsized keys to other remotes, including ssh remotes and
p2p remotes don't do disk size checking for unsized keys. This would need a
change in protocol.
(It does seem like it would be possible to implement the same thing for
directory special remotes though.)
In some sense, it might be better to not ever do disk free checking for
unsized keys, than to do it only sometimes. A user might notice this
direction working and consider it a bug that the other direction does not.
On the other hand, disk reserve checking is not implemented for most
special remotes at all, and yet it is implemented for a few, which is also
inconsistent, but best effort. And so doing this best effort seems to make
some sense. Fundamentally, if the user wants the size to always be checked,
they should not use unsized keys.
Sponsored-by: Brock Spratlen on Patreon
2024-01-16 18:29:10 +00:00
|
|
|
sendAnnex key rollback $ \f _sz ->
|
|
|
|
liftIO $ rsyncServerSend (map Param opts) f
|
2013-03-29 00:34:07 +00:00
|
|
|
, 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
|
2021-04-06 19:41:24 +00:00
|
|
|
fastDebug "Command.SendKey" "transfer start"
|
remove git-annex-shell compat code
* Removed support for accessing git remotes that use versions of
git-annex older than 6.20180312.
* git-annex-shell: Removed several commands that were only needed to
support git-annex versions older than 6.20180312.
(lockcontent, recvkey, sendkey, transferinfo, commit)
The P2P protocol was added in that version, and used ever since, so
this code was only needed for interop with older versions.
"git-annex-shell commit" is used by newer git-annex versions, though
unnecessarily so, because the p2pstdio command makes a single commit at
shutdown. Luckily, it was run with stderr and stdout sent to /dev/null,
and non-zero exit status or other exceptions are caught and ignored. So,
that was able to be removed from git-annex-shell too.
git-annex-shell inannex, recvkey, sendkey, and dropkey are still used by
gcrypt special remotes accessed over ssh, so those had to be kept.
It would probably be possible to convert that to using the P2P protocol,
but it would be another multi-year transition.
Some git-annex-shell fields were able to be removed. I hoped to remove
all of them, and the very concept of them, but unfortunately autoinit
is used by git-annex sync, and gcrypt uses remoteuuid.
The main win here is really in Remote.Git, removing piles of hairy fallback
code.
Sponsored-by: Luke Shumaker
2021-10-11 19:35:54 +00:00
|
|
|
let afile = AssociatedFile Nothing
|
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.
|
2023-03-27 19:10:46 +00:00
|
|
|
(\u -> runner (Transfer direction (toUUID u) (fromKey id key)) Nothing afile Nothing noRetry a)
|
2012-08-23 19:22:23 +00:00
|
|
|
=<< Fields.getField Fields.remoteUUID
|
2021-04-06 19:41:24 +00:00
|
|
|
fastDebug "Command.SendKey" "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
|