2013-08-31 21:38:33 +00:00
|
|
|
{- git-annex branch transitions
|
|
|
|
-
|
2019-01-03 17:21:48 +00:00
|
|
|
- Copyright 2013-2019 Joey Hess <id@joeyh.name>
|
2013-08-31 21:38:33 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2013-08-31 21:38:33 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Annex.Branch.Transitions (
|
|
|
|
FileTransition(..),
|
|
|
|
getTransitionCalculator
|
|
|
|
) where
|
|
|
|
|
2019-01-03 17:21:48 +00:00
|
|
|
import Common
|
2013-08-31 21:38:33 +00:00
|
|
|
import Logs
|
|
|
|
import Logs.Transitions
|
2014-07-24 20:23:36 +00:00
|
|
|
import qualified Logs.UUIDBased as UUIDBased
|
|
|
|
import qualified Logs.Presence.Pure as Presence
|
|
|
|
import qualified Logs.Chunk.Pure as Chunk
|
2018-09-05 17:20:10 +00:00
|
|
|
import qualified Logs.MetaData.Pure as MetaData
|
2019-10-15 15:33:33 +00:00
|
|
|
import qualified Logs.Remote.Pure as Remote
|
2013-08-31 21:38:33 +00:00
|
|
|
import Types.TrustLevel
|
|
|
|
import Types.UUID
|
2018-09-05 17:20:10 +00:00
|
|
|
import Types.MetaData
|
2019-10-14 19:38:07 +00:00
|
|
|
import Types.Remote
|
2020-02-14 23:38:50 +00:00
|
|
|
import Types.GitConfig (GitConfig)
|
2020-01-10 18:10:20 +00:00
|
|
|
import Types.ProposedAccepted
|
2019-10-14 19:38:07 +00:00
|
|
|
import Annex.SpecialRemote.Config
|
2013-08-31 21:38:33 +00:00
|
|
|
|
|
|
|
import qualified Data.Map as M
|
2019-10-15 15:33:33 +00:00
|
|
|
import qualified Data.Set as S
|
2019-01-03 17:21:48 +00:00
|
|
|
import qualified Data.ByteString.Lazy as L
|
2019-01-10 17:23:42 +00:00
|
|
|
import qualified Data.Attoparsec.ByteString.Lazy as A
|
2019-01-03 17:21:48 +00:00
|
|
|
import Data.ByteString.Builder
|
2013-08-31 21:38:33 +00:00
|
|
|
|
|
|
|
data FileTransition
|
2019-01-09 18:10:05 +00:00
|
|
|
= ChangeFile Builder
|
2013-08-31 21:38:33 +00:00
|
|
|
| PreserveFile
|
|
|
|
|
2020-02-14 19:22:48 +00:00
|
|
|
type TransitionCalculator = GitConfig -> TrustMap -> M.Map UUID RemoteConfig -> RawFilePath -> L.ByteString -> FileTransition
|
2013-08-31 21:38:33 +00:00
|
|
|
|
|
|
|
getTransitionCalculator :: Transition -> Maybe TransitionCalculator
|
|
|
|
getTransitionCalculator ForgetGitHistory = Nothing
|
|
|
|
getTransitionCalculator ForgetDeadRemotes = Just dropDead
|
|
|
|
|
2019-10-14 19:38:07 +00:00
|
|
|
-- Removes data about all dead repos.
|
|
|
|
--
|
|
|
|
-- The trust log is not changed, because other, unmerged clones
|
|
|
|
-- may contain other data about the dead repos. So we need to rememebr
|
|
|
|
-- which are dead to later remove that.
|
|
|
|
--
|
|
|
|
-- 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
|
2019-10-15 15:33:33 +00:00
|
|
|
-- the latter uuid, that also needs to be removed. The sameas-uuid
|
2019-10-14 19:38:07 +00:00
|
|
|
-- is not removed from the remote log, for the same reason the trust log
|
|
|
|
-- is not changed.
|
|
|
|
dropDead :: TransitionCalculator
|
2020-02-17 18:57:19 +00:00
|
|
|
dropDead gc trustmap remoteconfigmap f content = case getLogVariety gc f of
|
2019-02-21 17:43:21 +00:00
|
|
|
Just OldUUIDBasedLog
|
2014-03-26 17:28:26 +00:00
|
|
|
| f == trustLog -> PreserveFile
|
2019-10-15 15:33:33 +00:00
|
|
|
| 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
|
2019-01-09 18:10:05 +00:00
|
|
|
Just NewUUIDBasedLog -> ChangeFile $
|
2019-01-10 17:23:42 +00:00
|
|
|
UUIDBased.buildLogNew byteString $
|
2019-10-14 19:38:07 +00:00
|
|
|
dropDeadFromMapLog trustmap' id $
|
2019-01-10 17:23:42 +00:00
|
|
|
UUIDBased.parseLogNew A.takeByteString content
|
2019-01-09 18:10:05 +00:00
|
|
|
Just (ChunkLog _) -> ChangeFile $
|
2019-10-14 20:04:15 +00:00
|
|
|
Chunk.buildLog $ dropDeadFromMapLog trustmap' fst $
|
|
|
|
Chunk.parseLog content
|
|
|
|
Just (PresenceLog _) -> ChangeFile $ Presence.buildLog $
|
|
|
|
Presence.compactLog $
|
|
|
|
dropDeadFromPresenceLog trustmap' $
|
|
|
|
Presence.parseLog content
|
|
|
|
Just RemoteMetaDataLog -> ChangeFile $ MetaData.buildLog $
|
|
|
|
dropDeadFromRemoteMetaDataLog trustmap' $
|
2019-10-14 19:38:07 +00:00
|
|
|
MetaData.simplifyLog $ MetaData.parseLog content
|
2014-02-13 01:12:22 +00:00
|
|
|
Just OtherLog -> PreserveFile
|
2013-08-31 21:38:33 +00:00
|
|
|
Nothing -> PreserveFile
|
2019-10-14 19:38:07 +00:00
|
|
|
where
|
|
|
|
trustmap' = trustmap `M.union`
|
|
|
|
M.map (const DeadTrusted) (M.filter sameasdead remoteconfigmap)
|
|
|
|
sameasdead cm =
|
2020-01-10 18:10:20 +00:00
|
|
|
case toUUID . fromProposedAccepted <$> M.lookup sameasUUIDField cm of
|
2019-10-14 19:38:07 +00:00
|
|
|
Nothing -> False
|
|
|
|
Just u' -> M.lookup u' trustmap == Just DeadTrusted
|
2019-10-15 15:33:33 +00:00
|
|
|
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)
|
2013-08-31 21:38:33 +00:00
|
|
|
|
2016-01-27 13:44:38 +00:00
|
|
|
dropDeadFromMapLog :: TrustMap -> (k -> UUID) -> M.Map k v -> M.Map k v
|
2018-09-05 17:20:10 +00:00
|
|
|
dropDeadFromMapLog trustmap getuuid =
|
|
|
|
M.filterWithKey $ \k _v -> notDead trustmap getuuid k
|
2013-08-31 21:38:33 +00:00
|
|
|
|
|
|
|
{- Presence logs can contain UUIDs or other values. Any line that matches
|
|
|
|
- a dead uuid is dropped; any other values are passed through. -}
|
|
|
|
dropDeadFromPresenceLog :: TrustMap -> [Presence.LogLine] -> [Presence.LogLine]
|
2018-09-05 17:20:10 +00:00
|
|
|
dropDeadFromPresenceLog trustmap =
|
2019-01-03 17:21:48 +00:00
|
|
|
filter $ notDead trustmap (toUUID . Presence.fromLogInfo . Presence.info)
|
2018-09-05 17:20:10 +00:00
|
|
|
|
|
|
|
dropDeadFromRemoteMetaDataLog :: TrustMap -> MetaData.Log MetaData -> MetaData.Log MetaData
|
|
|
|
dropDeadFromRemoteMetaDataLog trustmap =
|
|
|
|
MetaData.filterOutEmpty . MetaData.filterRemoteMetaData (notDead trustmap id)
|
2013-08-31 21:38:33 +00:00
|
|
|
|
|
|
|
notDead :: TrustMap -> (v -> UUID) -> v -> Bool
|
2014-10-14 18:10:22 +00:00
|
|
|
notDead trustmap a v = M.findWithDefault def (a v) trustmap /= DeadTrusted
|