From a0e4b9678b227b1ad4c24fc13b5e7619311187f5 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 13 Apr 2018 14:50:14 -0400 Subject: [PATCH] fix inverted Ord for TrustLevel (intermediate commit) This commit removes the Ord and Enum instances, commenting out all code that depends on them, to make sure that all code effected by the inversion fix has been identified. (Assuming no ifdefs involve TrustLevel.) The next commit will fix up all the identified code. --- Annex/SpecialRemote.hs | 5 +++-- Command/Move.hs | 2 +- Command/Vicfg.hs | 8 ++++++-- Limit.hs | 2 +- Logs/Trust.hs | 2 +- Logs/Trust/Pure.hs | 2 +- Types/TrustLevel.hs | 8 +++----- 7 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Annex/SpecialRemote.hs b/Annex/SpecialRemote.hs index 23b0f582fd..4f2f99a537 100644 --- a/Annex/SpecialRemote.hs +++ b/Annex/SpecialRemote.hs @@ -25,10 +25,11 @@ import Data.Ord findExisting :: RemoteName -> Annex (Maybe (UUID, RemoteConfig)) findExisting name = do t <- trustMap - matches <- sortBy (comparing $ \(u, _c) -> M.lookup u t) + headMaybe + . reverse + -- . sortBy (comparing $ \(u, _c) -> M.lookup u t) . findByName name <$> Logs.Remote.readRemoteLog - return $ headMaybe matches newConfig :: RemoteName -> RemoteConfig newConfig = M.singleton nameKey diff --git a/Command/Move.hs b/Command/Move.hs index 43df414d22..6b02528803 100644 --- a/Command/Move.hs +++ b/Command/Move.hs @@ -300,6 +300,6 @@ willDropMakeItWorse srcuuid destuuid deststartedwithcopy key afile = checktrustlevel = do desttrust <- lookupTrust destuuid srctrust <- lookupTrust srcuuid - return (desttrust <= srctrust || desttrust < UnTrusted) + return True -- return (desttrust >= srctrust || desttrust > UnTrusted) data DropCheck = DropWorse | DropAllowed | DropCheckNumCopies diff --git a/Command/Vicfg.hs b/Command/Vicfg.hs index 62f453f728..9bf31f1f4b 100644 --- a/Command/Vicfg.hs +++ b/Command/Vicfg.hs @@ -151,14 +151,18 @@ genCfg cfg descs = unlines $ intercalate [""] , com " setting field = value" ] - trust = settings cfg descs cfgTrustMap + trust = undefined + -- TODO: Down order + {- settings cfg descs cfgTrustMap [ com "Repository trust configuration" , com "(Valid trust levels: " ++ trustlevels ++ ")" ] (\(t, u) -> line "trust" u $ showTrustLevel t) (\u -> lcom $ line "trust" u $ showTrustLevel def) where - trustlevels = unwords $ map showTrustLevel [Trusted .. DeadTrusted] + trustlevels = "XXX" -- unwords $ reverse $ + -- map showTrustLevel [minBound..maxBound] + -} groups = settings cfg descs cfgGroupMap [ com "Repository groups" diff --git a/Limit.hs b/Limit.hs index 97e3653b14..918f4a3999 100644 --- a/Limit.hs +++ b/Limit.hs @@ -180,7 +180,7 @@ limitCopies want = case splitc ':' want of checktrust checker u = checker <$> lookupTrust u checkgroup g u = S.member g <$> lookupGroups u parsetrustspec s - | "+" `isSuffixOf` s = (>=) <$> readTrustLevel (beginning s) + -- | "+" `isSuffixOf` s = (<=) <$> readTrustLevel (beginning s) | otherwise = (==) <$> readTrustLevel s {- Adds a limit to match files that need more copies made. -} diff --git a/Logs/Trust.hs b/Logs/Trust.hs index e68efc8956..95843c882e 100644 --- a/Logs/Trust.hs +++ b/Logs/Trust.hs @@ -72,7 +72,7 @@ trustMapLoad = do map (\r -> (Types.Remote.uuid r, UnTrusted)) exports logged <- trustMapRaw let configured = M.fromList $ mapMaybe configuredtrust l - let m = M.unionWith max exportoverrides $ + let m = --M.unionWith max exportoverrides $ M.union overrides $ M.union configured logged Annex.changeState $ \s -> s { Annex.trustmap = Just m } diff --git a/Logs/Trust/Pure.hs b/Logs/Trust/Pure.hs index 74b7fd38cb..e67583b568 100644 --- a/Logs/Trust/Pure.hs +++ b/Logs/Trust/Pure.hs @@ -31,6 +31,6 @@ showTrustLog DeadTrusted = "X" showTrustLog SemiTrusted = "?" prop_parse_show_TrustLog :: Bool -prop_parse_show_TrustLog = all check [minBound .. maxBound] +prop_parse_show_TrustLog = True -- all check [minBound .. maxBound] where check l = parseTrustLog (showTrustLog l) == l diff --git a/Types/TrustLevel.hs b/Types/TrustLevel.hs index 6ec18e5128..f0ff495eba 100644 --- a/Types/TrustLevel.hs +++ b/Types/TrustLevel.hs @@ -18,10 +18,8 @@ import Data.Default import Types.UUID --- This order may seem backwards, but we generally want to list dead --- remotes last and trusted ones first. -data TrustLevel = Trusted | SemiTrusted | UnTrusted | DeadTrusted - deriving (Eq, Enum, Ord, Bounded, Show) +data TrustLevel = DeadTrusted | UnTrusted | SemiTrusted | Trusted + deriving (Eq, Bounded, Show) instance Default TrustLevel where def = SemiTrusted @@ -42,6 +40,6 @@ showTrustLevel SemiTrusted = "semitrusted" showTrustLevel DeadTrusted = "dead" prop_read_show_TrustLevel :: Bool -prop_read_show_TrustLevel = all check [minBound .. maxBound] +prop_read_show_TrustLevel = True -- all check [minBound .. maxBound] where check l = readTrustLevel (showTrustLevel l) == Just l