summaryrefslogtreecommitdiff
path: root/Remote.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-06-01 19:10:38 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-06-01 19:11:27 -0400
commit971ab27e7820a3228f71dd42f3e870c0fc2f4345 (patch)
treef54a3fed5d3a161c5e6caff8954002f830ec8eed /Remote.hs
parent80efafe4960e0fb33d1e6783bd34eaf459febea1 (diff)
better types allowed breaking module dep loop
Diffstat (limited to 'Remote.hs')
-rw-r--r--Remote.hs28
1 files changed, 28 insertions, 0 deletions
diff --git a/Remote.hs b/Remote.hs
index 51da5e471..9685b4612 100644
--- a/Remote.hs
+++ b/Remote.hs
@@ -14,6 +14,7 @@ module Remote (
removeKey,
hasKey,
hasKeyCheap,
+ keyPossibilities,
remoteTypes,
genList,
@@ -45,6 +46,8 @@ import qualified Annex
import Locations
import Utility
import Config
+import Trust
+import LocationLog
import qualified Remote.Git
import qualified Remote.S3
@@ -110,6 +113,31 @@ remotesWithUUID rs us = filter (\r -> uuid r `elem` us) rs
remotesWithoutUUID :: [Remote Annex] -> [UUID] -> [Remote Annex]
remotesWithoutUUID rs us = filter (\r -> uuid r `notElem` us) rs
+{- Cost ordered lists of remotes that the LocationLog indicate may have a key.
+ -
+ - Also returns a list of UUIDs that are trusted to have the key
+ - (some may not have configured remotes).
+ -}
+keyPossibilities :: Key -> Annex ([Remote Annex], [UUID])
+keyPossibilities key = do
+ g <- Annex.gitRepo
+ u <- getUUID g
+ trusted <- trustGet Trusted
+
+ -- get uuids of all remotes that are recorded to have the key
+ uuids <- liftIO $ keyLocations g key
+ let validuuids = filter (/= u) uuids
+
+ -- note that validuuids is assumed to not have dups
+ let validtrusteduuids = intersect validuuids trusted
+
+ -- remotes that match uuids that have the key
+ allremotes <- genList
+ let validremotes = remotesWithUUID allremotes validuuids
+
+ return (sort validremotes, validtrusteduuids)
+
+
{- Filename of remote.log. -}
remoteLog :: Annex FilePath
remoteLog = do