startup check fixes

Move lsof check, and display a message before daemon startup if on an
unsupported OS.
This commit is contained in:
Joey Hess 2012-06-17 14:02:58 -04:00
parent e84b78f40c
commit 1863185693
2 changed files with 22 additions and 16 deletions

View file

@ -49,7 +49,6 @@ import Assistant.DaemonStatus
import Assistant.Watcher
import Assistant.Committer
import Assistant.SanityChecker
import qualified Annex
import qualified Utility.Daemon
import Utility.LogFile
@ -65,12 +64,8 @@ startDaemon foreground
pidfile <- fromRepo gitAnnexPidFile
go $ Utility.Daemon.daemonize logfd (Just pidfile) False
where
go a = ifM (liftIO $ inPath "lsof")
( go a
, ifM (Annex.getState Annex.force)
(start a, needlsof)
)
start a = withThreadState $ \st -> do
go a = withThreadState $ \st -> do
checkCanWatch
dstatus <- startDaemonStatus
liftIO $ a $ do
changechan <- newChangeChan
@ -84,12 +79,5 @@ startDaemon foreground
_ <- forkIO $ sanityCheckerThread st dstatus changechan
watchThread st dstatus changechan
needlsof = error $ unlines
[ "The lsof command is needed for watch mode to be safe, and is not in PATH."
, "To override lsof checks to ensure that files are not open for writing"
, "when added to the annex, you can use --force"
, "Be warned: This can corrupt data in the annex, and make fsck complain."
]
stopDaemon :: Annex ()
stopDaemon = liftIO . Utility.Daemon.stopDaemon =<< fromRepo gitAnnexPidFile

View file

@ -13,13 +13,14 @@ import Common.Annex
import Assistant.ThreadedMonad
import Assistant.DaemonStatus
import Assistant.Committer
import Utility.ThreadLock
import Utility.ThreadScheduler
import qualified Annex.Queue
import qualified Git.Command
import qualified Git.UpdateIndex
import qualified Git.HashObject
import qualified Git.LsFiles
import qualified Backend
import qualified Annex
import Annex.Content
import Annex.CatFile
import Git.Types
@ -35,6 +36,23 @@ import System.INotify
type Handler = FilePath -> Maybe FileStatus -> DaemonStatusHandle -> Annex (Maybe Change)
checkCanWatch :: Annex ()
checkCanWatch = do
#if defined linux_HOST_OS
unlessM (liftIO (inPath "lsof") <||> Annex.getState Annex.force) $
needLsof
#else
error "watch mode is currently only available in Linux"
#endif
needLsof :: Annex ()
needLsof = error $ unlines
[ "The lsof command is needed for watch mode to be safe, and is not in PATH."
, "To override lsof checks to ensure that files are not open for writing"
, "when added to the annex, you can use --force"
, "Be warned: This can corrupt data in the annex, and make fsck complain."
]
watchThread :: ThreadState -> DaemonStatusHandle -> ChangeChan -> IO ()
#if defined linux_HOST_OS
watchThread st dstatus changechan = withINotify $ \i -> do
@ -61,7 +79,7 @@ watchThread st dstatus changechan = withINotify $ \i -> do
, errHook = hook onErr
}
#else
watchThread = error "so far only available on Linux"
watchThread = undefined
#endif
ignored :: FilePath -> Bool