Skip to content

Commit

Permalink
dnf-context.cpp: Added network_wait seconds to struct DnfContext and …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
RishabhSaini committed Sep 6, 2022
1 parent 6529773 commit ec3a78f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 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_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:
**/
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
14 changes: 12 additions & 2 deletions libdnf/dnf-repo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1729,6 +1729,7 @@ dnf_repo_update(DnfRepo *repo,
gint64 timestamp_new = 0;
g_autoptr(GError) error_local = NULL;
RepoUpdateData updatedata = { 0, };
GCancellable *cancellable = g_cancellable_new ();

/* cannot change DVD contents */
if (priv->kind == DNF_REPO_KIND_MEDIA) {
Expand Down Expand Up @@ -1764,7 +1765,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);

Expand Down Expand Up @@ -1866,10 +1867,14 @@ dnf_repo_update(DnfRepo *repo,
goto out;
}

ret = lr_handle_network_wait(priv->repo_handle, error, dnf_context_get_network_timeout_seconds(priv->context), cancellable);
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) {
Expand Down Expand Up @@ -2222,6 +2227,7 @@ dnf_repo_download_packages(DnfRepo *repo,
GlobalDownloadData global_data = { 0, };
g_autoptr(GError) error_local = NULL;
g_autofree gchar *directory_slash = NULL;
GCancellable *cancellable = g_cancellable_new ();

/* ensure we reset the values from the keyfile */
if (!dnf_repo_set_keyfile_data(repo, TRUE, error))
Expand All @@ -2247,6 +2253,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), cancellable);
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 ec3a78f

Please sign in to comment.