Move rpm-md repo status display into core

Part of: https://github.com/projectatomic/rpm-ostree/issues/774

Basically, for `rpm-ostree status` to accurately help people
understand whether or not their system is up to date, we need
to be showing repository timestamps.

Ideally, we'd change the libdnf API to support what we're doing
here better.  But, this works for now.

Closes: #791
Approved by: jlebon
This commit is contained in:
Colin Walters 2017-05-25 12:48:20 -04:00 committed by Atomic Bot
parent 2c509a768f
commit 7aba1b91dc
2 changed files with 61 additions and 33 deletions

View File

@ -372,30 +372,6 @@ install_packages_in_root (RpmOstreeTreeComposeContext *self,
if (!rpmostree_context_download_metadata (ctx, cancellable, error))
goto out;
{ GPtrArray *repos = dnf_context_get_repos (rpmostree_context_get_hif (ctx));
g_autoptr(GString) disabled = g_string_new ("");
g_print ("rpm-md repository versions:\n");
for (guint i = 0; i < repos->len; i++)
{
DnfRepo *repo = repos->pdata[i];
if (dnf_repo_get_enabled (repo) & DNF_REPO_ENABLED_PACKAGES)
{
g_autoptr(GDateTime) ts = g_date_time_new_from_unix_utc (dnf_repo_get_timestamp_generated (repo));
g_autofree char *formatted = g_date_time_format (ts, "%Y-%m-%d %T");
g_print (" %s: packages=%u generated=%s\n",
dnf_repo_get_id (repo),
dnf_repo_get_n_solvables (repo),
formatted);
}
else
{
g_string_append (disabled, dnf_repo_get_id (repo));
g_string_append_c (disabled, ' ');
}
}
g_print ("Disabled repositories: %s\n", disabled->str);
}
if (!rpmostree_context_prepare_install (ctx, &hifinstall, cancellable, error))
goto out;

View File

@ -915,18 +915,70 @@ rpmostree_context_download_metadata (RpmOstreeContext *self,
{
g_assert (!self->empty);
g_autoptr(DnfState) hifstate = dnf_state_new ();
g_autoptr(GPtrArray) rpmmd_repos = get_enabled_rpmmd_repos (self->hifctx, DNF_REPO_ENABLED_METADATA);
guint progress_sigid = g_signal_connect (hifstate, "percentage-changed",
G_CALLBACK (on_hifstate_percentage_changed),
"Downloading metadata:");
g_print ("Enabled rpm-md repositories:");
for (guint i = 0; i < rpmmd_repos->len; i++)
{
DnfRepo *repo = rpmmd_repos->pdata[i];
g_print (" %s", dnf_repo_get_id (repo));
}
g_print ("\n");
DECLARE_RPMSIGHANDLER_RESET;
if (!dnf_context_setup_sack (self->hifctx, hifstate, error))
return FALSE;
for (guint i = 0; i < rpmmd_repos->len; i++)
{
DnfRepo *repo = rpmmd_repos->pdata[i];
g_autoptr(DnfState) hifstate = dnf_state_new ();
gboolean did_update = FALSE;
if (!dnf_repo_check(repo,
dnf_context_get_cache_age (self->hifctx),
hifstate,
NULL))
{
dnf_state_reset (hifstate);
g_autofree char *prefix = g_strdup_printf ("Updating metadata for '%s':",
dnf_repo_get_id (repo));
guint progress_sigid = g_signal_connect (hifstate, "percentage-changed",
G_CALLBACK (on_hifstate_percentage_changed),
prefix);
if (!dnf_repo_update (repo, DNF_REPO_UPDATE_FLAG_FORCE, hifstate, error))
return FALSE;
did_update = TRUE;
g_signal_handler_disconnect (hifstate, progress_sigid);
rpmostree_output_percent_progress_end ();
}
guint64 ts = dnf_repo_get_timestamp_generated (repo);
g_autoptr(GDateTime) repo_ts = g_date_time_new_from_unix_utc (ts);
g_autofree char *repo_ts_str = NULL;
if (repo_ts != NULL)
repo_ts_str = g_date_time_format (repo_ts, "%Y-%m-%d %T");
else
repo_ts_str = g_strdup_printf ("(invalid timestamp)");
g_print ("rpm-md repo '%s'%s; generated: %s\n", dnf_repo_get_id (repo),
!did_update ? " (cached)" : "", repo_ts_str);
}
{ g_autoptr(DnfState) hifstate = dnf_state_new ();
guint progress_sigid = g_signal_connect (hifstate, "percentage-changed",
G_CALLBACK (on_hifstate_percentage_changed),
"Importing metadata");
/* This will check the metadata again, but it *should* hit the cache; down
* the line we should really improve the libdnf API around all of this.
*/
DECLARE_RPMSIGHANDLER_RESET;
if (!dnf_context_setup_sack (self->hifctx, hifstate, error))
return FALSE;
g_signal_handler_disconnect (hifstate, progress_sigid);
rpmostree_output_percent_progress_end ();
}
g_signal_handler_disconnect (hifstate, progress_sigid);
rpmostree_output_percent_progress_end ();
return TRUE;
}