Blame SOURCES/0002-modules-Add-special-handling-for-src-artifacts-RhBug-1809314.patch

7d5be8
From 71db968178e5d8cd4c01ed36fa940c2a95f3e494 Mon Sep 17 00:00:00 2001
7d5be8
From: Jaroslav Mracek <jmracek@redhat.com>
7d5be8
Date: Mon, 9 Nov 2020 18:10:37 +0100
7d5be8
Subject: [PATCH] [modules] Add special handling for src artifacts
7d5be8
 (RhBug:1809314)
7d5be8
7d5be8
Source packages are special because they cannot be installed and provide
7d5be8
nothing, therefore they should be handled by a different way than binary
7d5be8
packages. Source rpm should not trigger a removal of binary packages.
7d5be8
---
7d5be8
 libdnf/dnf-sack.cpp | 22 +++++++++++++++++++---
7d5be8
 1 file changed, 19 insertions(+), 3 deletions(-)
7d5be8
7d5be8
diff --git a/libdnf/dnf-sack.cpp b/libdnf/dnf-sack.cpp
7d5be8
index 9fd2c72d1..d44e1d86d 100644
7d5be8
--- a/libdnf/dnf-sack.cpp
7d5be8
+++ b/libdnf/dnf-sack.cpp
7d5be8
@@ -2335,20 +2335,29 @@ setModuleExcludes(DnfSack *sack, const char ** hotfixRepos,
7d5be8
 {
7d5be8
     dnf_sack_set_module_excludes(sack, nullptr);
7d5be8
     std::vector<std::string> names;
7d5be8
+    std::vector<std::string> srcNames;
7d5be8
     libdnf::DependencyContainer nameDependencies{sack};
7d5be8
     libdnf::Nevra nevra;
7d5be8
     for (const auto &rpm : includeNEVRAs) {
7d5be8
         if (nevra.parse(rpm.c_str(), HY_FORM_NEVRA)) {
7d5be8
-            names.push_back(nevra.getName());
7d5be8
-            nameDependencies.addReldep(nevra.getName().c_str());
7d5be8
+            auto arch = nevra.getArch();
7d5be8
+            // source packages do not provide anything and must not cause excluding binary packages
7d5be8
+            if (arch == "src" || arch == "nosrc") {
7d5be8
+                srcNames.push_back(nevra.getName());
7d5be8
+            } else {
7d5be8
+                names.push_back(nevra.getName());
7d5be8
+                nameDependencies.addReldep(nevra.getName().c_str());
7d5be8
+            }
7d5be8
         }
7d5be8
     }
7d5be8
 
7d5be8
     std::vector<const char *> namesCString(names.size() + 1);
7d5be8
+    std::vector<const char *> srcNamesCString(srcNames.size() + 1);
7d5be8
     std::vector<const char *> excludeNEVRAsCString(excludeNEVRAs.size() + 1);
7d5be8
     std::vector<const char *> includeNEVRAsCString(includeNEVRAs.size() + 1);
7d5be8
 
7d5be8
     transform(names.begin(), names.end(), namesCString.begin(), std::mem_fn(&std::string::c_str));
7d5be8
+    transform(srcNames.begin(), srcNames.end(), srcNamesCString.begin(), std::mem_fn(&std::string::c_str));
7d5be8
     transform(excludeNEVRAs.begin(), excludeNEVRAs.end(), excludeNEVRAsCString.begin(),
7d5be8
               std::mem_fn(&std::string::c_str));
7d5be8
     transform(includeNEVRAs.begin(), includeNEVRAs.end(), includeNEVRAsCString.begin(),
7d5be8
@@ -2363,6 +2372,7 @@ setModuleExcludes(DnfSack *sack, const char ** hotfixRepos,
7d5be8
     libdnf::Query excludeQuery{keepPackages};
7d5be8
     libdnf::Query excludeProvidesQuery{keepPackages};
7d5be8
     libdnf::Query excludeNamesQuery(keepPackages);
7d5be8
+    libdnf::Query excludeSrcNamesQuery(keepPackages);
7d5be8
     includeQuery.addFilter(HY_PKG_NEVRA_STRICT, HY_EQ, includeNEVRAsCString.data());
7d5be8
 
7d5be8
     excludeQuery.addFilter(HY_PKG_NEVRA_STRICT, HY_EQ, excludeNEVRAsCString.data());
7d5be8
@@ -2372,8 +2382,14 @@ setModuleExcludes(DnfSack *sack, const char ** hotfixRepos,
7d5be8
     excludeProvidesQuery.addFilter(HY_PKG_PROVIDES, &nameDependencies);
7d5be8
     excludeProvidesQuery.queryDifference(includeQuery);
7d5be8
 
7d5be8
-    // Requred to filtrate out source packages and packages with incompatible architectures
7d5be8
+    // Search for source packages with same names as included source artifacts
7d5be8
+    excludeSrcNamesQuery.addFilter(HY_PKG_NAME, HY_EQ, srcNamesCString.data());
7d5be8
+    const char * srcArchs[] = {"src", "nosrc", nullptr};
7d5be8
+    excludeSrcNamesQuery.addFilter(HY_PKG_ARCH, HY_EQ, srcArchs);
7d5be8
+
7d5be8
+    // Required to filtrate out source packages and packages with incompatible architectures
7d5be8
     excludeNamesQuery.addFilter(HY_PKG_NAME, HY_EQ, namesCString.data());
7d5be8
+    excludeNamesQuery.queryUnion(excludeSrcNamesQuery);
7d5be8
     excludeNamesQuery.queryDifference(includeQuery);
7d5be8
 
7d5be8
     dnf_sack_set_module_excludes(sack, excludeQuery.getResultPset());