dcavalca / rpms / libdnf

Forked from rpms/libdnf 2 years ago
Clone

Blame SOURCES/0004-context-improve-retrieving-repository-configuration.patch

208e85
From be8449aa177473a834a5b2c401a8a3fcc61522b4 Mon Sep 17 00:00:00 2001
208e85
From: Jaroslav Rohel <jrohel@redhat.com>
208e85
Date: Wed, 2 Dec 2020 08:00:07 +0100
208e85
Subject: [PATCH 1/9] Option: Add reset() method
208e85
208e85
The method resets the option to its initial state.
208e85
Can be used, for example, before reloading the configuration in daemon
208e85
mode (PackageKit).
208e85
---
208e85
 libdnf/conf/Option.hpp           |  2 ++
208e85
 libdnf/conf/OptionBool.hpp       |  9 ++++++++-
208e85
 libdnf/conf/OptionChild.hpp      | 14 ++++++++++++++
208e85
 libdnf/conf/OptionEnum.hpp       | 15 +++++++++++++++
208e85
 libdnf/conf/OptionNumber.hpp     | 10 +++++++++-
208e85
 libdnf/conf/OptionString.cpp     | 11 ++++++++---
208e85
 libdnf/conf/OptionString.hpp     |  8 ++++++++
208e85
 libdnf/conf/OptionStringList.hpp |  9 ++++++++-
208e85
 8 files changed, 72 insertions(+), 6 deletions(-)
208e85
208e85
diff --git a/libdnf/conf/Option.hpp b/libdnf/conf/Option.hpp
208e85
index e9a9dfc84..849871fe7 100644
208e85
--- a/libdnf/conf/Option.hpp
208e85
+++ b/libdnf/conf/Option.hpp
208e85
@@ -62,6 +62,8 @@ class Option {
208e85
     virtual void set(Priority priority, const std::string & value) = 0;
208e85
     virtual std::string getValueString() const = 0;
208e85
     virtual bool empty() const noexcept;
208e85
+    /// Resets the option to its initial state.
208e85
+    virtual void reset() = 0;
208e85
     virtual ~Option() = default;
208e85
 
208e85
 protected:
208e85
diff --git a/libdnf/conf/OptionBool.hpp b/libdnf/conf/OptionBool.hpp
208e85
index c27ab0b79..a5e647807 100644
208e85
--- a/libdnf/conf/OptionBool.hpp
208e85
+++ b/libdnf/conf/OptionBool.hpp
208e85
@@ -47,6 +47,7 @@ class OptionBool : public Option {
208e85
     std::string getValueString() const override;
208e85
     const char * const * getTrueValues() const noexcept;
208e85
     const char * const * getFalseValues() const noexcept;
208e85
+    void reset() override;
208e85
 
208e85
 protected:
208e85
     const char * const * const trueValues;
208e85
@@ -84,7 +85,13 @@ inline const char * const * OptionBool::getTrueValues() const noexcept
208e85
 
208e85
 inline const char * const * OptionBool::getFalseValues() const noexcept
208e85
 {
208e85
-    return falseValues ? falseValues : defFalseValues; 
208e85
+    return falseValues ? falseValues : defFalseValues;
208e85
+}
208e85
+
208e85
+inline void OptionBool::reset()
208e85
+{
208e85
+    value = defaultValue;
208e85
+    priority = Priority::DEFAULT;
208e85
 }
208e85
 
208e85
 }
208e85
diff --git a/libdnf/conf/OptionChild.hpp b/libdnf/conf/OptionChild.hpp
208e85
index 5d1503cb6..3056345f9 100644
208e85
--- a/libdnf/conf/OptionChild.hpp
208e85
+++ b/libdnf/conf/OptionChild.hpp
208e85
@@ -39,6 +39,7 @@ class OptionChild : public Option {
208e85
     const typename ParentOptionType::ValueType getDefaultValue() const;
208e85
     std::string getValueString() const override;
208e85
     bool empty() const noexcept override;
208e85
+    void reset() override;
208e85
 
208e85
 private:
208e85
     const ParentOptionType * parent;
208e85
@@ -56,6 +57,7 @@ class OptionChild
208e85
     const std::string & getDefaultValue() const;
208e85
     std::string getValueString() const override;
208e85
     bool empty() const noexcept override;
208e85
+    void reset() override;
208e85
 
208e85
 private:
208e85
     const ParentOptionType * parent;
208e85
@@ -119,6 +121,12 @@ inline bool OptionChild<ParentOptionType, Enable>::empty() const noexcept
208e85
     return priority == Priority::EMPTY && parent->empty();
208e85
 }
208e85
 
208e85
+template <class ParentOptionType, class Enable>
208e85
+inline void OptionChild<ParentOptionType, Enable>::reset()
208e85
+{
208e85
+    priority = Priority::EMPTY;
208e85
+}
208e85
+
208e85
 template <class ParentOptionType>
208e85
 inline OptionChild<ParentOptionType, typename std::enable_if<std::is_same<typename ParentOptionType::ValueType, std::string>::value>::type>::OptionChild(const ParentOptionType & parent)
208e85
 : parent(&parent) {}
208e85
@@ -171,6 +179,12 @@ inline bool OptionChild
208e85
     return priority == Priority::EMPTY && parent->empty();
208e85
 }
208e85
 
208e85
+template <class ParentOptionType>
208e85
+inline void OptionChild<ParentOptionType, typename std::enable_if<std::is_same<typename ParentOptionType::ValueType, std::string>::value>::type>::reset()
208e85
+{
208e85
+    priority = Priority::EMPTY;
208e85
+}
208e85
+
208e85
 }
208e85
 
208e85
 #endif
208e85
diff --git a/libdnf/conf/OptionEnum.hpp b/libdnf/conf/OptionEnum.hpp
208e85
index c63156cb3..d2f710f20 100644
208e85
--- a/libdnf/conf/OptionEnum.hpp
208e85
+++ b/libdnf/conf/OptionEnum.hpp
208e85
@@ -49,6 +49,7 @@ class OptionEnum : public Option {
208e85
     T getDefaultValue() const;
208e85
     std::string toString(ValueType value) const;
208e85
     std::string getValueString() const override;
208e85
+    void reset() override;
208e85
 
208e85
 protected:
208e85
     FromStringFunc fromStringUser;
208e85
@@ -74,6 +75,7 @@ class OptionEnum<std::string> : public Option {
208e85
     const std::string & getValue() const;
208e85
     const std::string & getDefaultValue() const;
208e85
     std::string getValueString() const override;
208e85
+    void reset() override;
208e85
 
208e85
 protected:
208e85
     FromStringFunc fromStringUser;
208e85
@@ -88,6 +90,13 @@ inline OptionEnum<T> * OptionEnum<T>::clone() const
208e85
     return new OptionEnum<T>(*this);
208e85
 }
208e85
 
208e85
+template <typename T>
208e85
+inline void OptionEnum<T>::reset()
208e85
+{
208e85
+    value = defaultValue;
208e85
+    priority = Priority::DEFAULT;
208e85
+}
208e85
+
208e85
 inline OptionEnum<std::string> * OptionEnum<std::string>::clone() const
208e85
 {
208e85
     return new OptionEnum<std::string>(*this);
208e85
@@ -108,6 +117,12 @@ inline std::string OptionEnum<std::string>::getValueString() const
208e85
     return value;
208e85
 }
208e85
 
208e85
+inline void OptionEnum<std::string>::reset()
208e85
+{
208e85
+    value = defaultValue;
208e85
+    priority = Priority::DEFAULT;
208e85
+}
208e85
+
208e85
 }
208e85
 
208e85
 #endif
208e85
diff --git a/libdnf/conf/OptionNumber.hpp b/libdnf/conf/OptionNumber.hpp
208e85
index 98988fd50..f7a7b3d6e 100644
208e85
--- a/libdnf/conf/OptionNumber.hpp
208e85
+++ b/libdnf/conf/OptionNumber.hpp
208e85
@@ -50,6 +50,7 @@ class OptionNumber : public Option {
208e85
     T getDefaultValue() const;
208e85
     std::string toString(ValueType value) const;
208e85
     std::string getValueString() const override;
208e85
+    void reset() override;
208e85
 
208e85
 protected:
208e85
     FromStringFunc fromStringUser;
208e85
@@ -80,7 +81,14 @@ inline T OptionNumber<T>::getDefaultValue() const
208e85
 template <typename T>
208e85
 inline std::string OptionNumber<T>::getValueString() const
208e85
 {
208e85
-    return toString(value); 
208e85
+    return toString(value);
208e85
+}
208e85
+
208e85
+template <typename T>
208e85
+inline void OptionNumber<T>::reset()
208e85
+{
208e85
+    value = defaultValue;
208e85
+    priority = Priority::DEFAULT;
208e85
 }
208e85
 
208e85
 extern template class OptionNumber<std::int32_t>;
208e85
diff --git a/libdnf/conf/OptionString.cpp b/libdnf/conf/OptionString.cpp
208e85
index d27194f7a..b42e6c633 100644
208e85
--- a/libdnf/conf/OptionString.cpp
208e85
+++ b/libdnf/conf/OptionString.cpp
208e85
@@ -27,18 +27,21 @@
208e85
 namespace libdnf {
208e85
 
208e85
 OptionString::OptionString(const std::string & defaultValue)
208e85
-: Option(Priority::DEFAULT), defaultValue(defaultValue), value(defaultValue) {}
208e85
+: Option(Priority::DEFAULT), initPriority(Priority::DEFAULT), defaultValue(defaultValue), value(defaultValue) {}
208e85
 
208e85
 OptionString::OptionString(const char * defaultValue)
208e85
 {
208e85
     if (defaultValue) {
208e85
         this->value = this->defaultValue = defaultValue;
208e85
-        this->priority = Priority::DEFAULT;
208e85
+        this->initPriority = this->priority = Priority::DEFAULT;
208e85
+    } else {
208e85
+        this->initPriority = Priority::EMPTY;
208e85
     }
208e85
 }
208e85
 
208e85
 OptionString::OptionString(const std::string & defaultValue, const std::string & regex, bool icase)
208e85
-: Option(Priority::DEFAULT), regex(regex), icase(icase), defaultValue(defaultValue), value(defaultValue) { test(defaultValue); }
208e85
+: Option(Priority::DEFAULT), initPriority(Priority::DEFAULT), regex(regex), icase(icase)
208e85
+, defaultValue(defaultValue), value(defaultValue) { test(defaultValue); }
208e85
 
208e85
 OptionString::OptionString(const char * defaultValue, const std::string & regex, bool icase)
208e85
 : regex(regex), icase(icase)
208e85
@@ -48,6 +51,8 @@ OptionString::OptionString(const char * defaultValue, const std::string & regex,
208e85
         test(this->defaultValue);
208e85
         this->value = this->defaultValue;
208e85
         this->priority = Priority::DEFAULT;
208e85
+    } else {
208e85
+        this->initPriority = Priority::EMPTY;
208e85
     }
208e85
 }
208e85
 
208e85
diff --git a/libdnf/conf/OptionString.hpp b/libdnf/conf/OptionString.hpp
208e85
index 2e26305c4..03fef8bcf 100644
208e85
--- a/libdnf/conf/OptionString.hpp
208e85
+++ b/libdnf/conf/OptionString.hpp
208e85
@@ -42,8 +42,10 @@ class OptionString : public Option {
208e85
     const std::string & getValue() const;
208e85
     const std::string & getDefaultValue() const noexcept;
208e85
     std::string getValueString() const override;
208e85
+    void reset() override;
208e85
 
208e85
 protected:
208e85
+    Priority initPriority;
208e85
     std::string regex;
208e85
     bool icase;
208e85
     std::string defaultValue;
208e85
@@ -70,6 +72,12 @@ inline std::string OptionString::fromString(const std::string & value) const
208e85
     return value;
208e85
 }
208e85
 
208e85
+inline void OptionString::reset()
208e85
+{
208e85
+    value = defaultValue;
208e85
+    priority = initPriority;
208e85
+}
208e85
+
208e85
 }
208e85
 
208e85
 #endif
208e85
diff --git a/libdnf/conf/OptionStringList.hpp b/libdnf/conf/OptionStringList.hpp
208e85
index 942e56b16..20debaa8c 100644
208e85
--- a/libdnf/conf/OptionStringList.hpp
208e85
+++ b/libdnf/conf/OptionStringList.hpp
208e85
@@ -45,6 +45,7 @@ class OptionStringList : public Option {
208e85
     const ValueType & getDefaultValue() const;
208e85
     std::string toString(const ValueType & value) const;
208e85
     std::string getValueString() const override;
208e85
+    void reset() override;
208e85
 
208e85
 protected:
208e85
     std::string regex;
208e85
@@ -70,7 +71,13 @@ inline const OptionStringList::ValueType & OptionStringList::getDefaultValue() c
208e85
 
208e85
 inline std::string OptionStringList::getValueString() const
208e85
 {
208e85
-    return toString(value); 
208e85
+    return toString(value);
208e85
+}
208e85
+
208e85
+inline void OptionStringList::reset()
208e85
+{
208e85
+    value = defaultValue;
208e85
+    priority = Priority::DEFAULT;
208e85
 }
208e85
 
208e85
 }
208e85
208e85
From 372a000414875f323147cd342dd8b4c8c7ebe260 Mon Sep 17 00:00:00 2001
208e85
From: Jaroslav Rohel <jrohel@redhat.com>
208e85
Date: Tue, 1 Dec 2020 08:29:53 +0100
208e85
Subject: [PATCH 2/9] Add OptionBinds::getOption() method
208e85
208e85
Sometime we want direct access to the underlying Option.
208e85
E.g. we want to get its original value (not just a string representation)
208e85
or find out the Option type.
208e85
---
208e85
 libdnf/conf/OptionBinds.cpp | 9 +++++++++
208e85
 libdnf/conf/OptionBinds.hpp | 2 ++
208e85
 2 files changed, 11 insertions(+)
208e85
208e85
diff --git a/libdnf/conf/OptionBinds.cpp b/libdnf/conf/OptionBinds.cpp
208e85
index f7c67540b..ab53518a3 100644
208e85
--- a/libdnf/conf/OptionBinds.cpp
208e85
+++ b/libdnf/conf/OptionBinds.cpp
208e85
@@ -66,6 +66,15 @@ bool OptionBinds::Item::getAddValue() const
208e85
     return addValue;
208e85
 }
208e85
 
208e85
+const Option & OptionBinds::Item::getOption() const
208e85
+{
208e85
+    return *option;
208e85
+}
208e85
+
208e85
+Option & OptionBinds::Item::getOption()
208e85
+{
208e85
+    return *option;
208e85
+}
208e85
 
208e85
 // =========== OptionBinds class ===============
208e85
 
208e85
diff --git a/libdnf/conf/OptionBinds.hpp b/libdnf/conf/OptionBinds.hpp
208e85
index 715c37e26..515120b93 100644
208e85
--- a/libdnf/conf/OptionBinds.hpp
208e85
+++ b/libdnf/conf/OptionBinds.hpp
208e85
@@ -55,6 +55,8 @@ class OptionBinds {
208e85
         void newString(Option::Priority priority, const std::string & value);
208e85
         std::string getValueString() const;
208e85
         bool getAddValue() const;
208e85
+        const Option & getOption() const;
208e85
+        Option & getOption();
208e85
 
208e85
     private:
208e85
         friend class OptionBinds;
208e85
208e85
From 3a686c378978c90538a6ac5d9826d52ce7c8daf6 Mon Sep 17 00:00:00 2001
208e85
From: Jaroslav Rohel <jrohel@redhat.com>
208e85
Date: Tue, 1 Dec 2020 08:37:14 +0100
208e85
Subject: [PATCH 3/9] [context] Add dnf_repo_conf_from_gkeyfile() and
208e85
 dnf_repo_conf_reset()
208e85
208e85
dnf_repo_conf_from_gkeyfile():
208e85
The function reloads repository configuration from GKeyFile.
208e85
208e85
dnf_repo_conf_reset():
208e85
Resets repository configuration options previously readed from repository
208e85
configuration file to initial state.
208e85
---
208e85
 libdnf/dnf-repo.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++++
208e85
 1 file changed, 64 insertions(+)
208e85
208e85
diff --git a/libdnf/dnf-repo.cpp b/libdnf/dnf-repo.cpp
208e85
index 00f4bbf7b..9f283df55 100644
208e85
--- a/libdnf/dnf-repo.cpp
208e85
+++ b/libdnf/dnf-repo.cpp
208e85
@@ -936,6 +936,70 @@ dnf_repo_get_boolean(GKeyFile *keyfile,
208e85
     return false;
208e85
 }
208e85
 
208e85
+/* Resets repository configuration options previously readed from repository
208e85
+ * configuration file to initial state. */
208e85
+static void
208e85
+dnf_repo_conf_reset(libdnf::ConfigRepo &config)
208e85
+{
208e85
+    for (auto & item : config.optBinds()) {
208e85
+        auto & itemOption = item.second;
208e85
+        if (itemOption.getPriority() == libdnf::Option::Priority::REPOCONFIG) {
208e85
+            itemOption.getOption().reset();
208e85
+        }
208e85
+    }
208e85
+}
208e85
+
208e85
+/* Loads repository configuration from GKeyFile */
208e85
+static void
208e85
+dnf_repo_conf_from_gkeyfile(libdnf::ConfigRepo &config, const char *repoId, GKeyFile *gkeyFile)
208e85
+{
208e85
+    // Reset to the initial state before reloading the configuration.
208e85
+    dnf_repo_conf_reset(config);
208e85
+
208e85
+    g_auto(GStrv) keys = g_key_file_get_keys(gkeyFile, repoId, NULL, NULL);
208e85
+    for (auto it = keys; *it != NULL; ++it) {
208e85
+        auto key = *it;
208e85
+        g_autofree gchar *str = g_key_file_get_value(gkeyFile, repoId, key, NULL);
208e85
+        if (str) {
208e85
+            try {
208e85
+                auto & optionItem = config.optBinds().at(key);
208e85
+
208e85
+                if (dynamic_cast<libdnf::OptionStringList*>(&optionItem.getOption()) ||
208e85
+                    dynamic_cast<libdnf::OptionChild<libdnf::OptionStringList>*>(&optionItem.getOption())
208e85
+                ) {
208e85
+
208e85
+                    // reload list option from gKeyFile using g_key_file_get_string_list()
208e85
+                    // g_key_file_get_value () is problematic for multiline lists
208e85
+                    g_auto(GStrv) list = g_key_file_get_string_list(gkeyFile, repoId, key, NULL, NULL);
208e85
+                    if (list) {
208e85
+                        // list can be ['value1', 'value2, value3'] therefore we first join
208e85
+                        // to have 'value1, value2, value3'
208e85
+                        g_autofree gchar * tmp_strval = g_strjoinv(",", list);
208e85
+                        try {
208e85
+                            optionItem.newString(libdnf::Option::Priority::REPOCONFIG, tmp_strval);
208e85
+                        } catch (const std::exception & ex) {
208e85
+                            g_debug("Invalid configuration value: %s = %s in %s; %s", key, str, repoId, ex.what());
208e85
+                        }
208e85
+                    }
208e85
+
208e85
+                } else {
208e85
+
208e85
+                    // process other (non list) options
208e85
+                    try {
208e85
+                        optionItem.newString(libdnf::Option::Priority::REPOCONFIG, str);
208e85
+                    } catch (const std::exception & ex) {
208e85
+                        g_debug("Invalid configuration value: %s = %s in %s; %s", key, str, repoId, ex.what());
208e85
+                    }
208e85
+
208e85
+                }
208e85
+
208e85
+            } catch (const std::exception &) {
208e85
+                g_debug("Unknown configuration option: %s = %s in %s", key, str, repoId);
208e85
+            }
208e85
+        }
208e85
+    }
208e85
+}
208e85
+
208e85
 /* Initialize (or potentially reset) repo & LrHandle from keyfile values. */
208e85
 static gboolean
208e85
 dnf_repo_set_keyfile_data(DnfRepo *repo, GError **error)
208e85
208e85
From 5f1c06a66fcdb2c2340c11c07c5ba0ea3abf4b77 Mon Sep 17 00:00:00 2001
208e85
From: Jaroslav Rohel <jrohel@redhat.com>
208e85
Date: Wed, 2 Dec 2020 11:37:26 +0100
208e85
Subject: [PATCH 4/9] [context] Use dnf_repo_conf_from_gkeyfile() for repo
208e85
 configuration reload
208e85
208e85
The dnf_repo_set_key_file_data() uses dnf_repo_conf_from_gkeyfile() now.
208e85
All occurrences of the direct use 'repo->getConfig()->.*set' and
208e85
newString() were removed.
208e85
---
208e85
 libdnf/dnf-repo.cpp | 121 +++++++++-----------------------------------
208e85
 1 file changed, 25 insertions(+), 96 deletions(-)
208e85
208e85
diff --git a/libdnf/dnf-repo.cpp b/libdnf/dnf-repo.cpp
208e85
index 9f283df55..2837580f7 100644
208e85
--- a/libdnf/dnf-repo.cpp
208e85
+++ b/libdnf/dnf-repo.cpp
208e85
@@ -1006,7 +1006,6 @@ dnf_repo_set_keyfile_data(DnfRepo *repo, GError **error)
208e85
 {
208e85
     DnfRepoPrivate *priv = GET_PRIVATE(repo);
208e85
     guint cost;
208e85
-    gboolean module_hotfixes = false;
208e85
     g_autofree gchar *metadata_expire_str = NULL;
208e85
     g_autofree gchar *mirrorlist = NULL;
208e85
     g_autofree gchar *mirrorlisturl = NULL;
208e85
@@ -1016,48 +1015,28 @@ dnf_repo_set_keyfile_data(DnfRepo *repo, GError **error)
208e85
     g_autofree gchar *usr = NULL;
208e85
     g_autofree gchar *usr_pwd = NULL;
208e85
     g_autofree gchar *usr_pwd_proxy = NULL;
208e85
-    g_auto(GStrv) baseurls;
208e85
 
208e85
     auto repoId = priv->repo->getId().c_str();
208e85
     g_debug("setting keyfile data for %s", repoId);
208e85
 
208e85
-    /* skip_if_unavailable is optional */
208e85
-    if (g_key_file_has_key(priv->keyfile, repoId, "skip_if_unavailable", NULL)) {
208e85
-        bool skip = dnf_repo_get_boolean(priv->keyfile, repoId, "skip_if_unavailable");
208e85
-        priv->repo->getConfig()->skip_if_unavailable().set(libdnf::Option::Priority::REPOCONFIG, skip);
208e85
-    }
208e85
+    auto conf = priv->repo->getConfig();
208e85
 
208e85
-    /* priority is optional */
208e85
-    g_autofree gchar * priority_str = g_key_file_get_string(priv->keyfile, repoId, "priority", NULL);
208e85
-    if (priority_str) {
208e85
-        priv->repo->getConfig()->priority().set(libdnf::Option::Priority::REPOCONFIG, priority_str);
208e85
-    }
208e85
+    // Reload repository configuration from keyfile.
208e85
+    dnf_repo_conf_from_gkeyfile(*conf, repoId, priv->keyfile);
208e85
 
208e85
     /* cost is optional */
208e85
     cost = g_key_file_get_integer(priv->keyfile, repoId, "cost", NULL);
208e85
     if (cost != 0)
208e85
         dnf_repo_set_cost(repo, cost);
208e85
 
208e85
-    module_hotfixes = g_key_file_get_boolean(priv->keyfile, repoId, "module_hotfixes", NULL);
208e85
-    priv->repo->getConfig()->module_hotfixes().set(libdnf::Option::Priority::REPOCONFIG, module_hotfixes);
208e85
-
208e85
     /* baseurl is optional; if missing, unset it */
208e85
-    baseurls = g_key_file_get_string_list(priv->keyfile, repoId, "baseurl", NULL, NULL);
208e85
-    if (baseurls) {
208e85
-        // baseruls can be ['value1', 'value2, value3'] therefore we first join to have 'value1, value2, value3'
208e85
-        g_autofree gchar * tmp_strval = g_strjoinv(",", baseurls);
208e85
-
208e85
-        auto & bindBaseurls = priv->repo->getConfig()->optBinds().at("baseurl");
208e85
-        bindBaseurls.newString(libdnf::Option::Priority::REPOCONFIG, tmp_strval);
208e85
-
208e85
-        auto & repoBaseurls = priv->repo->getConfig()->baseurl();
208e85
-        if (!repoBaseurls.getValue().empty()){
208e85
-            auto len = repoBaseurls.getValue().size();
208e85
-            g_strfreev(baseurls);
208e85
-            baseurls = g_new0(char *, len + 1);
208e85
-            for (size_t i = 0; i < len; ++i) {
208e85
-                baseurls[i] = g_strdup(repoBaseurls.getValue()[i].c_str());
208e85
-            }
208e85
+    g_auto(GStrv) baseurls = NULL;
208e85
+    auto & repoBaseurls = conf->baseurl().getValue();
208e85
+    if (!repoBaseurls.empty()){
208e85
+        auto len = repoBaseurls.size();
208e85
+        baseurls = g_new0(char *, len + 1);
208e85
+        for (size_t i = 0; i < len; ++i) {
208e85
+            baseurls[i] = g_strdup(repoBaseurls[i].c_str());
208e85
         }
208e85
     }
208e85
     if (!lr_handle_setopt(priv->repo_handle, error, LRO_URLS, baseurls))
208e85
@@ -1093,18 +1072,6 @@ dnf_repo_set_keyfile_data(DnfRepo *repo, GError **error)
208e85
     if (!lr_handle_setopt(priv->repo_handle, error, LRO_METALINKURL, metalinkurl))
208e85
         return FALSE;
208e85
 
208e85
-    /* needed in order for addCountmeFlag() to use the same persistdir as DNF
208e85
-     * would */
208e85
-    if (metalinkurl)
208e85
-        priv->repo->getConfig()->metalink().set(libdnf::Option::Priority::REPOCONFIG, metalinkurl);
208e85
-    if (mirrorlisturl)
208e85
-        priv->repo->getConfig()->mirrorlist().set(libdnf::Option::Priority::REPOCONFIG, mirrorlisturl);
208e85
-
208e85
-    if (g_key_file_has_key(priv->keyfile, repoId, "countme", NULL)) {
208e85
-        bool countme = dnf_repo_get_boolean(priv->keyfile, repoId, "countme");
208e85
-        priv->repo->getConfig()->countme().set(libdnf::Option::Priority::REPOCONFIG, countme);
208e85
-    }
208e85
-
208e85
     /* file:// */
208e85
     if (baseurls != NULL && baseurls[0] != NULL &&
208e85
         mirrorlisturl == NULL && metalinkurl == NULL) {
208e85
@@ -1150,42 +1117,20 @@ dnf_repo_set_keyfile_data(DnfRepo *repo, GError **error)
208e85
         dnf_repo_set_location_tmp(repo, tmp->str);
208e85
     }
208e85
 
208e85
-    /* gpgkey is optional for gpgcheck=1, but required for repo_gpgcheck=1 */
208e85
+    // Sync priv->gpgkeys
208e85
     g_strfreev(priv->gpgkeys);
208e85
-    priv->gpgkeys = NULL;
208e85
-
208e85
-    g_auto(GStrv) gpgkeys;
208e85
-    gpgkeys = g_key_file_get_string_list(priv->keyfile, repoId, "gpgkey", NULL, NULL);
208e85
-
208e85
-    if (gpgkeys) {
208e85
-        // gpgkeys can be ['value1', 'value2, value3'] therefore we first join to have 'value1, value2, value3'
208e85
-        g_autofree gchar * tmp_strval = g_strjoinv(",", gpgkeys);
208e85
-
208e85
-        auto & bindGpgkeys = priv->repo->getConfig()->optBinds().at("gpgkey");
208e85
-        bindGpgkeys.newString(libdnf::Option::Priority::REPOCONFIG, tmp_strval);
208e85
-
208e85
-        auto & repoGpgkeys = priv->repo->getConfig()->gpgkey();
208e85
-        if (!repoGpgkeys.getValue().empty()){
208e85
-            auto len = repoGpgkeys.getValue().size();
208e85
-            priv->gpgkeys = g_new0(char *, len + 1);
208e85
-            for (size_t i = 0; i < len; ++i) {
208e85
-                priv->gpgkeys[i] = g_strdup(repoGpgkeys.getValue()[i].c_str());
208e85
-            }
208e85
-        } else {
208e85
-            /* Canonicalize the empty list to NULL for ease of checking elsewhere */
208e85
-            g_strfreev(static_cast<gchar **>(g_steal_pointer(&priv->gpgkeys)));
208e85
+    auto & repoGpgkeys = conf->gpgkey().getValue();
208e85
+    if (!repoGpgkeys.empty()){
208e85
+        auto len = repoGpgkeys.size();
208e85
+        priv->gpgkeys = g_new0(char *, len + 1);
208e85
+        for (size_t i = 0; i < len; ++i) {
208e85
+            priv->gpgkeys[i] = g_strdup(repoGpgkeys[i].c_str());
208e85
         }
208e85
+    } else {
208e85
+        priv->gpgkeys = NULL;
208e85
     }
208e85
 
208e85
-    if (g_key_file_has_key(priv->keyfile, repoId, "gpgcheck", NULL)) {
208e85
-        auto gpgcheck_pkgs = dnf_repo_get_boolean(priv->keyfile, repoId, "gpgcheck");
208e85
-        priv->repo->getConfig()->gpgcheck().set(libdnf::Option::Priority::REPOCONFIG, gpgcheck_pkgs);
208e85
-    }
208e85
-
208e85
-    if (g_key_file_has_key(priv->keyfile, repoId, "repo_gpgcheck", NULL)) {
208e85
-        auto gpgcheck_md = dnf_repo_get_boolean(priv->keyfile, repoId, "repo_gpgcheck");
208e85
-        priv->repo->getConfig()->repo_gpgcheck().set(libdnf::Option::Priority::REPOCONFIG, gpgcheck_md);
208e85
-    }
208e85
+    /* gpgkey is optional for gpgcheck=1, but required for repo_gpgcheck=1 */
208e85
     auto gpgcheck_md = priv->repo->getConfig()->repo_gpgcheck().getValue();
208e85
     if (gpgcheck_md && priv->gpgkeys == NULL) {
208e85
         g_set_error_literal(error,
208e85
@@ -1199,35 +1144,19 @@ dnf_repo_set_keyfile_data(DnfRepo *repo, GError **error)
208e85
     if (!lr_handle_setopt(priv->repo_handle, error, LRO_GPGCHECK, (long)gpgcheck_md))
208e85
         return FALSE;
208e85
 
208e85
-    auto & repoExcludepkgs = priv->repo->getConfig()->excludepkgs();
208e85
-    repoExcludepkgs.set(libdnf::Option::Priority::REPOCONFIG, "");
208e85
-
208e85
-    auto & bindExcludepkgs = priv->repo->getConfig()->optBinds().at("excludepkgs");
208e85
-    if (auto excludepkgs = g_key_file_get_string(priv->keyfile, repoId, "exclude", NULL)) {
208e85
-        bindExcludepkgs.newString(libdnf::Option::Priority::REPOCONFIG, excludepkgs);
208e85
-        g_free(excludepkgs);
208e85
-    }
208e85
-    if (auto excludepkgs = g_key_file_get_string(priv->keyfile, repoId, "excludepkgs", NULL)) {
208e85
-        bindExcludepkgs.newString(libdnf::Option::Priority::REPOCONFIG, excludepkgs);
208e85
-        g_free(excludepkgs);
208e85
-    }
208e85
-
208e85
+    // Sync priv->exclude_packages
208e85
     g_strfreev(priv->exclude_packages);
208e85
-    if (!repoExcludepkgs.getValue().empty()) {
208e85
-        auto len = repoExcludepkgs.getValue().size();
208e85
+    auto & repoExcludepkgs = conf->excludepkgs().getValue();
208e85
+    if (!repoExcludepkgs.empty()) {
208e85
+        auto len = repoExcludepkgs.size();
208e85
         priv->exclude_packages = g_new0(char *, len + 1);
208e85
         for (size_t i = 0; i < len; ++i) {
208e85
-            priv->exclude_packages[i] = g_strdup(repoExcludepkgs.getValue()[i].c_str());
208e85
+            priv->exclude_packages[i] = g_strdup(repoExcludepkgs[i].c_str());
208e85
         }
208e85
     } else {
208e85
         priv->exclude_packages = NULL;
208e85
     }
208e85
 
208e85
-    if (auto includepkgs = g_key_file_get_string(priv->keyfile, repoId, "includepkgs", NULL)) {
208e85
-        priv->repo->getConfig()->includepkgs().set(libdnf::Option::Priority::REPOCONFIG, includepkgs);
208e85
-        g_free(includepkgs);
208e85
-    }
208e85
-
208e85
     /* proxy is optional */
208e85
     proxy = g_key_file_get_string(priv->keyfile, repoId, "proxy", NULL);
208e85
     auto repoProxy = proxy ? (strcasecmp(proxy, "_none_") == 0 ? NULL : proxy)
208e85
208e85
From c6afbb4f93eee480c68201297e9c5c7afdf05dd3 Mon Sep 17 00:00:00 2001
208e85
From: Jaroslav Rohel <jrohel@redhat.com>
208e85
Date: Wed, 2 Dec 2020 13:26:51 +0100
208e85
Subject: [PATCH 5/9] [context] Fix: "cost" and  "metadata_expire" repository
208e85
 options
208e85
208e85
Changes in dnf_repo_set_keyfile_data():
208e85
Removed the dnf_repo_set_cost() call.
208e85
Removed the "metadata_expire" parsing and dnf_repo_set_metadata_expire() call.
208e85
208e85
The options were set earlier. The function calls were redundant and
208e85
set the priority to the wrong RUNTIME value.
208e85
---
208e85
 libdnf/dnf-repo.cpp | 103 --------------------------------------------
208e85
 1 file changed, 103 deletions(-)
208e85
208e85
diff --git a/libdnf/dnf-repo.cpp b/libdnf/dnf-repo.cpp
208e85
index 2837580f7..61d496750 100644
208e85
--- a/libdnf/dnf-repo.cpp
208e85
+++ b/libdnf/dnf-repo.cpp
208e85
@@ -816,93 +816,6 @@ dnf_repo_set_metadata_expire(DnfRepo *repo, guint metadata_expire)
208e85
     priv->repo->getConfig()->metadata_expire().set(libdnf::Option::Priority::RUNTIME, metadata_expire);
208e85
 }
208e85
 
208e85
-/**
208e85
- *  dnf_repo_parse_time_from_str
208e85
- *  @expression: a expression to be parsed
208e85
- *  @out_parsed_time: (out): return location for parsed time
208e85
- *  @error: error item
208e85
- *
208e85
- *  Parse String into an integer value of seconds, or a human
208e85
- *  readable variation specifying days, hours, minutes or seconds
208e85
- *  until something happens. Note that due to historical president
208e85
- *  -1 means "never", so this accepts that and allows
208e85
- *  the word never, too.
208e85
- *
208e85
- *  Valid inputs: 100, 1.5m, 90s, 1.2d, 1d, 0xF, 0.1, -1, never.
208e85
- *  Invalid inputs: -10, -0.1, 45.6Z, 1d6h, 1day, 1y.
208e85
-
208e85
- *  Returns: integer value in seconds
208e85
- **/
208e85
-
208e85
-static gboolean
208e85
-dnf_repo_parse_time_from_str(const gchar *expression, guint *out_parsed_time, GError **error)
208e85
-{
208e85
-    gint multiplier;
208e85
-    gdouble parsed_time;
208e85
-    gchar *endptr = NULL;
208e85
-
208e85
-    if (!g_strcmp0(expression, "")) {
208e85
-        g_set_error_literal(error,
208e85
-                            DNF_ERROR,
208e85
-                            DNF_ERROR_FILE_INVALID,
208e85
-                            "no metadata value specified");
208e85
-        return FALSE;
208e85
-    }
208e85
-
208e85
-    if (g_strcmp0(expression, "-1") == 0 ||
208e85
-        g_strcmp0(expression,"never") == 0) {
208e85
-        *out_parsed_time = G_MAXUINT;
208e85
-        return TRUE; /* Note early return */
208e85
-    }
208e85
-
208e85
-    gchar last_char = expression[ strlen(expression) - 1 ];
208e85
-
208e85
-    /* check if the input ends with h, m ,d ,s as units */
208e85
-    if (g_ascii_isalpha(last_char)) {
208e85
-        if (last_char == 'h')
208e85
-            multiplier = 60 * 60;
208e85
-        else if (last_char == 's')
208e85
-            multiplier = 1;
208e85
-        else if (last_char == 'm')
208e85
-            multiplier = 60;
208e85
-        else if (last_char == 'd')
208e85
-            multiplier = 60 * 60 * 24;
208e85
-        else {
208e85
-            g_set_error(error, DNF_ERROR, DNF_ERROR_FILE_INVALID,
208e85
-                        "unknown unit %c", last_char);
208e85
-            return FALSE;
208e85
-        }
208e85
-    }
208e85
-    else
208e85
-        multiplier = 1;
208e85
-
208e85
-    /* convert expression into a double*/
208e85
-    parsed_time = g_ascii_strtod(expression, &endptr);
208e85
-
208e85
-    /* failed to parse */
208e85
-    if (expression == endptr) {
208e85
-        g_set_error(error, DNF_ERROR, DNF_ERROR_INTERNAL_ERROR,
208e85
-                    "failed to parse time: %s", expression);
208e85
-        return FALSE;
208e85
-    }
208e85
-
208e85
-    /* time can not be below zero */
208e85
-    if (parsed_time < 0) {
208e85
-        g_set_error(error, DNF_ERROR, DNF_ERROR_INTERNAL_ERROR,
208e85
-                    "seconds value must not be negative %s",expression );
208e85
-        return FALSE;
208e85
-    }
208e85
-
208e85
-    /* time too large */
208e85
-    if (parsed_time > G_MAXDOUBLE || (parsed_time * multiplier) > G_MAXUINT){
208e85
-        g_set_error(error, DNF_ERROR, DNF_ERROR_INTERNAL_ERROR,
208e85
-                    "time too large");
208e85
-        return FALSE;
208e85
-    }
208e85
-
208e85
-    *out_parsed_time = (guint) (parsed_time * multiplier);
208e85
-    return TRUE;
208e85
-}
208e85
 /**
208e85
  * dnf_repo_get_username_password_string:
208e85
  */
208e85
@@ -1005,8 +918,6 @@ static gboolean
208e85
 dnf_repo_set_keyfile_data(DnfRepo *repo, GError **error)
208e85
 {
208e85
     DnfRepoPrivate *priv = GET_PRIVATE(repo);
208e85
-    guint cost;
208e85
-    g_autofree gchar *metadata_expire_str = NULL;
208e85
     g_autofree gchar *mirrorlist = NULL;
208e85
     g_autofree gchar *mirrorlisturl = NULL;
208e85
     g_autofree gchar *metalinkurl = NULL;
208e85
@@ -1024,11 +935,6 @@ dnf_repo_set_keyfile_data(DnfRepo *repo, GError **error)
208e85
     // Reload repository configuration from keyfile.
208e85
     dnf_repo_conf_from_gkeyfile(*conf, repoId, priv->keyfile);
208e85
 
208e85
-    /* cost is optional */
208e85
-    cost = g_key_file_get_integer(priv->keyfile, repoId, "cost", NULL);
208e85
-    if (cost != 0)
208e85
-        dnf_repo_set_cost(repo, cost);
208e85
-
208e85
     /* baseurl is optional; if missing, unset it */
208e85
     g_auto(GStrv) baseurls = NULL;
208e85
     auto & repoBaseurls = conf->baseurl().getValue();
208e85
@@ -1042,15 +948,6 @@ dnf_repo_set_keyfile_data(DnfRepo *repo, GError **error)
208e85
     if (!lr_handle_setopt(priv->repo_handle, error, LRO_URLS, baseurls))
208e85
         return FALSE;
208e85
 
208e85
-    /* metadata_expire is optional, if shown, we parse the string to add the time */
208e85
-    metadata_expire_str = g_key_file_get_string(priv->keyfile, repoId, "metadata_expire", NULL);
208e85
-    if (metadata_expire_str) {
208e85
-        guint metadata_expire;
208e85
-        if (!dnf_repo_parse_time_from_str(metadata_expire_str, &metadata_expire, error))
208e85
-            return FALSE;
208e85
-        dnf_repo_set_metadata_expire(repo, metadata_expire);
208e85
-    }
208e85
-
208e85
     /* the "mirrorlist" entry could be either a real mirrorlist, or a metalink entry */
208e85
     mirrorlist = g_key_file_get_string(priv->keyfile, repoId, "mirrorlist", NULL);
208e85
     if (mirrorlist) {
208e85
208e85
From b11ac5204dc4c7048a7b6880813f2f9b1d8eb242 Mon Sep 17 00:00:00 2001
208e85
From: Jaroslav Rohel <jrohel@redhat.com>
208e85
Date: Wed, 2 Dec 2020 13:21:35 +0100
208e85
Subject: [PATCH 6/9] [context] Fix: username, password, proxy, proxy_username,
208e85
 proxy_password
208e85
208e85
- Uses global configuration options when they are not defined
208e85
  in the repository configuration.
208e85
- proxy_username and proxy_password is urlEncoded before passing to librepo.
208e85
---
208e85
 libdnf/dnf-repo.cpp | 78 ++++++++++++++++++++++++++-------------------
208e85
 1 file changed, 46 insertions(+), 32 deletions(-)
208e85
208e85
diff --git a/libdnf/dnf-repo.cpp b/libdnf/dnf-repo.cpp
208e85
index 61d496750..005721ef6 100644
208e85
--- a/libdnf/dnf-repo.cpp
208e85
+++ b/libdnf/dnf-repo.cpp
208e85
@@ -817,18 +817,22 @@ dnf_repo_set_metadata_expire(DnfRepo *repo, guint metadata_expire)
208e85
 }
208e85
 
208e85
 /**
208e85
- * dnf_repo_get_username_password_string:
208e85
- */
208e85
-static gchar *
208e85
-dnf_repo_get_username_password_string(const gchar *user, const gchar *pass)
208e85
-{
208e85
-    if (user == NULL && pass == NULL)
208e85
-        return NULL;
208e85
-    if (user != NULL && pass == NULL)
208e85
-        return g_strdup(user);
208e85
-    if (user == NULL && pass != NULL)
208e85
-        return g_strdup_printf(":%s", pass);
208e85
-    return g_strdup_printf("%s:%s", user, pass);
208e85
+* @brief Format user password string
208e85
+*
208e85
+* Returns user and password in user:password form. If encode is True,
208e85
+* special characters in user and password are URL encoded.
208e85
+*
208e85
+* @param user Username
208e85
+* @param passwd Password
208e85
+* @param encode If quote is True, special characters in user and password are URL encoded.
208e85
+* @return User and password in user:password form
208e85
+*/
208e85
+static std::string formatUserPassString(const std::string & user, const std::string & passwd, bool encode)
208e85
+{
208e85
+    if (encode)
208e85
+        return libdnf::urlEncode(user) + ":" + libdnf::urlEncode(passwd);
208e85
+    else
208e85
+        return user + ":" + passwd;
208e85
 }
208e85
 
208e85
 static gboolean
208e85
@@ -921,11 +925,8 @@ dnf_repo_set_keyfile_data(DnfRepo *repo, GError **error)
208e85
     g_autofree gchar *mirrorlist = NULL;
208e85
     g_autofree gchar *mirrorlisturl = NULL;
208e85
     g_autofree gchar *metalinkurl = NULL;
208e85
-    g_autofree gchar *proxy = NULL;
208e85
-    g_autofree gchar *pwd = NULL;
208e85
-    g_autofree gchar *usr = NULL;
208e85
-    g_autofree gchar *usr_pwd = NULL;
208e85
-    g_autofree gchar *usr_pwd_proxy = NULL;
208e85
+    std::string tmp_str;
208e85
+    const char *tmp_cstr;
208e85
 
208e85
     auto repoId = priv->repo->getId().c_str();
208e85
     g_debug("setting keyfile data for %s", repoId);
208e85
@@ -1054,26 +1055,39 @@ dnf_repo_set_keyfile_data(DnfRepo *repo, GError **error)
208e85
         priv->exclude_packages = NULL;
208e85
     }
208e85
 
208e85
-    /* proxy is optional */
208e85
-    proxy = g_key_file_get_string(priv->keyfile, repoId, "proxy", NULL);
208e85
-    auto repoProxy = proxy ? (strcasecmp(proxy, "_none_") == 0 ? NULL : proxy)
208e85
-        : dnf_context_get_http_proxy(priv->context);
208e85
-    if (!lr_handle_setopt(priv->repo_handle, error, LRO_PROXY, repoProxy))
208e85
+    tmp_str = conf->proxy().getValue();
208e85
+    tmp_cstr = tmp_str.empty() ? dnf_context_get_http_proxy(priv->context) : tmp_str.c_str();
208e85
+    if (!lr_handle_setopt(priv->repo_handle, error, LRO_PROXY, tmp_cstr))
208e85
         return FALSE;
208e85
 
208e85
-    /* both parts of the proxy auth are optional */
208e85
-    usr = g_key_file_get_string(priv->keyfile, repoId, "proxy_username", NULL);
208e85
-    pwd = g_key_file_get_string(priv->keyfile, repoId, "proxy_password", NULL);
208e85
-    usr_pwd_proxy = dnf_repo_get_username_password_string(usr, pwd);
208e85
-    if (!lr_handle_setopt(priv->repo_handle, error, LRO_PROXYUSERPWD, usr_pwd_proxy))
208e85
+    // setup proxy username and password
208e85
+    tmp_cstr = NULL;
208e85
+    if (!conf->proxy_username().empty()) {
208e85
+        tmp_str = conf->proxy_username().getValue();
208e85
+        if (!tmp_str.empty()) {
208e85
+            if (conf->proxy_password().empty()) {
208e85
+                g_set_error(error, DNF_ERROR, DNF_ERROR_FILE_INVALID,
208e85
+                            "repo '%s': 'proxy_username' is set but not 'proxy_password'", repoId);
208e85
+                return FALSE;
208e85
+            }
208e85
+            tmp_str = formatUserPassString(tmp_str, conf->proxy_password().getValue(), true);
208e85
+            tmp_cstr = tmp_str.c_str();
208e85
+        }
208e85
+    }
208e85
+    if (!lr_handle_setopt(priv->repo_handle, error, LRO_PROXYUSERPWD, tmp_cstr))
208e85
         return FALSE;
208e85
 
208e85
-    /* both parts of the HTTP auth are optional */
208e85
-    usr = g_key_file_get_string(priv->keyfile, repoId, "username", NULL);
208e85
-    pwd = g_key_file_get_string(priv->keyfile, repoId, "password", NULL);
208e85
-    usr_pwd = dnf_repo_get_username_password_string(usr, pwd);
208e85
-    if (!lr_handle_setopt(priv->repo_handle, error, LRO_USERPWD, usr_pwd))
208e85
+    // setup username and password
208e85
+    tmp_cstr = NULL;
208e85
+    tmp_str = conf->username().getValue();
208e85
+    if (!tmp_str.empty()) {
208e85
+        // TODO Use URL encoded form, needs support in librepo
208e85
+        tmp_str = formatUserPassString(tmp_str, conf->password().getValue(), false);
208e85
+        tmp_cstr = tmp_str.c_str();
208e85
+    }
208e85
+    if (!lr_handle_setopt(priv->repo_handle, error, LRO_USERPWD, tmp_cstr))
208e85
         return FALSE;
208e85
+
208e85
     return TRUE;
208e85
 }
208e85
 
208e85
208e85
From fd07b29ccaec2648cfc050122e16e4846d7ac4be Mon Sep 17 00:00:00 2001
208e85
From: Jaroslav Rohel <jrohel@redhat.com>
208e85
Date: Wed, 2 Dec 2020 13:53:45 +0100
208e85
Subject: [PATCH 7/9] [context] Add support for options: minrate, throttle,
208e85
 bandwidth, timeout
208e85
208e85
---
208e85
 libdnf/dnf-repo.cpp | 29 +++++++++++++++++++++++++++++
208e85
 1 file changed, 29 insertions(+)
208e85
208e85
diff --git a/libdnf/dnf-repo.cpp b/libdnf/dnf-repo.cpp
208e85
index 005721ef6..c6dd027be 100644
208e85
--- a/libdnf/dnf-repo.cpp
208e85
+++ b/libdnf/dnf-repo.cpp
208e85
@@ -1055,6 +1055,35 @@ dnf_repo_set_keyfile_data(DnfRepo *repo, GError **error)
208e85
         priv->exclude_packages = NULL;
208e85
     }
208e85
 
208e85
+    auto minrate = conf->minrate().getValue();
208e85
+    if (!lr_handle_setopt(priv->repo_handle, error, LRO_LOWSPEEDLIMIT, static_cast<long>(minrate)))
208e85
+        return FALSE;
208e85
+
208e85
+    auto maxspeed = conf->throttle().getValue();
208e85
+    if (maxspeed > 0 && maxspeed <= 1)
208e85
+        maxspeed *= conf->bandwidth().getValue();
208e85
+    if (maxspeed != 0 && maxspeed < minrate) {
208e85
+        g_set_error_literal(error, DNF_ERROR, DNF_ERROR_FILE_INVALID,
208e85
+                            "Maximum download speed is lower than minimum. "
208e85
+                            "Please change configuration of minrate or throttle");
208e85
+        return FALSE;
208e85
+    }
208e85
+    if (!lr_handle_setopt(priv->repo_handle, error, LRO_MAXSPEED, static_cast<int64_t>(maxspeed)))
208e85
+        return FALSE;
208e85
+
208e85
+    long timeout = conf->timeout().getValue();
208e85
+    if (timeout > 0) {
208e85
+        if (!lr_handle_setopt(priv->repo_handle, error, LRO_CONNECTTIMEOUT, timeout))
208e85
+            return FALSE;
208e85
+        if (!lr_handle_setopt(priv->repo_handle, error, LRO_LOWSPEEDTIME, timeout))
208e85
+            return FALSE;
208e85
+    } else {
208e85
+        if (!lr_handle_setopt(priv->repo_handle, error, LRO_CONNECTTIMEOUT, LRO_CONNECTTIMEOUT_DEFAULT))
208e85
+            return FALSE;
208e85
+        if (!lr_handle_setopt(priv->repo_handle, error, LRO_LOWSPEEDTIME, LRO_LOWSPEEDTIME_DEFAULT))
208e85
+            return FALSE;
208e85
+    }
208e85
+
208e85
     tmp_str = conf->proxy().getValue();
208e85
     tmp_cstr = tmp_str.empty() ? dnf_context_get_http_proxy(priv->context) : tmp_str.c_str();
208e85
     if (!lr_handle_setopt(priv->repo_handle, error, LRO_PROXY, tmp_cstr))
208e85
208e85
From c484de218699dff834fb32133cf502b2d0c64162 Mon Sep 17 00:00:00 2001
208e85
From: Jaroslav Rohel <jrohel@redhat.com>
208e85
Date: Thu, 3 Dec 2020 10:55:02 +0100
208e85
Subject: [PATCH 8/9] [context] Remove g_key_file_get_string() from
208e85
 dnf_repo_set_keyfile_data()
208e85
208e85
Removes the remaining usage of g_key_file_get_string() from
208e85
dnf_repo_set_keyfile_data(). Use the values from ConfigRepo instead.
208e85
---
208e85
 libdnf/dnf-repo.cpp | 23 +++++++++++------------
208e85
 1 file changed, 11 insertions(+), 12 deletions(-)
208e85
208e85
diff --git a/libdnf/dnf-repo.cpp b/libdnf/dnf-repo.cpp
208e85
index c6dd027be..c5c50d55c 100644
208e85
--- a/libdnf/dnf-repo.cpp
208e85
+++ b/libdnf/dnf-repo.cpp
208e85
@@ -922,9 +922,6 @@ static gboolean
208e85
 dnf_repo_set_keyfile_data(DnfRepo *repo, GError **error)
208e85
 {
208e85
     DnfRepoPrivate *priv = GET_PRIVATE(repo);
208e85
-    g_autofree gchar *mirrorlist = NULL;
208e85
-    g_autofree gchar *mirrorlisturl = NULL;
208e85
-    g_autofree gchar *metalinkurl = NULL;
208e85
     std::string tmp_str;
208e85
     const char *tmp_cstr;
208e85
 
208e85
@@ -949,20 +946,22 @@ dnf_repo_set_keyfile_data(DnfRepo *repo, GError **error)
208e85
     if (!lr_handle_setopt(priv->repo_handle, error, LRO_URLS, baseurls))
208e85
         return FALSE;
208e85
 
208e85
+    const char *mirrorlisturl = NULL;
208e85
+    const char *metalinkurl = NULL;
208e85
+
208e85
     /* the "mirrorlist" entry could be either a real mirrorlist, or a metalink entry */
208e85
-    mirrorlist = g_key_file_get_string(priv->keyfile, repoId, "mirrorlist", NULL);
208e85
-    if (mirrorlist) {
208e85
-        if (strstr(mirrorlist, "metalink"))
208e85
-            metalinkurl = static_cast<gchar *>(g_steal_pointer(&mirrorlist));
208e85
+    tmp_cstr = conf->mirrorlist().empty() ? NULL : conf->mirrorlist().getValue().c_str();
208e85
+    if (tmp_cstr) {
208e85
+        if (strstr(tmp_cstr, "metalink"))
208e85
+            metalinkurl = tmp_cstr;
208e85
         else /* it really is a mirrorlist */
208e85
-            mirrorlisturl = static_cast<gchar *>(g_steal_pointer(&mirrorlist));
208e85
+            mirrorlisturl = tmp_cstr;
208e85
     }
208e85
 
208e85
     /* let "metalink" entry override metalink-as-mirrorlist entry */
208e85
-    if (g_key_file_has_key(priv->keyfile, repoId, "metalink", NULL)) {
208e85
-        g_free(metalinkurl);
208e85
-        metalinkurl = g_key_file_get_string(priv->keyfile, repoId, "metalink", NULL);
208e85
-    }
208e85
+    tmp_cstr = conf->metalink().empty() ? NULL : conf->metalink().getValue().c_str();
208e85
+    if (tmp_cstr)
208e85
+        metalinkurl = tmp_cstr;
208e85
 
208e85
     /* now set the final values (or unset them) */
208e85
     if (!lr_handle_setopt(priv->repo_handle, error, LRO_MIRRORLISTURL, mirrorlisturl))
208e85
208e85
From ce44d3dced4b800e3b7f80556fac1daf7e7fa49d Mon Sep 17 00:00:00 2001
208e85
From: Jaroslav Rohel <jrohel@redhat.com>
208e85
Date: Thu, 3 Dec 2020 11:43:18 +0100
208e85
Subject: [PATCH 9/9] [context] Remove the extra gpgkey member from
208e85
 DnfRepoPrivate
208e85
208e85
The value stored in ConfigRepo can be used directly.
208e85
---
208e85
 libdnf/dnf-repo.cpp | 81 ++++++++++++++++++---------------------------
208e85
 1 file changed, 33 insertions(+), 48 deletions(-)
208e85
208e85
diff --git a/libdnf/dnf-repo.cpp b/libdnf/dnf-repo.cpp
208e85
index c5c50d55c..193999902 100644
208e85
--- a/libdnf/dnf-repo.cpp
208e85
+++ b/libdnf/dnf-repo.cpp
208e85
@@ -63,7 +63,6 @@
208e85
 typedef struct
208e85
 {
208e85
     DnfRepoEnabled   enabled;
208e85
-    gchar          **gpgkeys;
208e85
     gchar          **exclude_packages;
208e85
     gchar           *filename;      /* /etc/yum.repos.d/updates.repo */
208e85
     gchar           *location;      /* /var/cache/PackageKit/metadata/fedora */
208e85
@@ -97,7 +96,6 @@ dnf_repo_finalize(GObject *object)
208e85
     DnfRepoPrivate *priv = GET_PRIVATE(repo);
208e85
 
208e85
     g_free(priv->filename);
208e85
-    g_strfreev(priv->gpgkeys);
208e85
     g_strfreev(priv->exclude_packages);
208e85
     g_free(priv->location_tmp);
208e85
     g_free(priv->location);
208e85
@@ -225,16 +223,13 @@ gchar **
208e85
 dnf_repo_get_public_keys(DnfRepo *repo)
208e85
 {
208e85
     DnfRepoPrivate *priv = GET_PRIVATE(repo);
208e85
-    g_autoptr(GPtrArray) ret = g_ptr_array_new();
208e85
-    for (char **iter = priv->gpgkeys; iter && *iter; iter++) {
208e85
-        const char *key = *iter;
208e85
-        g_autofree gchar *key_bn = g_path_get_basename(key);
208e85
-        /* transfer ownership to ptrarray */
208e85
-        g_ptr_array_add(ret, g_build_filename(priv->location, key_bn, NULL));
208e85
+    const auto & keys = priv->repo->getConfig()->gpgkey().getValue();
208e85
+    gchar **ret = g_new0(gchar *, keys.size() + 1);
208e85
+    for (size_t i = 0; i < keys.size(); ++i) {
208e85
+        g_autofree gchar *key_bn = g_path_get_basename(keys[i].c_str());
208e85
+        ret[i] = g_build_filename(priv->location, key_bn, NULL);
208e85
     }
208e85
-    g_ptr_array_add(ret, NULL);
208e85
-    /* transfer ownership of container and elements to caller */
208e85
-    return (gchar**)g_ptr_array_free(static_cast<GPtrArray *>(g_steal_pointer(&ret)), FALSE);
208e85
+    return ret;
208e85
 }
208e85
 
208e85
 /**
208e85
@@ -1014,22 +1009,9 @@ dnf_repo_set_keyfile_data(DnfRepo *repo, GError **error)
208e85
         dnf_repo_set_location_tmp(repo, tmp->str);
208e85
     }
208e85
 
208e85
-    // Sync priv->gpgkeys
208e85
-    g_strfreev(priv->gpgkeys);
208e85
-    auto & repoGpgkeys = conf->gpgkey().getValue();
208e85
-    if (!repoGpgkeys.empty()){
208e85
-        auto len = repoGpgkeys.size();
208e85
-        priv->gpgkeys = g_new0(char *, len + 1);
208e85
-        for (size_t i = 0; i < len; ++i) {
208e85
-            priv->gpgkeys[i] = g_strdup(repoGpgkeys[i].c_str());
208e85
-        }
208e85
-    } else {
208e85
-        priv->gpgkeys = NULL;
208e85
-    }
208e85
-
208e85
     /* gpgkey is optional for gpgcheck=1, but required for repo_gpgcheck=1 */
208e85
-    auto gpgcheck_md = priv->repo->getConfig()->repo_gpgcheck().getValue();
208e85
-    if (gpgcheck_md && priv->gpgkeys == NULL) {
208e85
+    auto repo_gpgcheck = conf->repo_gpgcheck().getValue();
208e85
+    if (repo_gpgcheck && conf->gpgkey().getValue().empty()) {
208e85
         g_set_error_literal(error,
208e85
                             DNF_ERROR,
208e85
                             DNF_ERROR_FILE_INVALID,
208e85
@@ -1038,7 +1020,7 @@ dnf_repo_set_keyfile_data(DnfRepo *repo, GError **error)
208e85
     }
208e85
 
208e85
     /* XXX: setopt() expects a long, so we need a long on the stack */
208e85
-    if (!lr_handle_setopt(priv->repo_handle, error, LRO_GPGCHECK, (long)gpgcheck_md))
208e85
+    if (!lr_handle_setopt(priv->repo_handle, error, LRO_GPGCHECK, (long)repo_gpgcheck))
208e85
         return FALSE;
208e85
 
208e85
     // Sync priv->exclude_packages
208e85
@@ -1750,28 +1732,31 @@ dnf_repo_update(DnfRepo *repo,
208e85
         goto out;
208e85
     }
208e85
 
208e85
-    if (priv->gpgkeys &&
208e85
-        (priv->repo->getConfig()->repo_gpgcheck().getValue() || priv->repo->getConfig()->gpgcheck().getValue())) {
208e85
-        for (char **iter = priv->gpgkeys; iter && *iter; iter++) {
208e85
-            const char *gpgkey = *iter;
208e85
-            g_autofree char *gpgkey_name = g_path_get_basename(gpgkey);
208e85
-            g_autofree char *key_tmp = g_build_filename(priv->location_tmp, gpgkey_name, NULL);
208e85
-
208e85
-            /* download and import public key */
208e85
-            if ((g_str_has_prefix(gpgkey, "https://") ||
208e85
-                  g_str_has_prefix(gpgkey, "file://"))) {
208e85
-                g_debug("importing public key %s", gpgkey);
208e85
-
208e85
-                ret = dnf_repo_download_import_public_key(repo, gpgkey, key_tmp, error);
208e85
-                if (!ret)
208e85
-                    goto out;
208e85
-            }
208e85
+    {
208e85
+        const auto & gpgkeys = priv->repo->getConfig()->gpgkey().getValue();
208e85
+        if (!gpgkeys.empty() &&
208e85
+            (priv->repo->getConfig()->repo_gpgcheck().getValue() || priv->repo->getConfig()->gpgcheck().getValue())) {
208e85
+            for (const auto & key : gpgkeys) {
208e85
+                const char *gpgkey = key.c_str();
208e85
+                g_autofree char *gpgkey_name = g_path_get_basename(gpgkey);
208e85
+                g_autofree char *key_tmp = g_build_filename(priv->location_tmp, gpgkey_name, NULL);
208e85
+
208e85
+                /* download and import public key */
208e85
+                if ((g_str_has_prefix(gpgkey, "https://") ||
208e85
+                    g_str_has_prefix(gpgkey, "file://"))) {
208e85
+                    g_debug("importing public key %s", gpgkey);
208e85
+
208e85
+                    ret = dnf_repo_download_import_public_key(repo, gpgkey, key_tmp, error);
208e85
+                    if (!ret)
208e85
+                        goto out;
208e85
+                }
208e85
 
208e85
-            /* do we autoimport this into librpm? */
208e85
-            if ((flags & DNF_REPO_UPDATE_FLAG_IMPORT_PUBKEY) > 0) {
208e85
-                ret = dnf_repo_add_public_key(repo, key_tmp, error);
208e85
-                if (!ret)
208e85
-                    goto out;
208e85
+                /* do we autoimport this into librpm? */
208e85
+                if ((flags & DNF_REPO_UPDATE_FLAG_IMPORT_PUBKEY) > 0) {
208e85
+                    ret = dnf_repo_add_public_key(repo, key_tmp, error);
208e85
+                    if (!ret)
208e85
+                        goto out;
208e85
+                }
208e85
             }
208e85
         }
208e85
     }