built IO side of xmppReceivePack

This commit is contained in:
Joey Hess 2012-11-06 16:36:44 -04:00
parent f6bcab3f57
commit af44b7ec15

View file

@ -16,7 +16,7 @@ import Assistant.MakeRemote
import Assistant.Sync import Assistant.Sync
import Annex.UUID import Annex.UUID
import Config import Config
import Git.Types import Git
import Git.Command import Git.Command
import Locations.UserConfig import Locations.UserConfig
import qualified Types.Remote as Remote import qualified Types.Remote as Remote
@ -25,6 +25,7 @@ import Network.Protocol.XMPP
import qualified Data.Text as T import qualified Data.Text as T
import System.Posix.Env import System.Posix.Env
import System.Posix.Types import System.Posix.Types
import System.Process (std_in, std_out, std_err)
import Control.Concurrent import Control.Concurrent
import qualified Data.ByteString as B import qualified Data.ByteString as B
@ -172,15 +173,28 @@ xmppReceivePack :: Assistant Bool
xmppReceivePack = do xmppReceivePack = do
feeder <- asIO1 toxmpp feeder <- asIO1 toxmpp
reader <- asIO1 fromxmpp reader <- asIO1 fromxmpp
ok <- liftIO $ do controller <- asIO1 controlxmpp
(Just inh, Just outh, _, pid) <- createProcess $ p repodir <- liftAnnex $ fromRepo repoPath
{ std_in = CreatePipe let p = (proc "git" ["receive-pack", repodir])
, std_out = CreatePipe { std_in = CreatePipe
, std_err = Inherit , std_out = CreatePipe
} , std_err = Inherit
}
liftIO $ mapM_ killThread [t1, t2] liftIO $ do
(Just inh, Just outh, _, pid) <- createProcess p
feedertid <- forkIO $ feeder outh
void $ reader inh
code <- waitForProcess pid
void $ controller code
killThread feedertid
return $ code == ExitSuccess
where where
p = proc "git" params toxmpp outh = do
toxmpp = b <- liftIO $ B.hGetSome outh 1024
fromxmpp = if B.null b
then return () -- EOF
else do
error "TODO feed b to xmpp"
toxmpp outh
fromxmpp _inh = error "TODO feed xmpp to inh"
controlxmpp _code = error "TODO propigate exit code"