assistant: When there are multiple remotes giving different ways to access the same repository, honor remote cost settings and use the cheapest available.

Note that TransferInfo does not always contain the Remote, although
any transfer added to the TransferQueue does have a Remote in its
TransferInfo. The transferkeys command still accepts a UUID, which is
useful to handle upgrades, where an old assistant version runs the new
transferkeys.

This commit was sponsored by Kalle Svensson.
This commit is contained in:
Joey Hess 2014-05-19 16:19:33 -04:00
parent e5bebde345
commit fed509fb3e
6 changed files with 31 additions and 17 deletions

View file

@ -149,7 +149,7 @@ genTransfer t info = case transferRemote info of
- usual cleanup. However, first check if something else is - usual cleanup. However, first check if something else is
- running the transfer, to avoid removing active transfers. - running the transfer, to avoid removing active transfers.
-} -}
go remote transferrer = ifM (liftIO $ performTransfer transferrer t $ associatedFile info) go remote transferrer = ifM (liftIO $ performTransfer transferrer t info)
( do ( do
maybe noop maybe noop
(void . addAlert . makeAlertFiller True (void . addAlert . makeAlertFiller True

View file

@ -56,9 +56,9 @@ checkTransferrerPoolItem program batchmaker i = case i of
{- Requests that a Transferrer perform a Transfer, and waits for it to {- Requests that a Transferrer perform a Transfer, and waits for it to
- finish. -} - finish. -}
performTransfer :: Transferrer -> Transfer -> AssociatedFile -> IO Bool performTransfer :: Transferrer -> Transfer -> TransferInfo -> IO Bool
performTransfer transferrer t f = catchBoolIO $ do performTransfer transferrer t info = catchBoolIO $ do
T.sendRequest t f (transferrerWrite transferrer) T.sendRequest t info (transferrerWrite transferrer)
T.readResponse (transferrerRead transferrer) T.readResponse (transferrerRead transferrer)
{- Starts a new git-annex transferkeys process, setting up handles {- Starts a new git-annex transferkeys process, setting up handles

View file

@ -17,6 +17,7 @@ import Annex.Transfer
import qualified Remote import qualified Remote
import Types.Key import Types.Key
import Utility.SimpleProtocol (ioHandles) import Utility.SimpleProtocol (ioHandles)
import Git.Types (RemoteName)
data TransferRequest = TransferRequest Direction Remote Key AssociatedFile data TransferRequest = TransferRequest Direction Remote Key AssociatedFile
@ -56,13 +57,13 @@ runRequests readh writeh a = do
fileEncoding writeh fileEncoding writeh
go =<< readrequests go =<< readrequests
where where
go (d:u:k:f:rest) = do go (d:rn:k:f:rest) = do
case (deserialize d, deserialize u, deserialize k, deserialize f) of case (deserialize d, deserialize rn, deserialize k, deserialize f) of
(Just direction, Just uuid, Just key, Just file) -> do (Just direction, Just remotename, Just key, Just file) -> do
mremote <- Remote.remoteFromUUID uuid mremote <- Remote.byName' remotename
case mremote of case mremote of
Nothing -> sendresult False Left _ -> sendresult False
Just remote -> sendresult =<< a Right remote -> sendresult =<< a
(TransferRequest direction remote key file) (TransferRequest direction remote key file)
_ -> sendresult False _ -> sendresult False
go rest go rest
@ -75,13 +76,15 @@ runRequests readh writeh a = do
hPutStrLn writeh $ serialize b hPutStrLn writeh $ serialize b
hFlush writeh hFlush writeh
sendRequest :: Transfer -> AssociatedFile -> Handle -> IO () sendRequest :: Transfer -> TransferInfo -> Handle -> IO ()
sendRequest t f h = do sendRequest t info h = do
hPutStr h $ intercalate fieldSep hPutStr h $ intercalate fieldSep
[ serialize (transferDirection t) [ serialize (transferDirection t)
, serialize (transferUUID t) , maybe (serialize (fromUUID (transferUUID t)))
(serialize . Remote.name)
(transferRemote info)
, serialize (transferKey t) , serialize (transferKey t)
, serialize f , serialize (associatedFile info)
, "" -- adds a trailing null , "" -- adds a trailing null
] ]
hFlush h hFlush h
@ -116,9 +119,9 @@ instance TCSerialized AssociatedFile where
deserialize "" = Just Nothing deserialize "" = Just Nothing
deserialize f = Just $ Just f deserialize f = Just $ Just f
instance TCSerialized UUID where instance TCSerialized RemoteName where
serialize = fromUUID serialize n = n
deserialize = Just . toUUID deserialize n = Just n
instance TCSerialized Key where instance TCSerialized Key where
serialize = key2file serialize = key2file

View file

@ -25,6 +25,7 @@ module Remote (
remoteMap', remoteMap',
uuidDescriptions, uuidDescriptions,
byName, byName,
byName',
byNameOnly, byNameOnly,
byNameWithUUID, byNameWithUUID,
byCost, byCost,

8
debian/changelog vendored
View file

@ -1,3 +1,11 @@
git-annex (5.20140518) UNRELEASED; urgency=medium
* assistant: When there are multiple remotes giving different ways
to access the same repository, honor remote cost settings and use
the cheapest available.
-- Joey Hess <joeyh@debian.org> Mon, 19 May 2014 15:59:25 -0400
git-annex (5.20140517) unstable; urgency=medium git-annex (5.20140517) unstable; urgency=medium
* webapp: Switched to bootstrap 3. * webapp: Switched to bootstrap 3.

View file

@ -136,3 +136,5 @@ gpg: 68D8501429C42E01: skipped: public key already present
"""]] """]]
[[!meta title="transferkeys protocol needs to include remote name to deal with multiple remotes with same UUID"]] [[!meta title="transferkeys protocol needs to include remote name to deal with multiple remotes with same UUID"]]
> [[fixed|done]] --[[Joey]]