summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-09-23 15:35:00 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-09-23 15:35:00 -0400
commit0732d4c8efcc383919b9016881125dd147886121 (patch)
tree92c5b7e8a783f53df5796595a6aa5abaebcb4e8b
parent90eea19ea2bc96070fef376cb4d35df35a1c49e5 (diff)
parentf0bcc77fb245c5fccadff728fd816471fd9993bf (diff)
Merge remote-tracking branch 'npouillard/trustedcopies'
-rw-r--r--Limit.hs18
-rw-r--r--Logs/Trust.hs19
2 files changed, 26 insertions, 11 deletions
diff --git a/Limit.hs b/Limit.hs
index 0db418e6c..57d6ebf65 100644
--- a/Limit.hs
+++ b/Limit.hs
@@ -16,6 +16,7 @@ import qualified Utility.Matcher
import qualified Remote
import qualified Backend
import Annex.Content
+import Logs.Trust
type Limit = Utility.Matcher.Token (FilePath -> Annex Bool)
@@ -83,16 +84,21 @@ addIn name = addLimit $ check $ if name == "." then inAnnex else inremote
{- Adds a limit to skip files not believed to have the specified number
- of copies. -}
addCopies :: String -> Annex ()
-addCopies num =
- case readish num :: Maybe Int of
- Nothing -> error "bad number for --copies"
- Just n -> addLimit $ check n
- where
+addCopies trust_num = addLimit . check $ readnum num
+ where (num, mayCheckTrust) =
+ case split ":" trust_num of
+ [trust, num'] -> (num', checkTrust (readtrust trust))
+ [num'] -> (num', const (return True))
+ _ -> bad
+ readnum = maybe bad id . readish
+ readtrust = maybe bad id . readTrust
check n = Backend.lookupFile >=> handle n
handle _ Nothing = return False
handle n (Just (key, _)) = do
- us <- Remote.keyLocations key
+ us <- filterM mayCheckTrust =<< Remote.keyLocations key
return $ length us >= n
+ checkTrust t u = (== t) <$> lookupTrust u -- == or >=
+ bad = error "bad number or trust:number for --copies"
{- Adds a limit to skip files not using a specified key-value backend. -}
addInBackend :: String -> Annex ()
diff --git a/Logs/Trust.hs b/Logs/Trust.hs
index 1a6716d17..161c9fb45 100644
--- a/Logs/Trust.hs
+++ b/Logs/Trust.hs
@@ -10,6 +10,8 @@ module Logs.Trust (
trustGet,
trustSet,
trustPartition,
+ readTrust,
+ lookupTrust,
) where
import qualified Data.Map as M
@@ -44,6 +46,10 @@ trustSet uuid@(UUID _) level = do
Annex.changeState $ \s -> s { Annex.trustmap = Nothing }
trustSet NoUUID _ = error "unknown UUID; cannot modify trust level"
+{- Returns the TrustLevel of a given repo UUID. -}
+lookupTrust :: UUID -> Annex TrustLevel
+lookupTrust u = (fromMaybe SemiTrusted . M.lookup u) <$> trustMap
+
{- Partitions a list of UUIDs to those matching a TrustLevel and not. -}
trustPartition :: TrustLevel -> [UUID] -> Annex ([UUID], [UUID])
trustPartition level ls
@@ -76,12 +82,15 @@ trustMap = do
where
configuredtrust r =
maybe Nothing (\l -> Just (Types.Remote.uuid r, l)) <$>
- maybe Nothing convert <$>
+ maybe Nothing readTrust <$>
getTrustLevel (Types.Remote.repo r)
- convert "trusted" = Just Trusted
- convert "untrusted" = Just UnTrusted
- convert "semitrusted" = Just SemiTrusted
- convert _ = Nothing
+
+readTrust :: String -> Maybe TrustLevel
+readTrust "trusted" = Just Trusted
+readTrust "untrusted" = Just UnTrusted
+readTrust "semitrusted" = Just SemiTrusted
+readTrust "dead" = Just DeadTrusted -- NEW CASE
+readTrust _ = Nothing
{- The trust.log used to only list trusted repos, without a field for the
- trust status, which is why this defaults to Trusted. -}