diff options
Diffstat (limited to 'Command/Watch.hs')
-rw-r--r-- | Command/Watch.hs | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/Command/Watch.hs b/Command/Watch.hs index 8b8e5578d..f01a9616f 100644 --- a/Command/Watch.hs +++ b/Command/Watch.hs @@ -50,27 +50,36 @@ data Change = Change deriving (Show) def :: [Command] -def = [withOptions [foregroundOption] $ +def = [withOptions [foregroundOption, stopOption] $ command "watch" paramPaths seek "watch for changes"] seek :: [CommandSeek] -seek = [withFlag foregroundOption $ withNothing . start] +seek = [withFlag stopOption $ \stopdaemon -> + withFlag foregroundOption $ \foreground -> + withNothing $ start foreground stopdaemon] foregroundOption :: Option foregroundOption = Option.flag [] "foreground" "do not daemonize" -start :: Bool -> CommandStart -start foreground = notBareRepo $ withStateMVar $ \st -> do - if foreground - then do - showStart "watch" "." - liftIO $ watch st - else do - logfd <- liftIO . openLog =<< fromRepo gitAnnexLogFile - pidfile <- fromRepo gitAnnexPidFile - liftIO $ daemonize logfd (Just pidfile) False $ watch st +stopOption :: Option +stopOption = Option.flag [] "stop" "stop daemon" + +start :: Bool -> Bool -> CommandStart +start foreground stopdaemon = notBareRepo $ do + if stopdaemon + then liftIO . stopDaemon =<< fromRepo gitAnnexPidFile + else withStateMVar $ startDaemon (not foreground) stop +startDaemon :: Bool -> MVar Annex.AnnexState -> Annex () +startDaemon False st = do + showStart "watch" "." + liftIO $ watch st +startDaemon True st = do + logfd <- liftIO . openLog =<< fromRepo gitAnnexLogFile + pidfile <- fromRepo gitAnnexPidFile + liftIO $ daemonize logfd (Just pidfile) False $ watch st + watch :: MVar Annex.AnnexState -> IO () #if defined linux_HOST_OS watch st = withINotify $ \i -> do |