git-annex/Logs/Trust.hs
Joey Hess 40ecf58d4b
update licenses from GPL to AGPL
This does not change the overall license of the git-annex program, which
was already AGPL due to a number of sources files being AGPL already.

Legally speaking, I'm adding a new license under which these files are
now available; I already released their current contents under the GPL
license. Now they're dual licensed GPL and AGPL. However, I intend
for all my future changes to these files to only be released under the
AGPL license, and I won't be tracking the dual licensing status, so I'm
simply changing the license statement to say it's AGPL.

(In some cases, others wrote parts of the code of a file and released it
under the GPL; but in all cases I have contributed a significant portion
of the code in each file and it's that code that is getting the AGPL
license; the GPL license of other contributors allows combining with
AGPL code.)
2019-03-13 15:48:14 -04:00

87 lines
2.6 KiB
Haskell

{- git-annex trust log
-
- Copyright 2010-2012 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU AGPL version 3 or higher.
-}
module Logs.Trust (
module X,
trustLog,
TrustLevel(..),
trustGet,
trustMap,
trustPartition,
trustExclude,
lookupTrust,
trustMapLoad,
) where
import qualified Data.Map as M
import Data.Default
import Annex.Common
import Types.TrustLevel
import qualified Annex
import Logs
import Remote.List
import qualified Types.Remote
import Logs.Trust.Basic as X
{- Returns a list of UUIDs that the trustLog indicates have the
- specified trust level.
- Note that the list can be incomplete for SemiTrusted, since that's
- the default. -}
trustGet :: TrustLevel -> Annex [UUID]
trustGet level = M.keys . M.filter (== level) <$> trustMap
{- Returns the TrustLevel of a given repo UUID. -}
lookupTrust :: UUID -> Annex TrustLevel
lookupTrust u = (fromMaybe def . M.lookup u) <$> trustMap
{- Partitions a list of UUIDs to those matching a TrustLevel and not. -}
trustPartition :: TrustLevel -> [UUID] -> Annex ([UUID], [UUID])
trustPartition level ls
| level == SemiTrusted = do
t <- trustGet Trusted
u <- trustGet UnTrusted
d <- trustGet DeadTrusted
let uncandidates = t ++ u ++ d
return $ partition (`notElem` uncandidates) ls
| otherwise = do
candidates <- trustGet level
return $ partition (`elem` candidates) ls
{- Filters UUIDs to those not matching a TrustLevel. -}
trustExclude :: TrustLevel -> [UUID] -> Annex [UUID]
trustExclude level ls = snd <$> trustPartition level ls
{- trustLog in a map, overridden with any values from forcetrust or
- the git config. The map is cached for speed. -}
trustMap :: Annex TrustMap
trustMap = maybe trustMapLoad return =<< Annex.getState Annex.trustmap
{- Loads the map, updating the cache, -}
trustMapLoad :: Annex TrustMap
trustMapLoad = do
overrides <- Annex.getState Annex.forcetrust
l <- remoteList
-- Exports are not trusted, since they are not key/value stores.
-- This does not apply to appendonly exports, which are key/value
-- stores.
let untrustworthy r = pure (not (Types.Remote.appendonly r))
<&&> Types.Remote.isExportSupported r
exports <- filterM untrustworthy l
let exportoverrides = M.fromList $
map (\r -> (Types.Remote.uuid r, UnTrusted)) exports
logged <- trustMapRaw
let configured = M.fromList $ mapMaybe configuredtrust l
let m = M.unionWith min exportoverrides $
M.union overrides $
M.union configured logged
Annex.changeState $ \s -> s { Annex.trustmap = Just m }
return m
where
configuredtrust r = (\l -> Just (Types.Remote.uuid r, l))
=<< readTrustLevel
=<< remoteAnnexTrustLevel (Types.Remote.gitconfig r)