Avoid crashing when built w/o inotify..
atomically $ closeTBMChan chan
drainChangedRefs h
-watchChangedRefs :: Annex ChangedRefsHandle
+watchChangedRefs :: Annex (Maybe ChangedRefsHandle)
watchChangedRefs = do
-- This channel is used to accumulate notifications,
-- because the DirWatcher might have multiple threads that find
, modifyHook = notifyhook
}
- h <- liftIO $ watchDir refdir (const False) True hooks id
- return $ ChangedRefsHandle h chan
+ if canWatch
+ then do
+ h <- liftIO $ watchDir refdir (const False) True hooks id
+ return $ Just $ ChangedRefsHandle h chan
+ else return Nothing
notifyHook :: TBMChan Git.Sha -> FilePath -> Maybe FileStatus -> IO ()
notifyHook chan reffile _
seek = withNothing start
start :: CommandStart
-start = do
- h <- watchChangedRefs
-
- -- No messages need to be received from the caller,
- -- but when it closes the connection, notice and terminate.
- let receiver = forever $ void $ getProtocolLine stdin
- let sender = forever $ send . CHANGED =<< waitChangedRefs h
-
- liftIO $ send READY
- void $ liftIO $ concurrently sender receiver
- liftIO $ stopWatchingChangedRefs h
- stop
+start = go =<< watchChangedRefs
+ where
+ go (Just h) = do
+ -- No messages need to be received from the caller,
+ -- but when it closes the connection, notice and terminate.
+ let receiver = forever $ void $ getProtocolLine stdin
+ let sender = forever $ send . CHANGED =<< waitChangedRefs h
+
+ liftIO $ send READY
+ void $ liftIO $ concurrently sender receiver
+ liftIO $ stopWatchingChangedRefs h
+ stop
+ go Nothing = stop
send :: Notification -> IO ()
send n = do
import Control.Monad.Free
data RunMode
- = Serving UUID ChangedRefsHandle
+ = Serving UUID (Maybe ChangedRefsHandle)
| Client
-- Full interpreter for Proto, that can receive and send objects.
next
Right _ -> runner next
WaitRefChange next -> case runmode of
- Serving _ h -> do
+ Serving _ (Just h) -> do
v <- tryNonAsync $ liftIO $ waitChangedRefs h
case v of
Left e -> return (Left (show e))
Right changedrefs -> runner (next changedrefs)
- _ -> return $ Left "change notification not implemented for client"
+ _ -> return $ Left "change notification not available"
where
transfer mk k af ta = case runmode of
-- Update transfer logs when serving.
liftAnnex th $ mergeState st'
authed conn theiruuid =
- bracket watchChangedRefs (liftIO . stopWatchingChangedRefs) $ \crh -> do
+ bracket watchChangedRefs (liftIO . maybe noop stopWatchingChangedRefs) $ \crh -> do
v' <- runFullProto (Serving theiruuid crh) conn $
P2P.serveAuthed u
case v' of