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.
This commit is contained in:
Joey Hess 2018-04-13 14:50:14 -04:00
parent 1831cc4a7d
commit a0e4b9678b
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
7 changed files with 16 additions and 13 deletions

View file

@ -25,10 +25,11 @@ import Data.Ord
findExisting :: RemoteName -> Annex (Maybe (UUID, RemoteConfig)) findExisting :: RemoteName -> Annex (Maybe (UUID, RemoteConfig))
findExisting name = do findExisting name = do
t <- trustMap t <- trustMap
matches <- sortBy (comparing $ \(u, _c) -> M.lookup u t) headMaybe
. reverse
-- . sortBy (comparing $ \(u, _c) -> M.lookup u t)
. findByName name . findByName name
<$> Logs.Remote.readRemoteLog <$> Logs.Remote.readRemoteLog
return $ headMaybe matches
newConfig :: RemoteName -> RemoteConfig newConfig :: RemoteName -> RemoteConfig
newConfig = M.singleton nameKey newConfig = M.singleton nameKey

View file

@ -300,6 +300,6 @@ willDropMakeItWorse srcuuid destuuid deststartedwithcopy key afile =
checktrustlevel = do checktrustlevel = do
desttrust <- lookupTrust destuuid desttrust <- lookupTrust destuuid
srctrust <- lookupTrust srcuuid srctrust <- lookupTrust srcuuid
return (desttrust <= srctrust || desttrust < UnTrusted) return True -- return (desttrust >= srctrust || desttrust > UnTrusted)
data DropCheck = DropWorse | DropAllowed | DropCheckNumCopies data DropCheck = DropWorse | DropAllowed | DropCheckNumCopies

View file

@ -151,14 +151,18 @@ genCfg cfg descs = unlines $ intercalate [""]
, com " setting field = value" , com " setting field = value"
] ]
trust = settings cfg descs cfgTrustMap trust = undefined
-- TODO: Down order
{- settings cfg descs cfgTrustMap
[ com "Repository trust configuration" [ com "Repository trust configuration"
, com "(Valid trust levels: " ++ trustlevels ++ ")" , com "(Valid trust levels: " ++ trustlevels ++ ")"
] ]
(\(t, u) -> line "trust" u $ showTrustLevel t) (\(t, u) -> line "trust" u $ showTrustLevel t)
(\u -> lcom $ line "trust" u $ showTrustLevel def) (\u -> lcom $ line "trust" u $ showTrustLevel def)
where where
trustlevels = unwords $ map showTrustLevel [Trusted .. DeadTrusted] trustlevels = "XXX" -- unwords $ reverse $
-- map showTrustLevel [minBound..maxBound]
-}
groups = settings cfg descs cfgGroupMap groups = settings cfg descs cfgGroupMap
[ com "Repository groups" [ com "Repository groups"

View file

@ -180,7 +180,7 @@ limitCopies want = case splitc ':' want of
checktrust checker u = checker <$> lookupTrust u checktrust checker u = checker <$> lookupTrust u
checkgroup g u = S.member g <$> lookupGroups u checkgroup g u = S.member g <$> lookupGroups u
parsetrustspec s parsetrustspec s
| "+" `isSuffixOf` s = (>=) <$> readTrustLevel (beginning s) -- | "+" `isSuffixOf` s = (<=) <$> readTrustLevel (beginning s)
| otherwise = (==) <$> readTrustLevel s | otherwise = (==) <$> readTrustLevel s
{- Adds a limit to match files that need more copies made. -} {- Adds a limit to match files that need more copies made. -}

View file

@ -72,7 +72,7 @@ trustMapLoad = do
map (\r -> (Types.Remote.uuid r, UnTrusted)) exports map (\r -> (Types.Remote.uuid r, UnTrusted)) exports
logged <- trustMapRaw logged <- trustMapRaw
let configured = M.fromList $ mapMaybe configuredtrust l let configured = M.fromList $ mapMaybe configuredtrust l
let m = M.unionWith max exportoverrides $ let m = --M.unionWith max exportoverrides $
M.union overrides $ M.union overrides $
M.union configured logged M.union configured logged
Annex.changeState $ \s -> s { Annex.trustmap = Just m } Annex.changeState $ \s -> s { Annex.trustmap = Just m }

View file

@ -31,6 +31,6 @@ showTrustLog DeadTrusted = "X"
showTrustLog SemiTrusted = "?" showTrustLog SemiTrusted = "?"
prop_parse_show_TrustLog :: Bool prop_parse_show_TrustLog :: Bool
prop_parse_show_TrustLog = all check [minBound .. maxBound] prop_parse_show_TrustLog = True -- all check [minBound .. maxBound]
where where
check l = parseTrustLog (showTrustLog l) == l check l = parseTrustLog (showTrustLog l) == l

View file

@ -18,10 +18,8 @@ import Data.Default
import Types.UUID import Types.UUID
-- This order may seem backwards, but we generally want to list dead data TrustLevel = DeadTrusted | UnTrusted | SemiTrusted | Trusted
-- remotes last and trusted ones first. deriving (Eq, Bounded, Show)
data TrustLevel = Trusted | SemiTrusted | UnTrusted | DeadTrusted
deriving (Eq, Enum, Ord, Bounded, Show)
instance Default TrustLevel where instance Default TrustLevel where
def = SemiTrusted def = SemiTrusted
@ -42,6 +40,6 @@ showTrustLevel SemiTrusted = "semitrusted"
showTrustLevel DeadTrusted = "dead" showTrustLevel DeadTrusted = "dead"
prop_read_show_TrustLevel :: Bool prop_read_show_TrustLevel :: Bool
prop_read_show_TrustLevel = all check [minBound .. maxBound] prop_read_show_TrustLevel = True -- all check [minBound .. maxBound]
where where
check l = readTrustLevel (showTrustLevel l) == Just l check l = readTrustLevel (showTrustLevel l) == Just l