initremote: If two existing remotes have the same name, prefer the one with a higher trust level.
This commit is contained in:
parent
4f4b2b01fa
commit
49547ad32d
3 changed files with 13 additions and 4 deletions
|
@ -16,6 +16,9 @@ import qualified Logs.Remote
|
||||||
import qualified Types.Remote as R
|
import qualified Types.Remote as R
|
||||||
import Annex.UUID
|
import Annex.UUID
|
||||||
import Logs.UUID
|
import Logs.UUID
|
||||||
|
import Logs.Trust
|
||||||
|
|
||||||
|
import Data.Ord
|
||||||
|
|
||||||
def :: [Command]
|
def :: [Command]
|
||||||
def = [command "initremote"
|
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 -}
|
{- Look up existing remote's UUID and config by name, or generate a new one -}
|
||||||
findByName :: String -> Annex (UUID, R.RemoteConfig)
|
findByName :: String -> Annex (UUID, R.RemoteConfig)
|
||||||
findByName name = do
|
findByName name = do
|
||||||
m <- Logs.Remote.readRemoteLog
|
t <- trustMap
|
||||||
maybe generate return $ findByName' name m
|
matches <- sortBy (comparing $ \(u, _c) -> M.lookup u t )
|
||||||
|
. findByName' name
|
||||||
|
<$> Logs.Remote.readRemoteLog
|
||||||
|
maybe generate return $ headMaybe matches
|
||||||
where
|
where
|
||||||
generate = do
|
generate = do
|
||||||
uuid <- liftIO genUUID
|
uuid <- liftIO genUUID
|
||||||
return (uuid, M.insert nameKey name M.empty)
|
return (uuid, M.insert nameKey name M.empty)
|
||||||
|
|
||||||
findByName' :: String -> M.Map UUID R.RemoteConfig -> Maybe (UUID, R.RemoteConfig)
|
findByName' :: String -> M.Map UUID R.RemoteConfig -> [(UUID, R.RemoteConfig)]
|
||||||
findByName' n = headMaybe . filter (matching . snd) . M.toList
|
findByName' n = filter (matching . snd) . M.toList
|
||||||
where
|
where
|
||||||
matching c = case M.lookup nameKey c of
|
matching c = case M.lookup nameKey c of
|
||||||
Nothing -> False
|
Nothing -> False
|
||||||
|
|
|
@ -9,6 +9,7 @@ module Logs.Trust (
|
||||||
trustLog,
|
trustLog,
|
||||||
TrustLevel(..),
|
TrustLevel(..),
|
||||||
trustGet,
|
trustGet,
|
||||||
|
trustMap,
|
||||||
trustSet,
|
trustSet,
|
||||||
trustPartition,
|
trustPartition,
|
||||||
trustExclude,
|
trustExclude,
|
||||||
|
|
2
debian/changelog
vendored
2
debian/changelog
vendored
|
@ -29,6 +29,8 @@ git-annex (4.20130418) UNRELEASED; urgency=low
|
||||||
performing bulk adds of a large number of files (tens to hundreds
|
performing bulk adds of a large number of files (tens to hundreds
|
||||||
of thousands).
|
of thousands).
|
||||||
* assistant: Sanitize XMPP presence information logged for debugging.
|
* 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
|
-- Joey Hess <joeyh@debian.org> Thu, 18 Apr 2013 16:22:48 -0400
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue