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

View file

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

View file

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