From a102f2f1887f2565b3a7908eff8995e6cf04d567 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 30 May 2014 14:03:04 -0400 Subject: webapp: avoid overwriting remote configs when enabling it Avoid stomping on existing group and preferred content settings when enabling or combining with an already existing remote. Two level fix. First, use defaultStandardGroup rather than setStandardGroup, so if there is an existing configuration in the git-annex branch, it's not overwritten. To handle pre-existing ssh remotes (including gcrypt), a second level is needed, because before syncing with the remote, it's configuration won't be available locally. (And syncing could take a long time.) So, in this case, keep track of whether the remote is being created or enabled, and only set configs when creating it. This commit was sponsored by Anders Lannerback. --- Logs/PreferredContent.hs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'Logs/PreferredContent.hs') diff --git a/Logs/PreferredContent.hs b/Logs/PreferredContent.hs index ead303f1f..a485ec600 100644 --- a/Logs/PreferredContent.hs +++ b/Logs/PreferredContent.hs @@ -18,6 +18,7 @@ module Logs.PreferredContent ( groupPreferredContentMapRaw, checkPreferredContentExpression, setStandardGroup, + defaultStandardGroup, preferredRequiredMapsLoad, ) where @@ -133,10 +134,20 @@ checkPreferredContentExpression expr = case parsedToMatcher tokens of tokens = exprParser matchAll matchAll emptyGroupMap M.empty Nothing expr {- Puts a UUID in a standard group, and sets its preferred content to use - - the standard expression for that group, unless something is already set. -} + - the standard expression for that group (unless preferred content is + - already set). -} setStandardGroup :: UUID -> StandardGroup -> Annex () setStandardGroup u g = do groupSet u $ S.singleton $ fromStandardGroup g - m <- preferredContentMap - unless (isJust $ M.lookup u m) $ + unlessM (isJust . M.lookup u <$> preferredContentMap) $ preferredContentSet u "standard" + +{- Avoids overwriting the UUID's standard group or preferred content + - when it's already been configured. -} +defaultStandardGroup :: UUID -> StandardGroup -> Annex () +defaultStandardGroup u g = + unlessM (hasgroup <||> haspc) $ + setStandardGroup u g + where + hasgroup = not . S.null <$> lookupGroups u + haspc = isJust . M.lookup u <$> preferredContentMap -- cgit v1.2.3