diff options
author | Joey Hess <joey@kitenet.net> | 2012-01-09 23:31:44 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-01-09 23:31:44 -0400 |
commit | 0d5c4022105a393a4eac76b09940f8b22fa0a56c (patch) | |
tree | a86e5d64d4b9fc95b0316c5fb08b9eef925bd1b7 /Remote.hs | |
parent | 9ffd97442b3f2e4e9de6895d843aee382ad10dfd (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 'Remote.hs')
-rw-r--r-- | Remote.hs | 29 |
1 files changed, 21 insertions, 8 deletions
@@ -40,6 +40,7 @@ import Text.JSON.Generic import Common.Annex import Types.Remote import qualified Annex +import qualified Git import Config import Annex.UUID import Logs.UUID @@ -74,17 +75,15 @@ remoteList = do if null rs then do m <- readRemoteLog - l <- mapM (process m) remoteTypes - let rs' = concat l + rs' <- concat <$> mapM (process m) remoteTypes Annex.changeState $ \s -> s { Annex.remotes = rs' } return rs' else return rs where - process m t = - enumerate t >>= - mapM (gen m t) + process m t = enumerate t >>= mapM (gen m t) gen m t r = do u <- getRepoUUID r + checkTrust r u generate t r u (M.lookup u m) {- All remotes that are not ignored. -} @@ -242,10 +241,24 @@ showTriedRemotes remotes = (join ", " $ map name remotes) forceTrust :: TrustLevel -> String -> Annex () -forceTrust level remotename = do - r <- nameToUUID remotename +forceTrust level remotename = forceTrust' True level =<< nameToUUID remotename + +forceTrust' :: Bool -> TrustLevel -> UUID -> Annex () +forceTrust' overwrite level u = do Annex.changeState $ \s -> - s { Annex.forcetrust = (r, level):Annex.forcetrust s } + s { Annex.forcetrust = change u level (Annex.forcetrust s) } + -- This change invalidated any cached trustmap. + Annex.changeState $ \s -> s { Annex.trustmap = Nothing } + where + change + | overwrite = M.insert + | otherwise = M.insertWith (\_new old -> old) + +checkTrust :: Git.Repo -> UUID -> Annex () +checkTrust r u = set =<< getTrustLevel r + where + set (Just level) = forceTrust' False level u + set Nothing = return () {- Used to log a change in a remote's having a key. The change is logged - in the local repo, not on the remote. The process of transferring the |