summaryrefslogtreecommitdiff
path: root/Assistant/Threads/Merger.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-03-06 15:09:31 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-03-06 15:09:31 -0400
commit49b88039e597ec761227d00ddf125f8ebe5c6a4f (patch)
tree660cbf757c53229b12629f0da29a0d405a95bed2 /Assistant/Threads/Merger.hs
parent32743077f40eeb21eb3fc230c1d2a46b1b1181e4 (diff)
assistant: Get back in sync with XMPP remotes after network reconnection, and on startup.
Make manualPull send push requests over XMPP. When reconnecting with remotes, those that are XMPP remotes cannot immediately be pulled from and scanned, so instead maintain a set of (probably) desynced remotes, and put XMPP remotes on it. (This set could be used in other ways later, if we can detect we're out of sync with other types of remotes.) The merger handles detecting when a XMPP push is received from a desynced remote, and triggers a scan then, if they have in fact diverged. This has one known bug: A single XMPP remote can have multiple clients behind it. When this happens, only the UUID of one client is recorded as the UUID of the XMPP remote. Pushes from the other XMPP clients will not trigger a scan. If the client whose UUID is expected responds to the push request, it'll work, but when that client is offline, we're SOL.
Diffstat (limited to 'Assistant/Threads/Merger.hs')
-rw-r--r--Assistant/Threads/Merger.hs29
1 files changed, 27 insertions, 2 deletions
diff --git a/Assistant/Threads/Merger.hs b/Assistant/Threads/Merger.hs
index 1488a2f0d..d88cf00bd 100644
--- a/Assistant/Threads/Merger.hs
+++ b/Assistant/Threads/Merger.hs
@@ -10,12 +10,18 @@ module Assistant.Threads.Merger where
import Assistant.Common
import Assistant.TransferQueue
import Assistant.BranchChange
+import Assistant.DaemonStatus
+import Assistant.ScanRemotes
import Utility.DirWatcher
import Utility.Types.DirWatcher
import qualified Annex.Branch
import qualified Git
import qualified Git.Branch
import qualified Command.Sync
+import Annex.TaggedPush
+import Remote (remoteFromUUID)
+
+import qualified Data.Set as S
{- This thread watches for changes to .git/refs/, and handles incoming
- pushes. -}
@@ -64,13 +70,16 @@ onAdd file
| ".lock" `isSuffixOf` file = noop
| isAnnexBranch file = do
branchChanged
- whenM (liftAnnex Annex.Branch.forceUpdate) $
- queueDeferredDownloads "retrying deferred download" Later
+ diverged <- liftAnnex Annex.Branch.forceUpdate
+ when diverged $
+ unlessM handleDesynced $
+ queueDeferredDownloads "retrying deferred download" Later
| "/synced/" `isInfixOf` file = do
mergecurrent =<< liftAnnex (inRepo Git.Branch.current)
| otherwise = noop
where
changedbranch = fileToBranch file
+
mergecurrent (Just current)
| equivBranches changedbranch current = do
debug
@@ -80,6 +89,22 @@ onAdd file
void $ liftAnnex $ Command.Sync.mergeFrom changedbranch
mergecurrent _ = noop
+ handleDesynced = case branchTaggedBy changedbranch of
+ Nothing -> return False
+ Just u -> do
+ s <- desynced <$> getDaemonStatus
+ if S.member u s
+ then do
+ modifyDaemonStatus_ $ \st -> st
+ { desynced = S.delete u s }
+ mr <- liftAnnex $ remoteFromUUID u
+ case mr of
+ Just r -> do
+ addScanRemotes True [r]
+ return True
+ Nothing -> return False
+ else return False
+
equivBranches :: Git.Ref -> Git.Ref -> Bool
equivBranches x y = base x == base y
where