diff options
author | 2011-06-01 17:49:37 -0400 | |
---|---|---|
committer | 2011-06-01 17:57:31 -0400 | |
commit | a8fb97d2ce8e75b36b8e1572a83efd341e67d43e (patch) | |
tree | ab24a8af581281ff8b006309acfb4000317ad072 /Trust.hs | |
parent | 7a3d9d8c2e2bd53d0d4290e99186c6e37f18456d (diff) |
Add --trust, --untrust, and --semitrust options.
Diffstat (limited to 'Trust.hs')
-rw-r--r-- | Trust.hs | 30 |
1 files changed, 12 insertions, 18 deletions
@@ -1,4 +1,4 @@ -{- git-annex trust levels +{- git-annex trust - - Copyright 2010 Joey Hess <joey@kitenet.net> - @@ -17,26 +17,15 @@ module Trust ( import Control.Monad.State import qualified Data.Map as M +import TrustLevel import qualified GitRepo as Git import Types import UUID import Locations import qualified Annex +import qualified Remote import Utility -data TrustLevel = SemiTrusted | UnTrusted | Trusted - deriving Eq - -instance Show TrustLevel where - show SemiTrusted = "?" - show UnTrusted = "0" - show Trusted = "1" - -instance Read TrustLevel where - readsPrec _ "1" = [(Trusted, "")] - readsPrec _ "0" = [(UnTrusted, "")] - readsPrec _ _ = [(SemiTrusted, "")] - {- Filename of trust.log. -} trustLog :: Annex FilePath trustLog = do @@ -49,18 +38,23 @@ trustGet level = do m <- trustMap return $ M.keys $ M.filter (== level) m -{- Read the trustLog into a map. -} +{- Read the trustLog into a map, overriding with any + - values from forcetrust -} trustMap :: Annex (M.Map UUID TrustLevel) trustMap = do logfile <- trustLog + overrides <- Annex.getState Annex.forcetrust >>= mapM findoverride s <- liftIO $ catch (readFile logfile) ignoreerror - return $ trustMapParse s + return $ M.fromList $ trustMapParse s ++ overrides where ignoreerror _ = return "" + findoverride (name, t) = do + uuid <- Remote.nameToUUID name + return (uuid, t) {- Trust map parser. -} -trustMapParse :: String -> M.Map UUID TrustLevel -trustMapParse s = M.fromList $ map pair $ filter (not . null) $ lines s +trustMapParse :: String -> [(UUID, TrustLevel)] +trustMapParse s = map pair $ filter (not . null) $ lines s where pair l | length w > 1 = (w !! 0, read (w !! 1) :: TrustLevel) |