initremote: If two existing remotes have the same name, prefer the one with a higher trust level.

This commit is contained in:
Joey Hess 2013-04-24 21:53:58 -04:00
parent 4f4b2b01fa
commit 49547ad32d
3 changed files with 13 additions and 4 deletions

View file

@ -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

View file

@ -9,6 +9,7 @@ module Logs.Trust (
trustLog,
TrustLevel(..),
trustGet,
trustMap,
trustSet,
trustPartition,
trustExclude,

2
debian/changelog vendored
View file

@ -29,6 +29,8 @@ git-annex (4.20130418) UNRELEASED; urgency=low
performing bulk adds of a large number of files (tens to hundreds
of thousands).
* assistant: Sanitize XMPP presence information logged for debugging.
* initremote: If two existing remotes have the same name,
prefer the one with a higher trust level.
-- Joey Hess <joeyh@debian.org> Thu, 18 Apr 2013 16:22:48 -0400