From 84dc94f8a5c088f8155eb15fe198f4a6c4d497e9 Mon Sep 17 00:00:00 2001 From: RishabhSaini Date: Tue, 23 Aug 2022 17:03:49 -0400 Subject: [PATCH] dnf-context.cpp: Added network_wait seconds to struct DnfContext and implemented getters and setters for it dnf-repo.cpp: Call to librepo for network wait api call Adding network wait support by callin in API's from librepo --- libdnf/dnf-context.cpp | 31 +++++++++++++++++++++++++++++++ libdnf/dnf-context.h | 3 +++ libdnf/dnf-repo.cpp | 14 ++++++++++++-- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/libdnf/dnf-context.cpp b/libdnf/dnf-context.cpp index 97d1c59945..ea2e0d7a90 100644 --- a/libdnf/dnf-context.cpp +++ b/libdnf/dnf-context.cpp @@ -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; @@ -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. @@ -1634,6 +1651,20 @@ dnf_context_set_cache_age(DnfContext *context, guint cache_age) priv->cache_age = cache_age; } +/** + * dnf_context_set_cache_age: + * @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: **/ diff --git a/libdnf/dnf-context.h b/libdnf/dnf-context.h index cb00a29bdd..d3a21c4b88 100644 --- a/libdnf/dnf-context.h +++ b/libdnf/dnf-context.h @@ -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); @@ -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, diff --git a/libdnf/dnf-repo.cpp b/libdnf/dnf-repo.cpp index 48434fd9be..18c97a05a0 100644 --- a/libdnf/dnf-repo.cpp +++ b/libdnf/dnf-repo.cpp @@ -1764,7 +1764,7 @@ dnf_repo_update(DnfRepo *repo, /* ensure we set the values from the keyfile */ if (!dnf_repo_set_keyfile_data(repo, TRUE, error)) return FALSE; - + /* countme support */ libdnf::repoGetImpl(priv->repo)->addCountmeFlag(priv->repo_handle); @@ -1866,10 +1866,14 @@ dnf_repo_update(DnfRepo *repo, goto out; } + ret = lr_handle_setopt(priv->repo_handle, error, LRO_NETWORK_WAIT, dnf_context_get_network_timeout_seconds(priv->context)); + if(!ret) + goto out; + lr_result_clear(priv->repo_result); dnf_state_action_start(state_local, DNF_STATE_ACTION_DOWNLOAD_METADATA, NULL); - ret = lr_handle_perform(priv->repo_handle, + ret = lr_handle_perform(priv->repo_handle, priv->repo_result, &error_local); if (!ret) { @@ -2247,6 +2251,12 @@ dnf_repo_download_packages(DnfRepo *repo, directory_slash = g_build_filename(directory, "/", NULL); } + ret = lr_handle_setopt(priv->repo_handle, error, + LRO_NETWORK_WAIT, dnf_context_get_network_timeout_seconds(priv->context)); + + 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(packages->pdata[i]);