simplified
background transferrs seem to work now
This commit is contained in:
parent
430ad8ce85
commit
3d30a45e72
1 changed files with 8 additions and 19 deletions
|
@ -29,31 +29,20 @@ maxTransfers = 1
|
||||||
transfererThread :: ThreadState -> DaemonStatusHandle -> TransferQueue -> TransferSlots -> IO ()
|
transfererThread :: ThreadState -> DaemonStatusHandle -> TransferQueue -> TransferSlots -> IO ()
|
||||||
transfererThread st dstatus transferqueue slots = runEvery (Seconds 1) $ do
|
transfererThread st dstatus transferqueue slots = runEvery (Seconds 1) $ do
|
||||||
(t, info) <- getNextTransfer transferqueue
|
(t, info) <- getNextTransfer transferqueue
|
||||||
c <- runThreadState st $ shouldTransfer dstatus t
|
whenM (runThreadState st $ shouldTransfer dstatus t) $
|
||||||
let run = void $ inTransferSlot slots $
|
void $ inTransferSlot slots $
|
||||||
runTransfer st dstatus t info
|
runTransfer st dstatus t info
|
||||||
case c of
|
|
||||||
Yes -> run
|
|
||||||
Skip -> noop
|
|
||||||
TooMany -> waitTransfer >> run
|
|
||||||
|
|
||||||
data ShouldTransfer = Yes | Skip | TooMany
|
|
||||||
|
|
||||||
{- Checks if the requested transfer is already running, or
|
{- Checks if the requested transfer is already running, or
|
||||||
- the file to download is already present.
|
- the file to download is already present. -}
|
||||||
-
|
shouldTransfer :: DaemonStatusHandle -> Transfer -> Annex Bool
|
||||||
- There also may be too many transfers already running to service this
|
|
||||||
- transfer yet. -}
|
|
||||||
shouldTransfer :: DaemonStatusHandle -> Transfer -> Annex ShouldTransfer
|
|
||||||
shouldTransfer dstatus t = go =<< currentTransfers <$> getDaemonStatus dstatus
|
shouldTransfer dstatus t = go =<< currentTransfers <$> getDaemonStatus dstatus
|
||||||
where
|
where
|
||||||
go m
|
go m
|
||||||
| M.member t m = return Skip
|
| M.member t m = return False
|
||||||
| M.size m > maxTransfers = return TooMany
|
|
||||||
| transferDirection t == Download =
|
| transferDirection t == Download =
|
||||||
ifM (inAnnex $ transferKey t)
|
inAnnex $ transferKey t
|
||||||
(return Skip, return Yes)
|
| otherwise = return True
|
||||||
| otherwise = return Yes
|
|
||||||
|
|
||||||
{- Waits for any of the transfers in the map to complete. -}
|
{- Waits for any of the transfers in the map to complete. -}
|
||||||
waitTransfer :: IO ()
|
waitTransfer :: IO ()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue