make tor hidden service work when directory watching is not available

Avoid crashing when built w/o inotify..
This commit is contained in:
Joey Hess 2016-12-09 16:27:20 -04:00
parent 8ac4126bd2
commit 9dd510bf29
No known key found for this signature in database
GPG key ID: C910D9222512E3C7
4 changed files with 22 additions and 18 deletions

View file

@ -71,7 +71,7 @@ stopWatchingChangedRefs h@(ChangedRefsHandle wh chan) = do
atomically $ closeTBMChan chan atomically $ closeTBMChan chan
drainChangedRefs h drainChangedRefs h
watchChangedRefs :: Annex ChangedRefsHandle watchChangedRefs :: Annex (Maybe ChangedRefsHandle)
watchChangedRefs = do watchChangedRefs = do
-- This channel is used to accumulate notifications, -- This channel is used to accumulate notifications,
-- because the DirWatcher might have multiple threads that find -- because the DirWatcher might have multiple threads that find
@ -90,8 +90,11 @@ watchChangedRefs = do
, modifyHook = notifyhook , modifyHook = notifyhook
} }
h <- liftIO $ watchDir refdir (const False) True hooks id if canWatch
return $ ChangedRefsHandle h chan 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 :: TBMChan Git.Sha -> FilePath -> Maybe FileStatus -> IO ()
notifyHook chan reffile _ notifyHook chan reffile _

View file

@ -24,18 +24,19 @@ seek :: CmdParams -> CommandSeek
seek = withNothing start seek = withNothing start
start :: CommandStart start :: CommandStart
start = do start = go =<< watchChangedRefs
h <- 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
-- No messages need to be received from the caller, liftIO $ send READY
-- but when it closes the connection, notice and terminate. void $ liftIO $ concurrently sender receiver
let receiver = forever $ void $ getProtocolLine stdin liftIO $ stopWatchingChangedRefs h
let sender = forever $ send . CHANGED =<< waitChangedRefs h stop
go Nothing = stop
liftIO $ send READY
void $ liftIO $ concurrently sender receiver
liftIO $ stopWatchingChangedRefs h
stop
send :: Notification -> IO () send :: Notification -> IO ()
send n = do send n = do

View file

@ -26,7 +26,7 @@ import Utility.Metered
import Control.Monad.Free import Control.Monad.Free
data RunMode data RunMode
= Serving UUID ChangedRefsHandle = Serving UUID (Maybe ChangedRefsHandle)
| Client | Client
-- Full interpreter for Proto, that can receive and send objects. -- Full interpreter for Proto, that can receive and send objects.
@ -114,12 +114,12 @@ runLocal runmode runner a = case a of
next next
Right _ -> runner next Right _ -> runner next
WaitRefChange next -> case runmode of WaitRefChange next -> case runmode of
Serving _ h -> do Serving _ (Just h) -> do
v <- tryNonAsync $ liftIO $ waitChangedRefs h v <- tryNonAsync $ liftIO $ waitChangedRefs h
case v of case v of
Left e -> return (Left (show e)) Left e -> return (Left (show e))
Right changedrefs -> runner (next changedrefs) Right changedrefs -> runner (next changedrefs)
_ -> return $ Left "change notification not implemented for client" _ -> return $ Left "change notification not available"
where where
transfer mk k af ta = case runmode of transfer mk k af ta = case runmode of
-- Update transfer logs when serving. -- Update transfer logs when serving.

View file

@ -110,7 +110,7 @@ serveClient th u r q = bracket setup cleanup start
liftAnnex th $ mergeState st' liftAnnex th $ mergeState st'
authed conn theiruuid = authed conn theiruuid =
bracket watchChangedRefs (liftIO . stopWatchingChangedRefs) $ \crh -> do bracket watchChangedRefs (liftIO . maybe noop stopWatchingChangedRefs) $ \crh -> do
v' <- runFullProto (Serving theiruuid crh) conn $ v' <- runFullProto (Serving theiruuid crh) conn $
P2P.serveAuthed u P2P.serveAuthed u
case v' of case v' of