summaryrefslogtreecommitdiff
path: root/Logs/Trust.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-10-15 16:21:08 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-10-15 16:21:08 -0400
commit1a29b5b52eec641a5456d7c8dc24356c90107bc0 (patch)
tree0b902c278129bd085e8db986af168a4e46d3dea6 /Logs/Trust.hs
parent279150ccd5ad937a44cbff798ab7bb118ad1dbee (diff)
reorganize log modules
no code changes
Diffstat (limited to 'Logs/Trust.hs')
-rw-r--r--Logs/Trust.hs70
1 files changed, 70 insertions, 0 deletions
diff --git a/Logs/Trust.hs b/Logs/Trust.hs
new file mode 100644
index 000000000..6966ffdd6
--- /dev/null
+++ b/Logs/Trust.hs
@@ -0,0 +1,70 @@
+{- git-annex trust
+ -
+ - Copyright 2010 Joey Hess <joey@kitenet.net>
+ -
+ - Licensed under the GNU GPL version 3 or higher.
+ -}
+
+module Logs.Trust (
+ TrustLevel(..),
+ trustGet,
+ trustSet,
+ trustPartition
+) where
+
+import qualified Data.Map as M
+import Data.Time.Clock.POSIX
+
+import Common.Annex
+import Types.TrustLevel
+import qualified Annex.Branch
+import qualified Annex
+
+import Logs.UUID
+import Logs.UUIDBased
+
+{- Filename of trust.log. -}
+trustLog :: FilePath
+trustLog = "trust.log"
+
+{- Returns a list of UUIDs at the specified trust level. -}
+trustGet :: TrustLevel -> Annex [UUID]
+trustGet level = M.keys . M.filter (== level) <$> trustMap
+
+{- Read the trustLog into a map, overriding with any
+ - values from forcetrust. The map is cached for speed. -}
+trustMap :: Annex TrustMap
+trustMap = do
+ cached <- Annex.getState Annex.trustmap
+ case cached of
+ Just m -> return m
+ Nothing -> do
+ overrides <- M.fromList <$> Annex.getState Annex.forcetrust
+ m <- (M.union overrides . simpleMap . parseLog parseTrust) <$>
+ Annex.Branch.get trustLog
+ Annex.changeState $ \s -> s { Annex.trustmap = Just m }
+ return m
+
+parseTrust :: String -> Maybe TrustLevel
+parseTrust s
+ | length w > 0 = readMaybe $ head w
+ -- back-compat; the trust.log used to only list trusted repos
+ | otherwise = Just Trusted
+ where
+ w = words s
+
+{- Changes the trust level for a uuid in the trustLog. -}
+trustSet :: UUID -> TrustLevel -> Annex ()
+trustSet uuid level = do
+ when (null uuid) $
+ error "unknown UUID; cannot modify trust level"
+ ts <- liftIO $ getPOSIXTime
+ Annex.Branch.change trustLog $
+ showLog show . changeLog ts uuid level . parseLog parseTrust
+ Annex.changeState $ \s -> s { Annex.trustmap = Nothing }
+
+{- Partitions a list of UUIDs to those matching a TrustLevel and not. -}
+trustPartition :: TrustLevel -> [UUID] -> Annex ([UUID], [UUID])
+trustPartition level ls = do
+ candidates <- trustGet level
+ return $ partition (`elem` candidates) ls