This commit is contained in:
Joey Hess 2012-10-29 17:02:50 -04:00
parent 1852eddce6
commit d5a5c05a79
5 changed files with 15 additions and 13 deletions

View file

@ -181,8 +181,8 @@ adjustTransfersSTM dstatus a = do
putTMVar dstatus $ s { currentTransfers = a (currentTransfers s) }
{- Alters a transfer's info, if the transfer is in the map. -}
alterTransferInfo :: Transfer -> (TransferInfo -> TransferInfo) -> DaemonStatusHandle -> IO ()
alterTransferInfo t a dstatus = updateTransferInfo' dstatus $ M.adjust a t
alterTransferInfo :: DaemonStatusHandle -> Transfer -> (TransferInfo -> TransferInfo) -> IO ()
alterTransferInfo dstatus t a = updateTransferInfo' dstatus $ M.adjust a t
{- Updates a transfer's info. Adds the transfer to the map if necessary,
- or if already present, updates it while preserving the old transferTid,

View file

@ -13,6 +13,7 @@ module Assistant.Monad (
newAssistantData,
runAssistant,
getAssistant,
withAssistant,
liftAnnex,
(<~>),
(<<~),
@ -111,5 +112,7 @@ asIO2 a = do
(<<~) :: (a -> IO b) -> (AssistantData -> a) -> Assistant b
io <<~ v = reader v >>= liftIO . io
withAssistant v io = io <<~ v
daemonStatus :: Assistant DaemonStatus
daemonStatus = getDaemonStatus <<~ daemonStatusHandle

View file

@ -52,6 +52,7 @@ transferPollerThread = NamedThread "TransferPoller" $ do
newsize t info sz
| bytesComplete info /= sz && isJust sz =
alterTransferInfo t (\i -> i { bytesComplete = sz })
<<~ daemonStatusHandle
withAssistant daemonStatusHandle $ \h ->
alterTransferInfo h t $
\i -> i { bytesComplete = sz }
| otherwise = noop

View file

@ -79,9 +79,9 @@ onModify file = do
Just t -> go t =<< liftIO (readTransferInfoFile Nothing file)
where
go _ Nothing = noop
go t (Just newinfo) = alterTransferInfo t
(\i -> i { bytesComplete = bytesComplete newinfo })
<<~ daemonStatusHandle
go t (Just newinfo) = withAssistant daemonStatusHandle $ \h ->
alterTransferInfo h t $
\i -> i { bytesComplete = bytesComplete newinfo }
{- This thread can only watch transfer sizes when the DirWatcher supports
- tracking modificatons to files. -}

View file

@ -88,9 +88,8 @@ cancelTransfer pause t = do
maybe noop killproc $ transferPid info
if pause
then void $
alterTransferInfo t
(\i -> i { transferPaused = True })
dstatus
alterTransferInfo dstatus t $
\i -> i { transferPaused = True }
else void $
removeTransfer dstatus t
signalthread tid
@ -119,9 +118,8 @@ startTransfer t = do
resume tid = do
dstatus <- getAssistantY daemonStatusHandle
liftIO $ do
alterTransferInfo t
(\i -> i { transferPaused = False })
dstatus
alterTransferInfo dstatus t $
\i -> i { transferPaused = False }
throwTo tid ResumeTransfer
start info = runAssistantY $ do
program <- liftIO readProgramFile