diff options
author | Joey Hess <joey@kitenet.net> | 2013-04-24 21:53:58 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2013-04-24 21:53:58 -0400 |
commit | 25b51d072343ac7cdf23e1dae74a6d4300f21a27 (patch) | |
tree | 514f40cbf098326cf3ee04605a0a3fa148635127 /Command/InitRemote.hs | |
parent | 668000dda86ff1c1aea09377da3efb6572340d37 (diff) |
initremote: If two existing remotes have the same name, prefer the one with a higher trust level.
Diffstat (limited to 'Command/InitRemote.hs')
-rw-r--r-- | Command/InitRemote.hs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/Command/InitRemote.hs b/Command/InitRemote.hs index 5d48e9715..948b6ef63 100644 --- a/Command/InitRemote.hs +++ b/Command/InitRemote.hs @@ -16,6 +16,9 @@ import qualified Logs.Remote import qualified Types.Remote as R import Annex.UUID import Logs.UUID +import Logs.Trust + +import Data.Ord def :: [Command] def = [command "initremote" @@ -57,15 +60,18 @@ cleanup u name c = do {- Look up existing remote's UUID and config by name, or generate a new one -} findByName :: String -> Annex (UUID, R.RemoteConfig) findByName name = do - m <- Logs.Remote.readRemoteLog - maybe generate return $ findByName' name m + t <- trustMap + matches <- sortBy (comparing $ \(u, _c) -> M.lookup u t ) + . findByName' name + <$> Logs.Remote.readRemoteLog + maybe generate return $ headMaybe matches where generate = do uuid <- liftIO genUUID return (uuid, M.insert nameKey name M.empty) -findByName' :: String -> M.Map UUID R.RemoteConfig -> Maybe (UUID, R.RemoteConfig) -findByName' n = headMaybe . filter (matching . snd) . M.toList +findByName' :: String -> M.Map UUID R.RemoteConfig -> [(UUID, R.RemoteConfig)] +findByName' n = filter (matching . snd) . M.toList where matching c = case M.lookup nameKey c of Nothing -> False |