summaryrefslogtreecommitdiff
path: root/Remote/External.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-12-27 02:49:10 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-12-27 02:49:10 -0400
commit8ad91f287cf87b3a5a849d997de35210a0e9f2b7 (patch)
tree0850980711d834864512c2ef04ea0adf7bed0703 /Remote/External.hs
parentd0d51528d0d90c218173593db17de1a480e0b15e (diff)
don't send PREPARE before INITREMOTE
That complicated special remote programs, because they had to avoid making PREPARE fail if some configuration is missing, because the remote might not be initialized yet. Instead, complicate git-annex slightly by only sending PREPARE immediately before some other request other than INITREMOTE (or PREPARE of course).
Diffstat (limited to 'Remote/External.hs')
-rw-r--r--Remote/External.hs20
1 files changed, 15 insertions, 5 deletions
diff --git a/Remote/External.hs b/Remote/External.hs
index 1cf199e99..5a09d1de0 100644
--- a/Remote/External.hs
+++ b/Remote/External.hs
@@ -169,6 +169,8 @@ handleRequest external req mp responsehandler =
handleRequest' :: ExternalLock -> External -> Request -> Maybe MeterUpdate -> (Response -> Maybe (Annex a)) -> Annex a
handleRequest' lck external req mp responsehandler = do
+ when (needsPREPARE req) $
+ checkPrepared lck external
sendMessage lck external req
loop
where
@@ -230,15 +232,13 @@ fromExternal lck external extractor a =
void $ liftIO $ atomically $ swapTMVar v st
{- Handle initial protocol startup; check the VERSION
- - the remote sends, and send it the PREPARE request. -}
+ - the remote sends. -}
receiveMessage lck external
(const Nothing)
(checkVersion lck external)
(const Nothing)
- handleRequest' lck external PREPARE Nothing $ \resp ->
- case resp of
- PREPARE_SUCCESS -> Just $ run st
- _ -> Nothing
+
+ run st
run st = a $ extractor st
v = externalState external
@@ -259,6 +259,7 @@ startExternal externaltype = liftIO $ do
{ externalSend = hin
, externalReceive = hout
, externalPid = pid
+ , externalPrepared = False
}
stopExternal :: External -> Annex ()
@@ -282,6 +283,15 @@ checkVersion lck external (VERSION v) = Just $
else sendMessage lck external (ERROR "unsupported VERSION")
checkVersion _ _ _ = Nothing
+checkPrepared :: ExternalLock -> External -> Annex ()
+checkPrepared lck external =
+ fromExternal lck external externalPrepared $ \prepared ->
+ unless prepared $
+ handleRequest' lck external PREPARE Nothing $ \resp ->
+ case resp of
+ PREPARE_SUCCESS -> Just noop
+ _ -> Nothing
+
{- Caches the cost in the git config to avoid needing to start up an
- external special remote every time time just to ask it what its
- cost is. -}