summaryrefslogtreecommitdiff
path: root/Logs/Trust.hs
diff options
context:
space:
mode:
authorGravatar Nicolas Pouillard <nicolas.pouillard@gmail.com>2012-09-23 19:50:31 +0200
committerGravatar Nicolas Pouillard <nicolas.pouillard@gmail.com>2012-09-23 19:57:21 +0200
commitf0bcc77fb245c5fccadff728fd816471fd9993bf (patch)
tree2a306cca28917c7a25c6079cc6418074af5c391f /Logs/Trust.hs
parentc9b3b8829dc3f106583fb933808179ec02773790 (diff)
Limiting the number of copies per trustlevel
The --copies flag now takes an argument of the form: trustlevel:number or number If a trust level is specified the command is limited to files with at least 'number' copies of this 'trustlevel'.
Diffstat (limited to 'Logs/Trust.hs')
-rw-r--r--Logs/Trust.hs19
1 files changed, 14 insertions, 5 deletions
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. -}