p2p: Added --one-way option.
This commit was sponsored by Fernando Jimenez on Patreon.
This commit is contained in:
parent
3037feb1bf
commit
bd811d3853
3 changed files with 30 additions and 14 deletions
|
@ -17,6 +17,7 @@ git-annex (6.20161211) UNRELEASED; urgency=medium
|
||||||
* p2p --link now defaults to setting up a bi-directional link;
|
* p2p --link now defaults to setting up a bi-directional link;
|
||||||
both the local and remote git repositories get remotes added
|
both the local and remote git repositories get remotes added
|
||||||
pointing at one-another.
|
pointing at one-another.
|
||||||
|
* p2p: Added --one-way option.
|
||||||
|
|
||||||
-- Joey Hess <id@joeyh.name> Sun, 11 Dec 2016 21:29:51 -0400
|
-- Joey Hess <id@joeyh.name> Sun, 11 Dec 2016 21:29:51 -0400
|
||||||
|
|
||||||
|
|
|
@ -24,10 +24,13 @@ data P2POpts
|
||||||
= GenAddresses
|
= GenAddresses
|
||||||
| LinkRemote
|
| LinkRemote
|
||||||
|
|
||||||
optParser :: CmdParamsDesc -> Parser (P2POpts, Maybe RemoteName)
|
data LinkDirection = BiDirectional | OneWay
|
||||||
optParser _ = (,)
|
|
||||||
|
optParser :: CmdParamsDesc -> Parser (P2POpts, Maybe RemoteName, LinkDirection)
|
||||||
|
optParser _ = (,,)
|
||||||
<$> (genaddresses <|> linkremote)
|
<$> (genaddresses <|> linkremote)
|
||||||
<*> optional name
|
<*> optional name
|
||||||
|
<*> direction
|
||||||
where
|
where
|
||||||
genaddresses = flag' GenAddresses
|
genaddresses = flag' GenAddresses
|
||||||
( long "gen-addresses"
|
( long "gen-addresses"
|
||||||
|
@ -42,13 +45,17 @@ optParser _ = (,)
|
||||||
<> metavar paramName
|
<> metavar paramName
|
||||||
<> help "name of remote"
|
<> help "name of remote"
|
||||||
)
|
)
|
||||||
|
direction = flag BiDirectional OneWay
|
||||||
|
( long "one-way"
|
||||||
|
<> help "make one-way link, rather than default bi-directional link"
|
||||||
|
)
|
||||||
|
|
||||||
seek :: (P2POpts, Maybe RemoteName) -> CommandSeek
|
seek :: (P2POpts, Maybe RemoteName, LinkDirection) -> CommandSeek
|
||||||
seek (GenAddresses, _) = genAddresses =<< loadP2PAddresses
|
seek (GenAddresses, _, _) = genAddresses =<< loadP2PAddresses
|
||||||
seek (LinkRemote, Just name) = commandAction $
|
seek (LinkRemote, Just name, direction) = commandAction $
|
||||||
linkRemote (Git.Remote.makeLegalName name)
|
linkRemote direction (Git.Remote.makeLegalName name)
|
||||||
seek (LinkRemote, Nothing) = commandAction $
|
seek (LinkRemote, Nothing, direction) = commandAction $
|
||||||
linkRemote =<< unusedPeerRemoteName
|
linkRemote direction =<< unusedPeerRemoteName
|
||||||
|
|
||||||
-- Only addresses are output to stdout, to allow scripting.
|
-- Only addresses are output to stdout, to allow scripting.
|
||||||
genAddresses :: [P2PAddress] -> Annex ()
|
genAddresses :: [P2PAddress] -> Annex ()
|
||||||
|
@ -62,8 +69,8 @@ genAddresses addrs = do
|
||||||
map (`P2PAddressAuth` authtoken) addrs
|
map (`P2PAddressAuth` authtoken) addrs
|
||||||
|
|
||||||
-- Address is read from stdin, to avoid leaking it in shell history.
|
-- Address is read from stdin, to avoid leaking it in shell history.
|
||||||
linkRemote :: RemoteName -> CommandStart
|
linkRemote :: LinkDirection -> RemoteName -> CommandStart
|
||||||
linkRemote remotename = do
|
linkRemote direction remotename = do
|
||||||
showStart "p2p link" remotename
|
showStart "p2p link" remotename
|
||||||
next $ next prompt
|
next $ next prompt
|
||||||
where
|
where
|
||||||
|
@ -81,9 +88,12 @@ linkRemote remotename = do
|
||||||
liftIO $ hPutStrLn stderr "Unable to parse that address, please check its format and try again."
|
liftIO $ hPutStrLn stderr "Unable to parse that address, please check its format and try again."
|
||||||
prompt
|
prompt
|
||||||
Just addr -> do
|
Just addr -> do
|
||||||
|
linkbackto <- case direction of
|
||||||
|
OneWay -> return []
|
||||||
|
BiDirectional -> do
|
||||||
myaddrs <- loadP2PAddresses
|
myaddrs <- loadP2PAddresses
|
||||||
authtoken <- liftIO $ genAuthToken 128
|
authtoken <- liftIO $ genAuthToken 128
|
||||||
storeP2PAuthToken authtoken
|
storeP2PAuthToken authtoken
|
||||||
let linkbackto = map (`P2PAddressAuth` authtoken) myaddrs
|
return $ map (`P2PAddressAuth` authtoken) myaddrs
|
||||||
linkAddress addr linkbackto remotename
|
linkAddress addr linkbackto remotename
|
||||||
>>= either giveup return
|
>>= either giveup return
|
||||||
|
|
|
@ -39,6 +39,11 @@ services.
|
||||||
|
|
||||||
Specify a name to use when setting up a git remote.
|
Specify a name to use when setting up a git remote.
|
||||||
|
|
||||||
|
* `--one-way`
|
||||||
|
|
||||||
|
Use with `--link` to create a one-way link with a peer, rather than the
|
||||||
|
default bi-directional link.
|
||||||
|
|
||||||
# SEE ALSO
|
# SEE ALSO
|
||||||
|
|
||||||
[[git-annex]](1)
|
[[git-annex]](1)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue