make DropDead transition minimize remote.log for dead sameas remotes

All that needs to be retained in remote.log is the sameas-uuid.
The rest of the config is eliminated. This doesn't save enough space to
bother with, but it prevents anything sensitive in the config of the
dead sameas remote from lingering around.

Note that minimizesameasdead does not update the VectorClock when
changing the log line. That's normally a no-no, but in this case,
it makes each DropDead result in the exact same file contents,
and vector clocks are not needed because the transition breaks
the history chain.
This commit is contained in:
Joey Hess 2019-10-15 11:33:33 -04:00
parent 78f522e7c8
commit ce48eb797c
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
3 changed files with 29 additions and 14 deletions

View file

@ -17,6 +17,7 @@ import qualified Logs.UUIDBased as UUIDBased
import qualified Logs.Presence.Pure as Presence
import qualified Logs.Chunk.Pure as Chunk
import qualified Logs.MetaData.Pure as MetaData
import qualified Logs.Remote.Pure as Remote
import Types.TrustLevel
import Types.UUID
import Types.MetaData
@ -24,6 +25,7 @@ import Types.Remote
import Annex.SpecialRemote.Config
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.ByteString.Lazy as L
import qualified Data.Attoparsec.ByteString.Lazy as A
import Data.ByteString.Builder
@ -47,21 +49,22 @@ getTransitionCalculator ForgetDeadRemotes = Just dropDead
-- When the remote log contains a sameas-uuid pointing to a dead uuid,
-- the uuid of that remote configuration is also effectively dead,
-- though not in the trust log. There may be per-remote state stored using
-- the latter uuid, that also needs to be removed. That configuration
-- the latter uuid, that also needs to be removed. The sameas-uuid
-- is not removed from the remote log, for the same reason the trust log
-- is not changed.
dropDead :: TransitionCalculator
dropDead trustmap remoteconfigmap f content = case getLogVariety f of
Just OldUUIDBasedLog
| f == trustLog -> PreserveFile
| otherwise ->
let go tm = ChangeFile $
UUIDBased.buildLogOld byteString $
dropDeadFromMapLog tm id $
UUIDBased.parseLogOld A.takeByteString content
in if f == remoteLog
then go trustmap
else go trustmap'
| f == remoteLog -> ChangeFile $
Remote.buildRemoteConfigLog $
M.mapWithKey minimizesameasdead $
dropDeadFromMapLog trustmap id $
Remote.parseRemoteConfigLog content
| otherwise -> ChangeFile $
UUIDBased.buildLogOld byteString $
dropDeadFromMapLog trustmap' id $
UUIDBased.parseLogOld A.takeByteString content
Just NewUUIDBasedLog -> ChangeFile $
UUIDBased.buildLogNew byteString $
dropDeadFromMapLog trustmap' id $
@ -85,6 +88,11 @@ dropDead trustmap remoteconfigmap f content = case getLogVariety f of
case toUUID <$> M.lookup sameasUUIDField cm of
Nothing -> False
Just u' -> M.lookup u' trustmap == Just DeadTrusted
minimizesameasdead u l
| M.lookup u trustmap' == Just DeadTrusted =
l { UUIDBased.value = minimizesameasdead' (UUIDBased.value l) }
| otherwise = l
minimizesameasdead' c = M.restrictKeys c (S.singleton sameasUUIDField)
dropDeadFromMapLog :: TrustMap -> (k -> UUID) -> M.Map k v -> M.Map k v
dropDeadFromMapLog trustmap getuuid =

View file

@ -26,16 +26,15 @@ import Logs.Remote.Pure
import Annex.SpecialRemote.Config
import qualified Data.Map as M
import Data.ByteString.Builder
{- Adds or updates a remote's config in the log. -}
configSet :: UUID -> RemoteConfig -> Annex ()
configSet u cfg = do
c <- liftIO currentVectorClock
Annex.Branch.change remoteLog $
buildLogOld (byteString . encodeBS . showConfig)
buildRemoteConfigLog
. changeLog c u (removeSameasInherited cfg)
. parseLogOld remoteConfigParser
. parseRemoteConfigLog
{- Map of remotes by uuid containing key/value config maps. -}
readRemoteLog :: Annex (M.Map UUID RemoteConfig)

View file

@ -7,10 +7,11 @@
module Logs.Remote.Pure (
calcRemoteConfigMap,
parseRemoteConfigLog,
buildRemoteConfigLog,
keyValToConfig,
configToKeyVal,
showConfig,
remoteConfigParser,
prop_isomorphic_configEscape,
prop_parse_show_Config,
@ -25,11 +26,18 @@ import qualified Data.ByteString.Lazy as L
import qualified Data.Map as M
import Data.Char
import qualified Data.Attoparsec.ByteString.Lazy as A
import Data.ByteString.Builder
calcRemoteConfigMap :: L.ByteString -> M.Map UUID RemoteConfig
calcRemoteConfigMap = (\m -> M.map (addSameasInherited m) m)
. simpleMap
. parseLogOld remoteConfigParser
. parseRemoteConfigLog
parseRemoteConfigLog :: L.ByteString -> Log RemoteConfig
parseRemoteConfigLog = parseLogOld remoteConfigParser
buildRemoteConfigLog :: Log RemoteConfig -> Builder
buildRemoteConfigLog = buildLogOld (byteString . encodeBS . showConfig)
remoteConfigParser :: A.Parser RemoteConfig
remoteConfigParser = keyValToConfig . words . decodeBS <$> A.takeByteString