Blame SOURCES/0004-Behaviour-of--setopt-in-config-manager-plugin-RhBug1702678.patch

e582f9
From e5a30424d51f9c20cd0ec6cd3e515ac5509a9287 Mon Sep 17 00:00:00 2001
e582f9
From: Jaroslav Rohel <jrohel@redhat.com>
e582f9
Date: Thu, 18 Jul 2019 09:50:43 +0200
e582f9
Subject: [PATCH 1/6] [config-manager] --setopt: Fix crash with "--save --dump"
e582f9
 (RhBug:1702678)
e582f9
e582f9
Removes useless code which only causes crash.
e582f9
e582f9
Example of crash:
e582f9
dnf config-manager --save --dump --setopt=fedora.gpgcheck=1 fedora
e582f9
============================================================== repo: fedora ==============================================================
e582f9
Error: Error parsing '['1']': Wrong number or type of arguments for overloaded function 'OptionChildBool_set'.
e582f9
  Possible C/C++ prototypes are:
e582f9
    libdnf::OptionChild< libdnf::OptionBool >::set(libdnf::Option::Priority,libdnf::OptionBool::ValueType const &)
e582f9
    libdnf::OptionChild< libdnf::OptionBool >::set(libdnf::Option::Priority,std::string const &)
e582f9
---
e582f9
 plugins/config_manager.py | 5 -----
e582f9
 1 file changed, 5 deletions(-)
e582f9
e582f9
diff --git a/plugins/config_manager.py b/plugins/config_manager.py
e582f9
index 38fd51d..6db1bcb 100644
e582f9
--- a/plugins/config_manager.py
e582f9
+++ b/plugins/config_manager.py
e582f9
@@ -90,8 +90,6 @@ class ConfigManagerCommand(dnf.cli.Command):
e582f9
                 self.base.conf.write_raw_configfile(dnf.const.CONF_FILENAME, 'main', sbc.substitutions, modify)
e582f9
             if self.opts.dump:
e582f9
                 print(self.base.output.fmtSection('main'))
e582f9
-                for name, val in modify.items():
e582f9
-                    sbc._set_value(name, val)
e582f9
                 print(self.base.conf.dump())
e582f9
 
e582f9
         if self.opts.set_enabled or self.opts.set_disabled:
e582f9
@@ -120,9 +118,6 @@ class ConfigManagerCommand(dnf.cli.Command):
e582f9
                 self.base.conf.write_raw_configfile(repo.repofile, repo.id, sbc.substitutions, repo_modify)
e582f9
             if self.opts.dump:
e582f9
                 print(self.base.output.fmtSection('repo: ' + repo.id))
e582f9
-                for name, val in repo_modify.items():
e582f9
-                    if repo._has_option(name):
e582f9
-                        repo._set_value(name, val)
e582f9
                 print(repo.dump())
e582f9
 
e582f9
     def add_repo(self):
e582f9
-- 
e582f9
2.21.0
e582f9
e582f9
e582f9
From f096fe3e88884f8cc212bfcee5549bfc6b8a3ad0 Mon Sep 17 00:00:00 2001
e582f9
From: Jaroslav Rohel <jrohel@redhat.com>
e582f9
Date: Wed, 10 Jul 2019 09:21:37 +0200
e582f9
Subject: [PATCH 2/6] [config-manager] --setopt: Add globs support to repoid
e582f9
 (RhBug:1702678)
e582f9
e582f9
Set key in all repositories whose id starts with "updates-testing":
e582f9
dnf config-manager --save --setopt=updates-testing*.skip_if_unavailable=true
e582f9
---
e582f9
 plugins/config_manager.py | 8 +++++---
e582f9
 1 file changed, 5 insertions(+), 3 deletions(-)
e582f9
e582f9
diff --git a/plugins/config_manager.py b/plugins/config_manager.py
e582f9
index 6db1bcb..dedcc82 100644
e582f9
--- a/plugins/config_manager.py
e582f9
+++ b/plugins/config_manager.py
e582f9
@@ -23,6 +23,7 @@ from dnfpluginscore import _, logger, P_
e582f9
 import dnf
e582f9
 import dnf.cli
e582f9
 import dnf.pycomp
e582f9
+import fnmatch
e582f9
 import os
e582f9
 import re
e582f9
 import shutil
e582f9
@@ -111,9 +112,10 @@ class ConfigManagerCommand(dnf.cli.Command):
e582f9
                 repo_modify['enabled'] = "1"
e582f9
             elif self.opts.set_disabled:
e582f9
                 repo_modify['enabled'] = "0"
e582f9
-            if (hasattr(self.opts, 'repo_setopts')
e582f9
-                    and repo.id in self.opts.repo_setopts):
e582f9
-                repo_modify.update(self.opts.repo_setopts[repo.id])
e582f9
+            if hasattr(self.opts, 'repo_setopts'):
e582f9
+                for repoid, setopts in self.opts.repo_setopts.items():
e582f9
+                    if fnmatch.fnmatch(repo.id, repoid):
e582f9
+                        repo_modify.update(setopts)
e582f9
             if self.opts.save and repo_modify:
e582f9
                 self.base.conf.write_raw_configfile(repo.repofile, repo.id, sbc.substitutions, repo_modify)
e582f9
             if self.opts.dump:
e582f9
-- 
e582f9
2.21.0
e582f9
e582f9
e582f9
From c2ef00188a7ec911a5efc36d3df0cceae5a682c1 Mon Sep 17 00:00:00 2001
e582f9
From: Jaroslav Rohel <jrohel@redhat.com>
e582f9
Date: Tue, 16 Jul 2019 13:32:39 +0200
e582f9
Subject: [PATCH 3/6] [config-manager] --setopt=key=value is not applied to
e582f9
 repositories config (RhBug:1702678)
e582f9
e582f9
The command "dnf config-manager --setopt=key=value repo1 main" set key value
e582f9
in repo1 and global config before the patch. It was inconsistent with the rest
e582f9
of DNF because "--setopt=key=value" means to set key in global config only.
e582f9
To set key in repos we can use "--setopt=*.key=value".
e582f9
---
e582f9
 plugins/config_manager.py | 2 +-
e582f9
 1 file changed, 1 insertion(+), 1 deletion(-)
e582f9
e582f9
diff --git a/plugins/config_manager.py b/plugins/config_manager.py
e582f9
index dedcc82..1dcf085 100644
e582f9
--- a/plugins/config_manager.py
e582f9
+++ b/plugins/config_manager.py
e582f9
@@ -107,7 +107,7 @@ class ConfigManagerCommand(dnf.cli.Command):
e582f9
             raise dnf.exceptions.Error(_("No matching repo to modify: %s.")
e582f9
                                        % ', '.join(self.opts.crepo))
e582f9
         for repo in sorted(matched):
e582f9
-            repo_modify = dict(modify)  # create local copy
e582f9
+            repo_modify = {}
e582f9
             if self.opts.set_enabled:
e582f9
                 repo_modify['enabled'] = "1"
e582f9
             elif self.opts.set_disabled:
e582f9
-- 
e582f9
2.21.0
e582f9
e582f9
e582f9
From 3af60a1613877ad2fd090a83ba9da00623a00818 Mon Sep 17 00:00:00 2001
e582f9
From: Jaroslav Rohel <jrohel@redhat.com>
e582f9
Date: Tue, 16 Jul 2019 14:05:54 +0200
e582f9
Subject: [PATCH 4/6] [config-manager] --setopt and empty list of repositories
e582f9
 (RhBug:1702678)
e582f9
e582f9
This:
e582f9
"dnf config-manager --save --setopts=repo1.key1=value1 --setopt=repo2.key2=value2 repo1 repo2"
e582f9
e582f9
can be replaced by this now:
e582f9
"dnf config-manager --save --setopts=repo1.key1=value1 --setopt=repo2.key2=value2"
e582f9
e582f9
Empty list of repositories allowed to change only the global configuration
e582f9
before. Now empty list of repositories means that setopt works
e582f9
for any repository too.
e582f9
e582f9
Better compatibility with YUM.
e582f9
It solves : https://bugzilla.redhat.com/show_bug.cgi?id=1702678
e582f9
---
e582f9
 plugins/config_manager.py | 8 ++++++--
e582f9
 1 file changed, 6 insertions(+), 2 deletions(-)
e582f9
e582f9
diff --git a/plugins/config_manager.py b/plugins/config_manager.py
e582f9
index 1dcf085..41b36fa 100644
e582f9
--- a/plugins/config_manager.py
e582f9
+++ b/plugins/config_manager.py
e582f9
@@ -96,12 +96,16 @@ class ConfigManagerCommand(dnf.cli.Command):
e582f9
         if self.opts.set_enabled or self.opts.set_disabled:
e582f9
             self.opts.save = True
e582f9
 
e582f9
+        matched = []
e582f9
         if self.opts.crepo:
e582f9
-            matched = []
e582f9
             for name in self.opts.crepo:
e582f9
                 matched.extend(self.base.repos.get_matching(name))
e582f9
         else:
e582f9
-            return
e582f9
+            if hasattr(self.opts, 'repo_setopts'):
e582f9
+                for name in self.opts.repo_setopts.keys():
e582f9
+                    matched.extend(self.base.repos.get_matching(name))
e582f9
+            if not matched:
e582f9
+                return
e582f9
 
e582f9
         if not matched:
e582f9
             raise dnf.exceptions.Error(_("No matching repo to modify: %s.")
e582f9
-- 
e582f9
2.21.0
e582f9
e582f9
e582f9
From 27205851a592a3383a7592d87ceee5b69c9dfb70 Mon Sep 17 00:00:00 2001
e582f9
From: Jaroslav Rohel <jrohel@redhat.com>
e582f9
Date: Tue, 16 Jul 2019 15:51:38 +0200
e582f9
Subject: [PATCH 5/6] [config-manager] --setopt: Add check for existence of
e582f9
 input repositories (RhBug:1702678)
e582f9
e582f9
Examples:
e582f9
dnf config-manager --save --setopt=non_existent.key=value
e582f9
Error: No matching repo to modify: non_existent.
e582f9
e582f9
dnf config-manager --save --setopt=non_existent*.key=value
e582f9
Error: No matching repo to modify: non_existent*.
e582f9
e582f9
None change in configuration is done after the error.
e582f9
---
e582f9
 plugins/config_manager.py | 44 ++++++++++++++++++++++++++-------------
e582f9
 1 file changed, 29 insertions(+), 15 deletions(-)
e582f9
e582f9
diff --git a/plugins/config_manager.py b/plugins/config_manager.py
e582f9
index 41b36fa..83d58be 100644
e582f9
--- a/plugins/config_manager.py
e582f9
+++ b/plugins/config_manager.py
e582f9
@@ -78,6 +78,31 @@ class ConfigManagerCommand(dnf.cli.Command):
e582f9
     def modify_repo(self):
e582f9
         """ process --set-enabled, --set-disabled and --setopt options """
e582f9
 
e582f9
+        matching_repos = []         # list of matched repositories
e582f9
+        not_matching_repos_id = set()  # IDs of not matched repositories
e582f9
+
e582f9
+        def match_repos(key, add_matching_repos):
e582f9
+            matching = self.base.repos.get_matching(key)
e582f9
+            if not matching:
e582f9
+                not_matching_repos_id.add(name)
e582f9
+            elif add_matching_repos:
e582f9
+                matching_repos.extend(matching)
e582f9
+
e582f9
+        if self.opts.crepo:
e582f9
+            for name in self.opts.crepo:
e582f9
+                match_repos(name, True)
e582f9
+            if hasattr(self.opts, 'repo_setopts'):
e582f9
+                for name in self.opts.repo_setopts.keys():
e582f9
+                    match_repos(name, False)
e582f9
+        else:
e582f9
+            if hasattr(self.opts, 'repo_setopts'):
e582f9
+                for name in self.opts.repo_setopts.keys():
e582f9
+                    match_repos(name, True)
e582f9
+
e582f9
+        if not_matching_repos_id:
e582f9
+            raise dnf.exceptions.Error(_("No matching repo to modify: %s.")
e582f9
+                                       % ', '.join(not_matching_repos_id))
e582f9
+
e582f9
         sbc = self.base.conf
e582f9
         modify = {}
e582f9
         if hasattr(self.opts, 'main_setopts') and self.opts.main_setopts:
e582f9
@@ -93,24 +118,13 @@ class ConfigManagerCommand(dnf.cli.Command):
e582f9
                 print(self.base.output.fmtSection('main'))
e582f9
                 print(self.base.conf.dump())
e582f9
 
e582f9
+        if not matching_repos:
e582f9
+            return
e582f9
+
e582f9
         if self.opts.set_enabled or self.opts.set_disabled:
e582f9
             self.opts.save = True
e582f9
 
e582f9
-        matched = []
e582f9
-        if self.opts.crepo:
e582f9
-            for name in self.opts.crepo:
e582f9
-                matched.extend(self.base.repos.get_matching(name))
e582f9
-        else:
e582f9
-            if hasattr(self.opts, 'repo_setopts'):
e582f9
-                for name in self.opts.repo_setopts.keys():
e582f9
-                    matched.extend(self.base.repos.get_matching(name))
e582f9
-            if not matched:
e582f9
-                return
e582f9
-
e582f9
-        if not matched:
e582f9
-            raise dnf.exceptions.Error(_("No matching repo to modify: %s.")
e582f9
-                                       % ', '.join(self.opts.crepo))
e582f9
-        for repo in sorted(matched):
e582f9
+        for repo in sorted(matching_repos):
e582f9
             repo_modify = {}
e582f9
             if self.opts.set_enabled:
e582f9
                 repo_modify['enabled'] = "1"
e582f9
-- 
e582f9
2.21.0
e582f9
e582f9
e582f9
From f7d1fa8e5f657b3cc8ed60acdeaa02f6b725312a Mon Sep 17 00:00:00 2001
e582f9
From: Jaroslav Rohel <jrohel@redhat.com>
e582f9
Date: Thu, 18 Jul 2019 12:13:43 +0200
e582f9
Subject: [PATCH 6/6] [config-manager] Update documentation (RhBug:1702678)
e582f9
e582f9
---
e582f9
 doc/config_manager.rst | 32 +++++++++++++++++++++-----------
e582f9
 1 file changed, 21 insertions(+), 11 deletions(-)
e582f9
e582f9
diff --git a/doc/config_manager.rst b/doc/config_manager.rst
e582f9
index 2feafcb..80ee0fa 100644
e582f9
--- a/doc/config_manager.rst
e582f9
+++ b/doc/config_manager.rst
e582f9
@@ -19,22 +19,25 @@
e582f9
  DNF config-manager Plugin
e582f9
 ==========================
e582f9
 
e582f9
-Manage main DNF configuration options, toggle which
e582f9
+Manage main and repository DNF configuration options, toggle which
e582f9
 repositories are enabled or disabled, and add new repositories.
e582f9
 
e582f9
 --------
e582f9
 Synopsis
e582f9
 --------
e582f9
 
e582f9
-``dnf config-manager [options] <repoid>...``
e582f9
+``dnf config-manager [options] <section>...``
e582f9
 
e582f9
 ---------
e582f9
 Arguments
e582f9
 ---------
e582f9
 
e582f9
-``<repoid>``
e582f9
-    Display / modify a repository identified by <repoid>. If not specified, display / modify
e582f9
-    main DNF configuration. Repositories can be specified using globs.
e582f9
+``<section>``
e582f9
+    This argument can be used to explicitly select the configuration sections to manage.
e582f9
+    A section can either be ``main`` or a repoid.
e582f9
+    If not specified, the program will select the ``main`` section and each repoid
e582f9
+    used within any ``--setopt`` options.
e582f9
+    A repoid can be specified using globs.
e582f9
 
e582f9
 -------
e582f9
 Options
e582f9
@@ -51,13 +54,17 @@ Options
e582f9
     Print dump of current configuration values to stdout.
e582f9
 
e582f9
 ``--set-disabled``, ``--disable``
e582f9
-    Disable the specified repos (automatically saves).
e582f9
+    Disable the specified repos (implies ``--save``).
e582f9
 
e582f9
 ``--set-enabled``, ``--enable``
e582f9
-    Enable the specified repos (automatically saves).
e582f9
+    Enable the specified repos (implies ``--save``).
e582f9
 
e582f9
 ``--save``
e582f9
-    Save the current options (useful with --setopt).
e582f9
+    Save the current options (useful with ``--setopt``).
e582f9
+
e582f9
+``--setopt=<option>=<value>``
e582f9
+    Set a configuration option. To set configuration options for repositories, use
e582f9
+    ``repoid.option`` for the ``<option>``. Globs are supported in repoid.
e582f9
 
e582f9
 --------
e582f9
 Examples
e582f9
@@ -71,12 +78,15 @@ Examples
e582f9
 ``dnf config-manager --dump``
e582f9
     Display main DNF configuration.
e582f9
 
e582f9
-``dnf config-manager <repoid> --dump``
e582f9
-    Display configuration of a repository identified by <repoid>.
e582f9
+``dnf config-manager --dump <section>``
e582f9
+    Display configuration of a repository identified by <section>.
e582f9
 
e582f9
 ``dnf config-manager --set-enabled <repoid>``
e582f9
     Enable repository identified by <repoid> and make the change permanent.
e582f9
 
e582f9
-``dnf config-manager --setopt proxy=http://proxy.example.com:3128/ <repo1> <repo2> --save``
e582f9
+``dnf config-manager --save --setopt=*.proxy=http://proxy.example.com:3128/ <repo1> <repo2>``
e582f9
     Update proxy setting in repositories with repoid <repo1> and <repo2> and make the change
e582f9
     permanent.
e582f9
+
e582f9
+``dnf config-manager --save --setopt=*-debuginfo.gpgcheck=0``
e582f9
+    Update gpgcheck setting in all repositories whose id ends with -debuginfo and make the change permanent.
e582f9
-- 
e582f9
2.21.0
e582f9