avoid auto-enabling a remote that's already enabled

This commit is contained in:
Joey Hess 2015-09-14 15:34:15 -04:00
parent c919489c3e
commit b88739f0d0

View file

@ -8,7 +8,7 @@
module Annex.SpecialRemote where module Annex.SpecialRemote where
import Common.Annex import Common.Annex
import Remote (remoteTypes) import Remote (remoteTypes, remoteMap)
import Types.Remote (RemoteConfig, RemoteConfigKey, typename, setup) import Types.Remote (RemoteConfig, RemoteConfigKey, typename, setup)
import Logs.Remote import Logs.Remote
import Logs.Trust import Logs.Trust
@ -70,10 +70,11 @@ autoEnableKey = "autoenable"
autoEnable :: Annex () autoEnable :: Annex ()
autoEnable = do autoEnable = do
remotemap <- M.filter wanted <$> readRemoteLog remotemap <- M.filter configured <$> readRemoteLog
forM_ (M.toList remotemap) $ \(u, c) -> enabled <- remoteMap id
forM_ (M.toList remotemap) $ \(u, c) -> unless (u `M.member` enabled) $ do
case (M.lookup nameKey c, findType c) of case (M.lookup nameKey c, findType c) of
(Just name, Right t) -> unlessM ((== DeadTrusted) <$> lookupTrust u) $ do (Just name, Right t) -> whenM (canenable u) $ do
showSideAction $ "Auto enabling special remote " ++ name showSideAction $ "Auto enabling special remote " ++ name
res <- tryNonAsync $ setup t (Just u) Nothing c res <- tryNonAsync $ setup t (Just u) Nothing c
case res of case res of
@ -81,5 +82,6 @@ autoEnable = do
Right _ -> return () Right _ -> return ()
_ -> return () _ -> return ()
where where
wanted rc = fromMaybe False $ configured rc = fromMaybe False $
Git.Config.isTrue =<< M.lookup autoEnableKey rc Git.Config.isTrue =<< M.lookup autoEnableKey rc
canenable u = (/= DeadTrusted) <$> lookupTrust u