Skip to content

Commit

Permalink
[context] Add API for distro-sync
Browse files Browse the repository at this point in the history
libdnf consumers need to be able to request a distro-sync operation.
  • Loading branch information
Conan-Kudo authored and dmach committed Apr 12, 2021
1 parent 3216d19 commit 4d1a6f5
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 4 deletions.
4 changes: 2 additions & 2 deletions VERSION.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
set (DEFAULT_LIBDNF_MAJOR_VERSION 0)
set (DEFAULT_LIBDNF_MINOR_VERSION 61)
set (DEFAULT_LIBDNF_MICRO_VERSION 1)
set (DEFAULT_LIBDNF_MINOR_VERSION 62)
set (DEFAULT_LIBDNF_MICRO_VERSION 0)

if(DEFINED LIBDNF_MAJOR_VERSION)
if(NOT ${DEFAULT_LIBDNF_MAJOR_VERSION} STREQUAL ${LIBDNF_MAJOR_VERSION})
Expand Down
4 changes: 2 additions & 2 deletions libdnf.spec
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
%global dnf_conflict 4.3.0
%global swig_version 3.0.12
%global libdnf_major_version 0
%global libdnf_minor_version 61
%global libdnf_micro_version 1
%global libdnf_minor_version 62
%global libdnf_micro_version 0

%define __cmake_in_source_build 1

Expand Down
73 changes: 73 additions & 0 deletions libdnf/dnf-context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2539,6 +2539,79 @@ dnf_context_update_all (DnfContext *context,
return TRUE;
} CATCH_TO_GERROR(FALSE)

/**
* dnf_context_distrosync:
* @context: a #DnfContext instance.
* @name: A package or group name, e.g. "firefox" or "@gnome-desktop"
* @error: A #GError or %NULL
*
* Finds an installed and remote package and marks it to be synchronized with remote version.
*
* If multiple packages are available then the newest package is synchronized to.
*
* Returns: %TRUE for success, %FALSE otherwise
*
* Since: 0.62.0
**/
gboolean
dnf_context_distrosync(DnfContext *context, const gchar *name, GError **error) try
{
DnfContextPrivate *priv = GET_PRIVATE(context);

/* create sack and add repos */
if (priv->sack == NULL) {
dnf_state_reset(priv->state);
if (!dnf_context_setup_sack(context, priv->state, error))
return FALSE;
}

g_auto(HySubject) subject = hy_subject_create(name);
g_auto(HySelector) selector = hy_subject_get_best_selector(subject, priv->sack, NULL, FALSE,
NULL);
g_autoptr(GPtrArray) selector_matches = hy_selector_matches(selector);
if (selector_matches->len == 0) {
g_set_error(error,
DNF_ERROR,
DNF_ERROR_PACKAGE_NOT_FOUND,
"No package matches '%s'", name);
return FALSE;
}

if (hy_goal_distupgrade_selector(priv->goal, selector))
return FALSE;

return TRUE;
} CATCH_TO_GERROR(FALSE)

/**
* dnf_context_distrosync_all:
* @context: a #DnfContext instance.
* @error: A #GError or %NULL
*
* Distro-sync all packages.
*
* Returns: %TRUE for success, %FALSE otherwise
*
* Since: 0.62.0
**/
gboolean
dnf_context_distrosync_all (DnfContext *context,
GError **error) try
{
DnfContextPrivate *priv = GET_PRIVATE(context);

/* create sack and add repos */
if (priv->sack == NULL) {
dnf_state_reset(priv->state);
if (!dnf_context_setup_sack(context, priv->state, error))
return FALSE;
}

/* distrosync whole solvables */
hy_goal_distupgrade_all (priv->goal);
return TRUE;
} CATCH_TO_GERROR(FALSE)

/**
* dnf_context_repo_set_data:
**/
Expand Down
5 changes: 5 additions & 0 deletions libdnf/dnf-context.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ gboolean dnf_context_update (DnfContext *context
GError **error);
gboolean dnf_context_update_all (DnfContext *context,
GError **error);
gboolean dnf_context_distrosync (DnfContext *context,
const gchar *name,
GError **error);
gboolean dnf_context_distrosync_all (DnfContext *context,
GError **error);
gboolean dnf_context_repo_enable (DnfContext *context,
const gchar *repo_id,
GError **error);
Expand Down

0 comments on commit 4d1a6f5

Please sign in to comment.