summaryrefslogtreecommitdiff
path: root/Logs/Trust.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-01-09 23:31:44 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-01-09 23:31:44 -0400
commit0d5c4022105a393a4eac76b09940f8b22fa0a56c (patch)
treea86e5d64d4b9fc95b0316c5fb08b9eef925bd1b7 /Logs/Trust.hs
parent9ffd97442b3f2e4e9de6895d843aee382ad10dfd (diff)
Add annex-trustlevel configuration settings, which can be used to override the trust level of a remote.
This overrides the trust.log, and is overridden by the command-line trust parameters. It would have been nicer to have Logs.Trust.trustMap just look up the configuration for all remotes, but a dependency loop prevented that (Remotes depends on Logs.Trust in several ways). So instead, look up the configuration when building remotes, storing it in the same forcetrust field used for the command-line trust parameters.
Diffstat (limited to 'Logs/Trust.hs')
-rw-r--r--Logs/Trust.hs31
1 files changed, 20 insertions, 11 deletions
diff --git a/Logs/Trust.hs b/Logs/Trust.hs
index 5d769bd24..f6ead87f1 100644
--- a/Logs/Trust.hs
+++ b/Logs/Trust.hs
@@ -9,7 +9,8 @@ module Logs.Trust (
TrustLevel(..),
trustGet,
trustSet,
- trustPartition
+ trustPartition,
+ trustName
) where
import qualified Data.Map as M
@@ -32,6 +33,15 @@ trustLog = "trust.log"
trustGet :: TrustLevel -> Annex [UUID]
trustGet level = M.keys . M.filter (== level) <$> trustMap
+{- Changes the trust level for a uuid in the trustLog. -}
+trustSet :: UUID -> TrustLevel -> Annex ()
+trustSet uuid@(UUID _) level = do
+ ts <- liftIO getPOSIXTime
+ Annex.Branch.change trustLog $
+ showLog showTrust . changeLog ts uuid level . parseLog (Just . parseTrust)
+ Annex.changeState $ \s -> s { Annex.trustmap = Nothing }
+trustSet NoUUID _ = error "unknown UUID; cannot modify trust level"
+
{- Partitions a list of UUIDs to those matching a TrustLevel and not. -}
trustPartition :: TrustLevel -> [UUID] -> Annex ([UUID], [UUID])
trustPartition level ls
@@ -53,9 +63,10 @@ trustMap = do
case cached of
Just m -> return m
Nothing -> do
- overrides <- M.fromList <$> Annex.getState Annex.forcetrust
- m <- (M.union overrides . simpleMap . parseLog (Just . parseTrust)) <$>
+ overrides <- Annex.getState Annex.forcetrust
+ logged <- simpleMap . parseLog (Just . parseTrust) <$>
Annex.Branch.get trustLog
+ let m = M.union overrides logged
Annex.changeState $ \s -> s { Annex.trustmap = Just m }
return m
@@ -75,11 +86,9 @@ showTrust UnTrusted = "0"
showTrust DeadTrusted = "X"
showTrust SemiTrusted = "?"
-{- Changes the trust level for a uuid in the trustLog. -}
-trustSet :: UUID -> TrustLevel -> Annex ()
-trustSet uuid@(UUID _) level = do
- ts <- liftIO getPOSIXTime
- Annex.Branch.change trustLog $
- showLog showTrust . changeLog ts uuid level . parseLog (Just . parseTrust)
- Annex.changeState $ \s -> s { Annex.trustmap = Nothing }
-trustSet NoUUID _ = error "unknown UUID; cannot modify trust level"
+trustName :: String -> Maybe TrustLevel
+trustName "trusted" = Just Trusted
+trustName "untrusted" = Just UnTrusted
+trustName "deadtrusted" = Just DeadTrusted
+trustName "semitrusted" = Just SemiTrusted
+trustName _ = Nothing