dcavalca / 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

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