From ecc168aba30a0477381bcd2037c8d301368f3449 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 1 Aug 2012 16:10:26 -0400 Subject: implemented firstrun repository creation and redirection to full webapp Some of the trickiest code I've possibly ever written. --- Assistant.hs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'Assistant.hs') diff --git a/Assistant.hs b/Assistant.hs index 4bb85975b..be84fab55 100644 --- a/Assistant.hs +++ b/Assistant.hs @@ -122,7 +122,10 @@ import Utility.ThreadScheduler import Control.Concurrent -startDaemon :: Bool -> Bool -> Maybe (FilePath -> IO ()) -> Annex () +stopDaemon :: Annex () +stopDaemon = liftIO . Utility.Daemon.stopDaemon =<< fromRepo gitAnnexPidFile + +startDaemon :: Bool -> Bool -> Maybe (Url -> FilePath -> IO ()) -> Annex () startDaemon assistant foreground webappwaiter | foreground = do showStart (if assistant then "assistant" else "watch") "." @@ -132,10 +135,15 @@ startDaemon assistant foreground webappwaiter pidfile <- fromRepo gitAnnexPidFile go $ Utility.Daemon.daemonize logfd (Just pidfile) False where - go daemonize = withThreadState $ \st -> do - checkCanWatch - dstatus <- startDaemonStatus - liftIO $ daemonize $ run dstatus st + go d = startAssistant assistant d webappwaiter + +startAssistant :: Bool -> (IO () -> IO ()) -> Maybe (Url -> FilePath -> IO ()) -> Annex () +startAssistant assistant daemonize webappwaiter = do + withThreadState $ \st -> do + checkCanWatch + dstatus <- startDaemonStatus + liftIO $ daemonize $ run dstatus st + where run dstatus st = do changechan <- newChangeChan commitchan <- newCommitChan @@ -155,12 +163,8 @@ startDaemon assistant foreground webappwaiter , mountWatcherThread st dstatus scanremotes , transferScannerThread st dstatus scanremotes transferqueue #ifdef WITH_WEBAPP - , webAppThread (Just st) dstatus transferqueue webappwaiter + , webAppThread (Just st) dstatus transferqueue Nothing webappwaiter #endif , watchThread st dstatus transferqueue changechan ] - debug "Assistant" ["all threads started"] waitForTermination - -stopDaemon :: Annex () -stopDaemon = liftIO . Utility.Daemon.stopDaemon =<< fromRepo gitAnnexPidFile -- cgit v1.2.3