break module dependancy loop

A PITA but worth it to clean up the trust configuration code.
This commit is contained in:
Joey Hess 2012-01-10 13:11:16 -04:00
parent 0d5c402210
commit 07cacbeee9
10 changed files with 109 additions and 107 deletions

View file

@ -16,8 +16,7 @@
module Logs.Location (
LogStatus(..),
logChange,
readLog,
keyLocations,
loggedLocations,
loggedKeys,
loggedKeysFor,
logFile,
@ -27,7 +26,6 @@ module Logs.Location (
import Common.Annex
import qualified Annex.Branch
import Logs.Presence
import Logs.Trust
{- Log a change in the presence of a key's value in a repository. -}
logChange :: Key -> UUID -> LogStatus -> Annex ()
@ -36,13 +34,9 @@ logChange _ NoUUID _ = return ()
{- Returns a list of repository UUIDs that, according to the log, have
- the value of a key.
-
- Dead repositories are skipped.
-}
keyLocations :: Key -> Annex [UUID]
keyLocations key = do
l <- map toUUID <$> (currentLog . logFile) key
snd <$> trustPartition DeadTrusted l
loggedLocations :: Key -> Annex [UUID]
loggedLocations key = map toUUID <$> (currentLog . logFile) key
{- Finds all keys that have location log information.
- (There may be duplicate keys in the list.) -}
@ -57,7 +51,7 @@ loggedKeysFor u = filterM isthere =<< loggedKeys
{- This should run strictly to avoid the filterM
- building many thunks containing keyLocations data. -}
isthere k = do
us <- keyLocations k
us <- loggedLocations k
let !there = u `elem` us
return there

View file

@ -10,7 +10,6 @@ module Logs.Trust (
trustGet,
trustSet,
trustPartition,
trustName
) where
import qualified Data.Map as M
@ -21,6 +20,9 @@ import Types.TrustLevel
import qualified Annex.Branch
import qualified Annex
import Logs.UUIDBased
import Remote.List
import Config
import qualified Types.Remote
{- Filename of trust.log. -}
trustLog :: FilePath
@ -56,7 +58,7 @@ trustPartition level ls
return $ partition (`elem` candidates) ls
{- Read the trustLog into a map, overriding with any
- values from forcetrust. The map is cached for speed. -}
- values from forcetrust or the git config. The map is cached for speed. -}
trustMap :: Annex TrustMap
trustMap = do
cached <- Annex.getState Annex.trustmap
@ -66,9 +68,22 @@ trustMap = do
overrides <- Annex.getState Annex.forcetrust
logged <- simpleMap . parseLog (Just . parseTrust) <$>
Annex.Branch.get trustLog
let m = M.union overrides logged
configured <- M.fromList . catMaybes <$>
(mapM configuredtrust =<< remoteList)
let m = M.union overrides $ M.union configured logged
Annex.changeState $ \s -> s { Annex.trustmap = Just m }
return m
where
configuredtrust r =
maybe Nothing (\l -> Just (Types.Remote.uuid r, l)) <$>
(convert <$> getTrustLevel (Types.Remote.repo r))
convert :: Maybe String -> Maybe TrustLevel
convert Nothing = Nothing
convert (Just s)
| s == "trusted" = Just Trusted
| s == "untrusted" = Just UnTrusted
| s == "semitrusted" = Just SemiTrusted
| otherwise = Nothing
{- The trust.log used to only list trusted repos, without a field for the
- trust status, which is why this defaults to Trusted. -}
@ -85,10 +100,3 @@ showTrust Trusted = "1"
showTrust UnTrusted = "0"
showTrust DeadTrusted = "X"
showTrust SemiTrusted = "?"
trustName :: String -> Maybe TrustLevel
trustName "trusted" = Just Trusted
trustName "untrusted" = Just UnTrusted
trustName "deadtrusted" = Just DeadTrusted
trustName "semitrusted" = Just SemiTrusted
trustName _ = Nothing