richardphibel / rpms / libdnf

Forked from rpms/libdnf 2 years ago
Clone

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

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