From 8c4bfe2f2141bce84ea22120da445c148b6f1168 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 6 Apr 2014 19:06:03 -0400 Subject: added git-annex remotedaemon So far, handling connecting to git-annex-shell notifychanges, and pulling immediately when a change is pushed to a remote. A little bit buggy (crashes after the first pull), but it already works! This commit was sponsored by Mark Sheppard. --- RemoteDaemon/Types.hs | 58 +++++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 27 deletions(-) (limited to 'RemoteDaemon/Types.hs') diff --git a/RemoteDaemon/Types.hs b/RemoteDaemon/Types.hs index b4b8ba066..5cb0ef758 100644 --- a/RemoteDaemon/Types.hs +++ b/RemoteDaemon/Types.hs @@ -10,74 +10,78 @@ module RemoteDaemon.Types where +import qualified Annex import qualified Git.Types as Git import qualified Utility.SimpleProtocol as Proto +import Control.Concurrent + +-- A Transport for a particular git remote consumes some messages +-- from a Chan, and emits others to another Chan. +type Transport = Git.Repo -> RemoteName -> Annex.AnnexState -> Chan Consumed -> Chan Emitted -> IO () + -- Messages that the daemon emits. data Emitted = CONNECTED RemoteName | DISCONNECTED RemoteName - | CHANGED RemoteName ShaList - | STATUS RemoteName UserMessage - | ERROR RemoteName UserMessage + | SYNCING RemoteName + | DONESYNCING RemoteName Bool -- Messages that the deamon consumes. data Consumed = PAUSE | RESUME - | PUSH RemoteName + | CHANGED RefList | RELOAD + | STOP type RemoteName = String -type UserMessage = String -type ShaList = [Git.Sha] +type RefList = [Git.Ref] instance Proto.Sendable Emitted where formatMessage (CONNECTED remote) = ["CONNECTED", Proto.serialize remote] formatMessage (DISCONNECTED remote) = ["DISCONNECTED", Proto.serialize remote] - formatMessage (CHANGED remote shas) = - ["CHANGED" - , Proto.serialize remote - , Proto.serialize shas - ] - formatMessage (STATUS remote msg) = - ["STATUS" - , Proto.serialize remote - , Proto.serialize msg - ] - formatMessage (ERROR remote msg) = - ["ERROR" - , Proto.serialize remote - , Proto.serialize msg - ] + formatMessage (SYNCING remote) = + ["SYNCING", Proto.serialize remote] + formatMessage (DONESYNCING remote status) = + ["DONESYNCING", Proto.serialize remote, Proto.serialize status] instance Proto.Sendable Consumed where formatMessage PAUSE = ["PAUSE"] formatMessage RESUME = ["RESUME"] - formatMessage (PUSH remote) = ["PUSH", Proto.serialize remote] + formatMessage (CHANGED refs) =["CHANGED", Proto.serialize refs] formatMessage RELOAD = ["RELOAD"] + formatMessage STOP = ["STOP"] instance Proto.Receivable Emitted where parseCommand "CONNECTED" = Proto.parse1 CONNECTED parseCommand "DISCONNECTED" = Proto.parse1 DISCONNECTED - parseCommand "CHANGED" = Proto.parse2 CHANGED - parseCommand "STATUS" = Proto.parse2 STATUS - parseCommand "ERROR" = Proto.parse2 ERROR + parseCommand "SYNCING" = Proto.parse1 SYNCING + parseCommand "DONESYNCING" = Proto.parse2 DONESYNCING parseCommand _ = Proto.parseFail instance Proto.Receivable Consumed where parseCommand "PAUSE" = Proto.parse0 PAUSE parseCommand "RESUME" = Proto.parse0 RESUME - parseCommand "PUSH" = Proto.parse1 PUSH + parseCommand "CHANGED" = Proto.parse1 CHANGED parseCommand "RELOAD" = Proto.parse0 RELOAD + parseCommand "STOP" = Proto.parse0 STOP parseCommand _ = Proto.parseFail instance Proto.Serializable [Char] where serialize = id deserialize = Just -instance Proto.Serializable ShaList where +instance Proto.Serializable RefList where serialize = unwords . map Git.fromRef deserialize = Just . map Git.Ref . words + +instance Proto.Serializable Bool where + serialize False = "0" + serialize True = "1" + + deserialize "0" = Just False + deserialize "1" = Just True + deserialize _ = Nothing -- cgit v1.2.3