Skip to content

Commit

Permalink
dnf-context: Modify DnfContext struct to support timeout and
Browse files Browse the repository at this point in the history
             implemented getters and setters for it
dnf-repo: Call to librepo for network wait api call

Add network-wait support by calling in API's from librepo
  • Loading branch information
RishabhSaini committed Oct 14, 2022
1 parent 8913804 commit 27dcc91
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
31 changes: 31 additions & 0 deletions libdnf/dnf-context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ typedef struct
gchar *user_agent;
gchar *arch;
guint cache_age; /*seconds*/
guint network_wait_timeout_secs;
gboolean cacheOnly{false};
gboolean check_disk_space;
gboolean check_transaction;
Expand Down Expand Up @@ -1106,6 +1107,22 @@ dnf_context_get_cache_age(DnfContext *context)
return priv->cache_age;
}

/**
* dnf_context_get_network_timeout_seconds:
* @context: a #DnfContext instance.
*
* Gets the number seconds to wait for the network timeout.
*
* Returns: network timout in seconds
*
**/
guint
dnf_context_get_network_timeout_seconds(DnfContext *context)
{
DnfContextPrivate *priv = GET_PRIVATE(context);
return priv->network_wait_timeout_secs;
}

/**
* dnf_context_get_installonly_pkgs:
* @context: a #DnfContext instance.
Expand Down Expand Up @@ -1634,6 +1651,20 @@ dnf_context_set_cache_age(DnfContext *context, guint cache_age)
priv->cache_age = cache_age;
}

/**
* dnf_context_set_network_timeout_seconds:
* @context: a #DnfContext instance.
* @seconds: Number of seconds
*
* Sets the number of seconds to wait till network timeout.
**/
void
dnf_context_set_network_timeout_seconds(DnfContext *context, guint seconds)
{
DnfContextPrivate *priv = GET_PRIVATE(context);
priv->network_wait_timeout_secs = seconds;
}

/**
* dnf_context_set_os_release:
**/
Expand Down
3 changes: 3 additions & 0 deletions libdnf/dnf-context.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ gboolean dnf_context_get_zchunk (DnfContext *context
gboolean dnf_context_get_write_history (DnfContext *context);
guint dnf_context_get_cache_age (DnfContext *context);
guint dnf_context_get_installonly_limit (DnfContext *context);
guint dnf_context_get_network_timeout_seconds(DnfContext *context);
const gchar *dnf_context_get_http_proxy (DnfContext *context);
gboolean dnf_context_get_enable_filelists (DnfContext *context);
GPtrArray *dnf_context_get_repos (DnfContext *context);
Expand Down Expand Up @@ -205,6 +206,8 @@ void dnf_context_set_write_history (DnfContext *context
gboolean value);
void dnf_context_set_cache_age (DnfContext *context,
guint cache_age);
void dnf_context_set_network_timeout_seconds(DnfContext *context,
guint seconds);

void dnf_context_set_rpm_macro (DnfContext *context,
const gchar *key,
Expand Down
8 changes: 8 additions & 0 deletions libdnf/dnf-repo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1866,6 +1866,10 @@ dnf_repo_update(DnfRepo *repo,
goto out;
}

ret = lr_handle_network_wait(priv->repo_handle, error, dnf_context_get_network_timeout_seconds(priv->context), NULL);
if(!ret)
goto out;

lr_result_clear(priv->repo_result);
dnf_state_action_start(state_local,
DNF_STATE_ACTION_DOWNLOAD_METADATA, NULL);
Expand Down Expand Up @@ -2247,6 +2251,10 @@ dnf_repo_download_packages(DnfRepo *repo,
directory_slash = g_build_filename(directory, "/", NULL);
}

ret = lr_handle_network_wait(priv->repo_handle, error, dnf_context_get_network_timeout_seconds(priv->context), NULL);
if(!ret)
goto out;

global_data.download_size = dnf_package_array_get_download_size(packages);
for (i = 0; i < packages->len; i++) {
auto pkg = static_cast<DnfPackage *>(packages->pdata[i]);
Expand Down

0 comments on commit 27dcc91

Please sign in to comment.