summaryrefslogtreecommitdiff
path: root/Trust.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Trust.hs')
-rw-r--r--Trust.hs38
1 files changed, 16 insertions, 22 deletions
diff --git a/Trust.hs b/Trust.hs
index 1920bc617..2971256a4 100644
--- a/Trust.hs
+++ b/Trust.hs
@@ -7,29 +7,29 @@
module Trust (
TrustLevel(..),
- trustLog,
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 UUID
import qualified Annex
+import UUID
+import UUIDLog
+
{- 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 = do
- m <- trustMap
- return $ M.keys $ M.filter (== level) m
+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. -}
@@ -39,35 +39,29 @@ trustMap = do
case cached of
Just m -> return m
Nothing -> do
- overrides <- Annex.getState Annex.forcetrust
- l <- Annex.Branch.get trustLog
- let m = M.fromList $ trustMapParse l ++ overrides
+ 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
-{- Trust map parser. -}
-trustMapParse :: String -> [(UUID, TrustLevel)]
-trustMapParse s = map pair $ filter (not . null) $ lines s
+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
- pair l
- | length w > 1 = (w !! 0, read (w !! 1) :: TrustLevel)
- -- for back-compat; the trust log used to only
- -- list trusted uuids
- | otherwise = (w !! 0, Trusted)
- where
- w = words l
+ 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 $
- serialize . M.insert uuid level . M.fromList . trustMapParse
+ showLog show . changeLog ts uuid level . parseLog parseTrust
Annex.changeState $ \s -> s { Annex.trustmap = Nothing }
- where
- serialize m = unlines $ map showpair $ M.toList m
- showpair (u, t) = u ++ " " ++ show t
{- Partitions a list of UUIDs to those matching a TrustLevel and not. -}
trustPartition :: TrustLevel -> [UUID] -> Annex ([UUID], [UUID])