summaryrefslogtreecommitdiff
path: root/Assistant
diff options
context:
space:
mode:
Diffstat (limited to 'Assistant')
-rw-r--r--Assistant/Threads/TransferPoller.hs22
-rw-r--r--Assistant/Threads/TransferWatcher.hs20
-rw-r--r--Assistant/Threads/Watcher.hs2
3 files changed, 38 insertions, 6 deletions
diff --git a/Assistant/Threads/TransferPoller.hs b/Assistant/Threads/TransferPoller.hs
index f8f9388f0..10ed7dd31 100644
--- a/Assistant/Threads/TransferPoller.hs
+++ b/Assistant/Threads/TransferPoller.hs
@@ -12,6 +12,7 @@ import Assistant.ThreadedMonad
import Assistant.DaemonStatus
import Logs.Transfer
import Utility.NotificationBroadcaster
+import qualified Assistant.Threads.TransferWatcher as TransferWatcher
import Control.Concurrent
import qualified Data.Map as M
@@ -42,9 +43,20 @@ transferPollerThread st dstatus = thread $ do
sz <- catchMaybeIO $
fromIntegral . fileSize
<$> getFileStatus f
- when (bytesComplete info /= sz && isJust sz) $
- alterTransferInfo dstatus t $
- \i -> i { bytesComplete = sz }
- {- Can't poll uploads, instead the upload code
- - updates the files. -}
+ newsize t info sz
+ {- Uploads don't need to be polled for when the
+ - TransferWatcher thread can track file
+ - modifications. -}
+ | TransferWatcher.watchesTransferSize = noop
+ {- Otherwise, this code polls the upload progress
+ - by reading the transfer info file. -}
+ | otherwise = do
+ let f = transferFile t g
+ mi <- catchDefaultIO Nothing $
+ readTransferInfoFile Nothing f
+ maybe noop (newsize t info . bytesComplete) mi
+ newsize t info sz
+ | bytesComplete info /= sz && isJust sz =
+ alterTransferInfo dstatus t $
+ \i -> i { bytesComplete = sz }
| otherwise = noop
diff --git a/Assistant/Threads/TransferWatcher.hs b/Assistant/Threads/TransferWatcher.hs
index ce0708a91..d4ff9176e 100644
--- a/Assistant/Threads/TransferWatcher.hs
+++ b/Assistant/Threads/TransferWatcher.hs
@@ -30,6 +30,7 @@ transferWatcherThread st dstatus transferqueue = thread $ do
let hooks = mkWatchHooks
{ addHook = hook onAdd
, delHook = hook onDel
+ , modifyHook = hook onModify
, errHook = hook onErr
}
void $ watchDir dir (const False) hooks id
@@ -71,6 +72,25 @@ onAdd st dstatus _ file _ = case parseTransferFile file of
{ transferRemote = r }
sameuuid t r = Remote.uuid r == transferUUID t
+{- Called when a transfer information file is updated.
+ -
+ - The only thing that should change in the transfer info is the
+ - bytesComplete, so that's the only thing updated in the DaemonStatus. -}
+onModify :: Handler
+onModify _ dstatus _ file _ = do
+ case parseTransferFile file of
+ Nothing -> noop
+ Just t -> go t =<< readTransferInfoFile Nothing file
+ where
+ go _ Nothing = noop
+ go t (Just newinfo) = alterTransferInfo dstatus t $ \info ->
+ info { bytesComplete = bytesComplete newinfo }
+
+{- This thread can only watch transfer sizes when the DirWatcher supports
+ - tracking modificatons to files. -}
+watchesTransferSize :: Bool
+watchesTransferSize = modifyTracked
+
{- Called when a transfer information file is removed. -}
onDel :: Handler
onDel st dstatus transferqueue file _ = case parseTransferFile file of
diff --git a/Assistant/Threads/Watcher.hs b/Assistant/Threads/Watcher.hs
index fa8b7b379..41396a23c 100644
--- a/Assistant/Threads/Watcher.hs
+++ b/Assistant/Threads/Watcher.hs
@@ -67,7 +67,7 @@ watchThread st dstatus transferqueue changechan = NamedThread thisThread $ do
where
startup = startupScan st dstatus
hook delay a = Just $ runHandler thisThread delay st dstatus transferqueue changechan a
- hooks delayadd = WatchHooks
+ hooks delayadd = mkWatchHooks
{ addHook = hook (Seconds <$> delayadd) onAdd
, delHook = hook Nothing onDel
, addSymlinkHook = hook Nothing onAddSymlink