Blame SOURCES/0001-Better-msgs-if-basecachedir-or-proxy-password-isn-t-set-RhBug-1888946.patch

504788
From 2353dfbcb49a16bd37115915517417678fe49b19 Mon Sep 17 00:00:00 2001
504788
From: Jaroslav Rohel <jrohel@redhat.com>
504788
Date: Fri, 13 Nov 2020 09:55:23 +0100
504788
Subject: [PATCH] Better msgs if "basecachedir" or "proxy_password" isn't set
504788
 (RhBug:1888946)
504788
504788
Generates more specific error messages:
504788
- repo '%s': 'basecachedir' is not set
504788
- repo '%s': 'proxy_username' is set but not 'proxy_password'
504788
- 'proxy_username' is set but not 'proxy_password'
504788
instead of generic "GetValue(): Value not set"
504788
---
504788
 libdnf/repo/Repo.cpp | 24 ++++++++++++++++++++++--
504788
 1 file changed, 22 insertions(+), 2 deletions(-)
504788
504788
diff --git a/libdnf/repo/Repo.cpp b/libdnf/repo/Repo.cpp
504788
index d7c137d75..34539e1ee 100644
504788
--- a/libdnf/repo/Repo.cpp
504788
+++ b/libdnf/repo/Repo.cpp
504788
@@ -484,8 +484,12 @@ std::unique_ptr<LrHandle> Repo::Impl::lrHandleInitLocal()
504788
     handleSetOpt(h.get(), LRO_LOCAL, 1L);
504788
 #ifdef LRO_SUPPORTS_CACHEDIR
504788
     /* If zchunk is enabled, set librepo cache dir */
504788
-    if (conf->getMasterConfig().zchunk().getValue())
504788
+    if (conf->getMasterConfig().zchunk().getValue()) {
504788
+        if (conf->basecachedir().empty()) {
504788
+            throw Exception(tfm::format(_("repo '%s': 'basecachedir' is not set"), id));
504788
+        }
504788
         handleSetOpt(h.get(), LRO_CACHEDIR, conf->basecachedir().getValue().c_str());
504788
+    }
504788
 #endif
504788
     return h;
504788
 }
504788
@@ -526,6 +530,9 @@ std::unique_ptr<LrHandle> Repo::Impl::lrHandleInitRemote(const char *destdir)
504788
                 handleSetOpt(h.get(), LRO_METALINKURL, tmp.c_str());
504788
         }
504788
         handleSetOpt(h.get(), LRO_FASTESTMIRROR, conf->fastestmirror().getValue() ? 1L : 0L);
504788
+        if (conf->basecachedir().empty()) {
504788
+            throw Exception(tfm::format(_("repo '%s': 'basecachedir' is not set"), id));
504788
+        }
504788
         auto fastestMirrorCacheDir = conf->basecachedir().getValue();
504788
         if (fastestMirrorCacheDir.back() != '/')
504788
             fastestMirrorCacheDir.push_back('/');
504788
@@ -569,8 +576,12 @@ std::unique_ptr<LrHandle> Repo::Impl::lrHandleInitRemote(const char *destdir)
504788
 
504788
 #ifdef LRO_SUPPORTS_CACHEDIR
504788
     /* If zchunk is enabled, set librepo cache dir */
504788
-    if (conf->getMasterConfig().zchunk().getValue())
504788
+    if (conf->getMasterConfig().zchunk().getValue()) {
504788
+        if (conf->basecachedir().empty()) {
504788
+            throw Exception(tfm::format(_("repo '%s': 'basecachedir' is not set"), id));
504788
+        }
504788
         handleSetOpt(h.get(), LRO_CACHEDIR, conf->basecachedir().getValue().c_str());
504788
+    }
504788
 #endif
504788
 
504788
     auto minrate = conf->minrate().getValue();
504788
@@ -610,6 +621,9 @@ std::unique_ptr<LrHandle> Repo::Impl::lrHandleInitRemote(const char *destdir)
504788
     if (!conf->proxy_username().empty()) {
504788
         userpwd = conf->proxy_username().getValue();
504788
         if (!userpwd.empty()) {
504788
+            if (conf->proxy_password().empty()) {
504788
+                throw RepoError(tfm::format(_("repo '%s': 'proxy_username' is set but not 'proxy_password'"), id));
504788
+            }
504788
             userpwd = formatUserPassString(userpwd, conf->proxy_password().getValue(), true);
504788
             handleSetOpt(h.get(), LRO_PROXYUSERPWD, userpwd.c_str());
504788
         }
504788
@@ -1346,6 +1360,9 @@ std::string Repo::Impl::getHash() const
504788
 
504788
 std::string Repo::Impl::getCachedir() const
504788
 {
504788
+    if (conf->basecachedir().empty()) {
504788
+        throw Exception(tfm::format(_("repo '%s': 'basecachedir' is not set"), id));
504788
+    }
504788
     auto repodir(conf->basecachedir().getValue());
504788
     if (repodir.back() != '/')
504788
         repodir.push_back('/');
504788
@@ -1690,6 +1707,9 @@ static LrHandle * newHandle(ConfigMain * conf)
504788
         if (!conf->proxy_username().empty()) {
504788
             auto userpwd = conf->proxy_username().getValue();
504788
             if (!userpwd.empty()) {
504788
+                if (conf->proxy_password().empty()) {
504788
+                    throw RepoError(_("'proxy_username' is set but not 'proxy_password'"));
504788
+                }
504788
                 userpwd = formatUserPassString(userpwd, conf->proxy_password().getValue(), true);
504788
                 handleSetOpt(h, LRO_PROXYUSERPWD, userpwd.c_str());
504788
             }