summaryrefslogtreecommitdiff
path: root/Assistant
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-10-09 12:18:41 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-10-09 12:18:41 -0400
commit5aca7af2f702aa508ec5949e1fddbee429a93db5 (patch)
treef941ab8fc820ced727c3e5a024d1e0ec0cfcb559 /Assistant
parenta7d8c4101c4cc476323ce0fca372b01198167773 (diff)
assistant: Now honors preferred content settings when deciding what to transfer.
Both when queueing downloads, and uploads, consults the preferred content settings. I didn't make it check yet when requeing failed transfers or queuing deferred downloads; dealing with the preferred content settings (or indeed, other settings) changing while the assistant is running still needs work.
Diffstat (limited to 'Assistant')
-rw-r--r--Assistant/Threads/Committer.hs2
-rw-r--r--Assistant/Threads/TransferScanner.hs15
-rw-r--r--Assistant/TransferQueue.hs33
3 files changed, 28 insertions, 22 deletions
diff --git a/Assistant/Threads/Committer.hs b/Assistant/Threads/Committer.hs
index 6b036d09a..b791dcc82 100644
--- a/Assistant/Threads/Committer.hs
+++ b/Assistant/Threads/Committer.hs
@@ -210,7 +210,7 @@ handleAdds delayadd st changechan transferqueue dstatus cs = returnWhen (null in
sha <- inRepo $
Git.HashObject.hashObject BlobObject link
stageSymlink file sha
- queueTransfers Next transferqueue dstatus key (Just file) Upload
+ queueTransfers Next transferqueue dstatus st key (Just file) Upload
showEndOk
return $ Just change
diff --git a/Assistant/Threads/TransferScanner.hs b/Assistant/Threads/TransferScanner.hs
index cb02ed2f2..85275374d 100644
--- a/Assistant/Threads/TransferScanner.hs
+++ b/Assistant/Threads/TransferScanner.hs
@@ -22,6 +22,7 @@ import Utility.ThreadScheduler
import qualified Git.LsFiles as LsFiles
import Command
import Annex.Content
+import Annex.Wanted
import qualified Data.Set as S
@@ -105,18 +106,20 @@ expensiveScan st dstatus transferqueue rs = unless onlyweb $ do
in if null rs' then rs else rs'
go [] = noop
go (f:fs) = do
- mapM_ (enqueue f) =<< catMaybes <$> runThreadState st
- (ifAnnexed f findtransfers $ return [])
+ mapM_ (enqueue f) =<< runThreadState st
+ (ifAnnexed f (findtransfers f) $ return [])
go fs
enqueue f (r, t) = do
debug thisThread ["queuing", show t]
queueTransferWhenSmall transferqueue dstatus (Just f) t r
- findtransfers (key, _) = do
+ findtransfers f (key, _) = do
locs <- loggedLocations key
- let use a = return $ map (a key locs) rs
+ let use a = return $ catMaybes $ map (a key locs) rs
ifM (inAnnex key)
- ( use $ check Upload False
- , use $ check Download True
+ ( filterM (wantSend (Just f) . Remote.uuid . fst)
+ =<< use (check Upload False)
+ , ifM (wantGet $ Just f)
+ ( use (check Download True) , return [] )
)
check direction want key locs r
| direction == Upload && Remote.readonly r = Nothing
diff --git a/Assistant/TransferQueue.hs b/Assistant/TransferQueue.hs
index e2c3f167b..9b081d32e 100644
--- a/Assistant/TransferQueue.hs
+++ b/Assistant/TransferQueue.hs
@@ -27,6 +27,7 @@ import Logs.Transfer
import Types.Remote
import qualified Remote
import qualified Types.Remote as Remote
+import Annex.Wanted
import Control.Concurrent.STM
import qualified Data.Map as M
@@ -56,22 +57,26 @@ stubInfo f r = stubTransferInfo
, associatedFile = f
}
-{- Adds transfers to queue for some of the known remotes. -}
+{- Adds transfers to queue for some of the known remotes.
+ - Honors preferred content settings, only transferring wanted files. -}
queueTransfers :: Schedule -> TransferQueue -> DaemonStatusHandle -> Key -> AssociatedFile -> Direction -> Annex ()
queueTransfers = queueTransfersMatching (const True)
{- Adds transfers to queue for some of the known remotes, that match a
- - condition. -}
+ - condition. Honors preferred content settings. -}
queueTransfersMatching :: (UUID -> Bool) -> Schedule -> TransferQueue -> DaemonStatusHandle -> Key -> AssociatedFile -> Direction -> Annex ()
-queueTransfersMatching matching schedule q dstatus k f direction = do
- rs <- sufficientremotes
- =<< knownRemotes <$> liftIO (getDaemonStatus dstatus)
- let matchingrs = filter (matching . Remote.uuid) rs
- if null matchingrs
- then defer
- else forM_ matchingrs $ \r -> liftIO $
- enqueue schedule q dstatus (gentransfer r) (stubInfo f r)
+queueTransfersMatching matching schedule q dstatus k f direction
+ | direction == Download = whenM (wantGet f) go
+ | otherwise = go
where
+ go = do
+ rs <- sufficientremotes
+ =<< knownRemotes <$> liftIO (getDaemonStatus dstatus)
+ let matchingrs = filter (matching . Remote.uuid) rs
+ if null matchingrs
+ then defer
+ else forM_ matchingrs $ \r -> liftIO $
+ enqueue schedule q dstatus (gentransfer r) (stubInfo f r)
sufficientremotes rs
{- Queue downloads from all remotes that
- have the key, with the cheapest ones first.
@@ -80,11 +85,9 @@ queueTransfersMatching matching schedule q dstatus k f direction = do
| direction == Download = do
uuids <- Remote.keyLocations k
return $ filter (\r -> uuid r `elem` uuids) rs
- {- TODO: Determine a smaller set of remotes that
- - can be uploaded to, in order to ensure all
- - remotes can access the content. Currently,
- - send to every remote we can. -}
- | otherwise = return $ filter (not . Remote.readonly) rs
+ {- Upload to all remotes that want the content. -}
+ | otherwise = filterM (wantSend f . Remote.uuid) $
+ filter (not . Remote.readonly) rs
gentransfer r = Transfer
{ transferDirection = direction
, transferKey = k