summaryrefslogtreecommitdiff
path: root/Assistant.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-08-01 16:10:26 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-08-01 16:10:26 -0400
commitecc168aba30a0477381bcd2037c8d301368f3449 (patch)
tree13efe09744264cea284f87a0179a6b6023f987d6 /Assistant.hs
parent1efe4f3332680be5ad9d5d496939d6757fbd2b0a (diff)
implemented firstrun repository creation and redirection to full webapp
Some of the trickiest code I've possibly ever written.
Diffstat (limited to 'Assistant.hs')
-rw-r--r--Assistant.hs24
1 files changed, 14 insertions, 10 deletions
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