|
|
2d633e |
From 876393d5d0cd5f806415dcdc90168e58e66da916 Mon Sep 17 00:00:00 2001
|
|
|
2d633e |
From: Jaroslav Rohel <jrohel@redhat.com>
|
|
|
2d633e |
Date: Mon, 28 Mar 2022 07:29:48 +0200
|
|
|
2d633e |
Subject: [PATCH] context: dnf_context_remove accepts `<package-spec>` as dnf,
|
|
|
2d633e |
unify code
|
|
|
2d633e |
|
|
|
2d633e |
Prior to change, the `dnf_context_remove` function only accepted
|
|
|
2d633e |
the package name (without globs). It was not possible to enter more detailed
|
|
|
2d633e |
specifications and thus, for example, select a specific version of the package
|
|
|
2d633e |
to uninstall - for example, which kernel we want to uninstall.
|
|
|
2d633e |
This patch adds full `<package-spec>` support as in dnf, including support
|
|
|
2d633e |
for globs (wildcards) and searching against 'provides' and 'file provides'.
|
|
|
2d633e |
|
|
|
2d633e |
Better error handling for `hy_goal_upgrade_selector` in` dnf_context_update`.
|
|
|
2d633e |
|
|
|
2d633e |
Unification of the function code `dnf_context_install`, `dnf_context_remove`,
|
|
|
2d633e |
`dnf_context_update`.
|
|
|
2d633e |
|
|
|
2d633e |
= changelog =
|
|
|
2d633e |
msg: context: Support <package-spec> (NEVRA forms, provides, file provides) including globs in the dnf_context_remove func
|
|
|
2d633e |
type: enhancement
|
|
|
2d633e |
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2084602
|
|
|
2d633e |
---
|
|
|
2d633e |
libdnf/dnf-context.cpp | 46 ++++++++++++++++++++++++------------------
|
|
|
2d633e |
1 file changed, 26 insertions(+), 20 deletions(-)
|
|
|
2d633e |
|
|
|
2d633e |
diff --git a/libdnf/dnf-context.cpp b/libdnf/dnf-context.cpp
|
|
|
2d633e |
index 6cb0011b..4b055f03 100644
|
|
|
2d633e |
--- a/libdnf/dnf-context.cpp
|
|
|
2d633e |
+++ b/libdnf/dnf-context.cpp
|
|
|
2d633e |
@@ -2391,10 +2391,9 @@ dnf_context_run(DnfContext *context, GCancellable *cancellable, GError **error)
|
|
|
2d633e |
* Since: 0.1.0
|
|
|
2d633e |
**/
|
|
|
2d633e |
gboolean
|
|
|
2d633e |
-dnf_context_install (DnfContext *context, const gchar *name, GError **error) try
|
|
|
2d633e |
+dnf_context_install(DnfContext *context, const gchar *name, GError **error) try
|
|
|
2d633e |
{
|
|
|
2d633e |
DnfContextPrivate *priv = GET_PRIVATE (context);
|
|
|
2d633e |
- g_autoptr(GPtrArray) selector_matches = NULL;
|
|
|
2d633e |
|
|
|
2d633e |
/* create sack and add sources */
|
|
|
2d633e |
if (priv->sack == NULL) {
|
|
|
2d633e |
@@ -2405,7 +2404,7 @@ dnf_context_install (DnfContext *context, const gchar *name, GError **error) try
|
|
|
2d633e |
|
|
|
2d633e |
g_auto(HySubject) subject = hy_subject_create(name);
|
|
|
2d633e |
g_auto(HySelector) selector = hy_subject_get_best_selector(subject, priv->sack, NULL, FALSE, NULL);
|
|
|
2d633e |
- selector_matches = hy_selector_matches(selector);
|
|
|
2d633e |
+ g_autoptr(GPtrArray) selector_matches = hy_selector_matches(selector);
|
|
|
2d633e |
if (selector_matches->len == 0) {
|
|
|
2d633e |
g_set_error(error,
|
|
|
2d633e |
DNF_ERROR,
|
|
|
2d633e |
@@ -2438,31 +2437,33 @@ gboolean
|
|
|
2d633e |
dnf_context_remove(DnfContext *context, const gchar *name, GError **error) try
|
|
|
2d633e |
{
|
|
|
2d633e |
DnfContextPrivate *priv = GET_PRIVATE(context);
|
|
|
2d633e |
- GPtrArray *pkglist;
|
|
|
2d633e |
- hy_autoquery HyQuery query = NULL;
|
|
|
2d633e |
- gboolean ret = TRUE;
|
|
|
2d633e |
- guint i;
|
|
|
2d633e |
|
|
|
2d633e |
/* create sack and add repos */
|
|
|
2d633e |
if (priv->sack == NULL) {
|
|
|
2d633e |
dnf_state_reset(priv->state);
|
|
|
2d633e |
- ret = dnf_context_setup_sack(context, priv->state, error);
|
|
|
2d633e |
- if (!ret)
|
|
|
2d633e |
+ if (!dnf_context_setup_sack(context, priv->state, error))
|
|
|
2d633e |
return FALSE;
|
|
|
2d633e |
}
|
|
|
2d633e |
|
|
|
2d633e |
- /* find installed packages to remove */
|
|
|
2d633e |
- query = hy_query_create(priv->sack);
|
|
|
2d633e |
- query->installed();
|
|
|
2d633e |
- hy_query_filter(query, HY_PKG_NAME, HY_EQ, name);
|
|
|
2d633e |
- pkglist = hy_query_run(query);
|
|
|
2d633e |
+ libdnf::Query query(priv->sack, libdnf::Query::ExcludeFlags::APPLY_EXCLUDES);
|
|
|
2d633e |
+ query.installed();
|
|
|
2d633e |
+ auto ret = query.filterSubject(name, nullptr, false, true, true, true);
|
|
|
2d633e |
+ if (!ret.first) {
|
|
|
2d633e |
+ g_set_error(error,
|
|
|
2d633e |
+ DNF_ERROR,
|
|
|
2d633e |
+ DNF_ERROR_PACKAGE_NOT_FOUND,
|
|
|
2d633e |
+ "No installed package matches '%s'", name);
|
|
|
2d633e |
+ return FALSE;
|
|
|
2d633e |
+ }
|
|
|
2d633e |
+
|
|
|
2d633e |
+ g_autoptr(GPtrArray) packages = query.run();
|
|
|
2d633e |
|
|
|
2d633e |
/* add each package */
|
|
|
2d633e |
- for (i = 0; i < pkglist->len; i++) {
|
|
|
2d633e |
- auto pkg = static_cast<DnfPackage *>(g_ptr_array_index(pkglist, i));
|
|
|
2d633e |
+ for (guint i = 0; i < packages->len; i++) {
|
|
|
2d633e |
+ auto pkg = static_cast<DnfPackage *>(g_ptr_array_index(packages, i));
|
|
|
2d633e |
hy_goal_erase(priv->goal, pkg);
|
|
|
2d633e |
}
|
|
|
2d633e |
- g_ptr_array_unref(pkglist);
|
|
|
2d633e |
+
|
|
|
2d633e |
return TRUE;
|
|
|
2d633e |
} CATCH_TO_GERROR(FALSE)
|
|
|
2d633e |
|
|
|
2d633e |
@@ -2493,8 +2494,7 @@ dnf_context_update(DnfContext *context, const gchar *name, GError **error) try
|
|
|
2d633e |
}
|
|
|
2d633e |
|
|
|
2d633e |
g_auto(HySubject) subject = hy_subject_create(name);
|
|
|
2d633e |
- g_auto(HySelector) selector = hy_subject_get_best_selector(subject, priv->sack, NULL, FALSE,
|
|
|
2d633e |
- NULL);
|
|
|
2d633e |
+ g_auto(HySelector) selector = hy_subject_get_best_selector(subject, priv->sack, NULL, FALSE, NULL);
|
|
|
2d633e |
g_autoptr(GPtrArray) selector_matches = hy_selector_matches(selector);
|
|
|
2d633e |
if (selector_matches->len == 0) {
|
|
|
2d633e |
g_set_error(error,
|
|
|
2d633e |
@@ -2504,8 +2504,14 @@ dnf_context_update(DnfContext *context, const gchar *name, GError **error) try
|
|
|
2d633e |
return FALSE;
|
|
|
2d633e |
}
|
|
|
2d633e |
|
|
|
2d633e |
- if (hy_goal_upgrade_selector(priv->goal, selector))
|
|
|
2d633e |
+ int ret = hy_goal_upgrade_selector(priv->goal, selector);
|
|
|
2d633e |
+ if (ret != 0) {
|
|
|
2d633e |
+ g_set_error(error,
|
|
|
2d633e |
+ DNF_ERROR,
|
|
|
2d633e |
+ ret,
|
|
|
2d633e |
+ "Ill-formed Selector '%s'", name);
|
|
|
2d633e |
return FALSE;
|
|
|
2d633e |
+ }
|
|
|
2d633e |
|
|
|
2d633e |
return TRUE;
|
|
|
2d633e |
} CATCH_TO_GERROR(FALSE)
|
|
|
2d633e |
--
|
|
|
2d633e |
2.36.1
|
|
|
2d633e |
|