Add timestamps to trust.log.
This commit is contained in:
parent
3e0d2a0803
commit
f929d0229c
3 changed files with 18 additions and 22 deletions
38
Trust.hs
38
Trust.hs
|
@ -7,29 +7,29 @@
|
||||||
|
|
||||||
module Trust (
|
module Trust (
|
||||||
TrustLevel(..),
|
TrustLevel(..),
|
||||||
trustLog,
|
|
||||||
trustGet,
|
trustGet,
|
||||||
trustSet,
|
trustSet,
|
||||||
trustPartition
|
trustPartition
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
|
import Data.Time.Clock.POSIX
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
import Types.TrustLevel
|
import Types.TrustLevel
|
||||||
import qualified Annex.Branch
|
import qualified Annex.Branch
|
||||||
import UUID
|
|
||||||
import qualified Annex
|
import qualified Annex
|
||||||
|
|
||||||
|
import UUID
|
||||||
|
import UUIDLog
|
||||||
|
|
||||||
{- Filename of trust.log. -}
|
{- Filename of trust.log. -}
|
||||||
trustLog :: FilePath
|
trustLog :: FilePath
|
||||||
trustLog = "trust.log"
|
trustLog = "trust.log"
|
||||||
|
|
||||||
{- Returns a list of UUIDs at the specified trust level. -}
|
{- Returns a list of UUIDs at the specified trust level. -}
|
||||||
trustGet :: TrustLevel -> Annex [UUID]
|
trustGet :: TrustLevel -> Annex [UUID]
|
||||||
trustGet level = do
|
trustGet level = M.keys . M.filter (== level) <$> trustMap
|
||||||
m <- trustMap
|
|
||||||
return $ M.keys $ M.filter (== level) m
|
|
||||||
|
|
||||||
{- Read the trustLog into a map, overriding with any
|
{- Read the trustLog into a map, overriding with any
|
||||||
- values from forcetrust. The map is cached for speed. -}
|
- values from forcetrust. The map is cached for speed. -}
|
||||||
|
@ -39,35 +39,29 @@ trustMap = do
|
||||||
case cached of
|
case cached of
|
||||||
Just m -> return m
|
Just m -> return m
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
overrides <- Annex.getState Annex.forcetrust
|
overrides <- M.fromList <$> Annex.getState Annex.forcetrust
|
||||||
l <- Annex.Branch.get trustLog
|
m <- (M.union overrides . simpleMap . parseLog parseTrust) <$>
|
||||||
let m = M.fromList $ trustMapParse l ++ overrides
|
Annex.Branch.get trustLog
|
||||||
Annex.changeState $ \s -> s { Annex.trustmap = Just m }
|
Annex.changeState $ \s -> s { Annex.trustmap = Just m }
|
||||||
return m
|
return m
|
||||||
|
|
||||||
{- Trust map parser. -}
|
parseTrust :: String -> Maybe TrustLevel
|
||||||
trustMapParse :: String -> [(UUID, TrustLevel)]
|
parseTrust s
|
||||||
trustMapParse s = map pair $ filter (not . null) $ lines s
|
| length w > 0 = readMaybe $ head w
|
||||||
|
-- back-compat; the trust.log used to only list trusted repos
|
||||||
|
| otherwise = Just Trusted
|
||||||
where
|
where
|
||||||
pair l
|
w = words s
|
||||||
| 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
|
|
||||||
|
|
||||||
{- Changes the trust level for a uuid in the trustLog. -}
|
{- Changes the trust level for a uuid in the trustLog. -}
|
||||||
trustSet :: UUID -> TrustLevel -> Annex ()
|
trustSet :: UUID -> TrustLevel -> Annex ()
|
||||||
trustSet uuid level = do
|
trustSet uuid level = do
|
||||||
when (null uuid) $
|
when (null uuid) $
|
||||||
error "unknown UUID; cannot modify trust level"
|
error "unknown UUID; cannot modify trust level"
|
||||||
|
ts <- liftIO $ getPOSIXTime
|
||||||
Annex.Branch.change trustLog $
|
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 }
|
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. -}
|
{- Partitions a list of UUIDs to those matching a TrustLevel and not. -}
|
||||||
trustPartition :: TrustLevel -> [UUID] -> Annex ([UUID], [UUID])
|
trustPartition :: TrustLevel -> [UUID] -> Annex ([UUID], [UUID])
|
||||||
|
|
1
debian/changelog
vendored
1
debian/changelog
vendored
|
@ -12,6 +12,7 @@ git-annex (3.20110929) UNRELEASED; urgency=low
|
||||||
has been merged.
|
has been merged.
|
||||||
* Note that older versions of git-annex will display the timestamp as part
|
* Note that older versions of git-annex will display the timestamp as part
|
||||||
of the repository description, which is ugly but otherwise harmless.
|
of the repository description, which is ugly but otherwise harmless.
|
||||||
|
* Add timestamps to trust.log.
|
||||||
|
|
||||||
-- Joey Hess <joeyh@debian.org> Thu, 29 Sep 2011 18:58:53 -0400
|
-- Joey Hess <joeyh@debian.org> Thu, 29 Sep 2011 18:58:53 -0400
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ would keep working, ignoring the timestamp.
|
||||||
> update: converted! --[[Joey]]
|
> update: converted! --[[Joey]]
|
||||||
- trust.log: "uuid trustlevel timestamp" would work; old git-annex
|
- trust.log: "uuid trustlevel timestamp" would work; old git-annex
|
||||||
ignores trailing words
|
ignores trailing words
|
||||||
|
> update: converted! --[[Joey]]
|
||||||
- remote.log: "uuid key=value ... timestamp" is on the edge but does work
|
- remote.log: "uuid key=value ... timestamp" is on the edge but does work
|
||||||
(old git-annex will include the timestamp in the key/value map it builds,
|
(old git-annex will include the timestamp in the key/value map it builds,
|
||||||
but that should not break anything really)
|
but that should not break anything really)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue