richardphibel / rpms / libdnf

Forked from rpms/libdnf 2 years ago
Clone

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

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