find-remotes: Add pull support to the find-remotes built-in command

This will pull the remotes after finding them. This potentially needs to
go in its own pull-from-remotes built-in command, but it will be fine
here for now.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #924
Approved by: cgwalters
This commit is contained in:
Philip Withnall 2017-05-04 10:47:23 +01:00 committed by Atomic Bot
parent 6453203f54
commit 37fc49f36d

View File

@ -32,11 +32,13 @@
static gchar *opt_cache_dir = NULL;
static gboolean opt_disable_fsync = FALSE;
static gboolean opt_pull = FALSE;
static GOptionEntry options[] =
{
{ "cache-dir", 0, 0, G_OPTION_ARG_FILENAME, &opt_cache_dir, "Use custom cache dir", NULL },
{ "disable-fsync", 0, 0, G_OPTION_ARG_NONE, &opt_disable_fsync, "Do not invoke fsync()", NULL },
{ "pull", 0, 0, G_OPTION_ARG_NONE, &opt_pull, "Pull the updates after finding them", NULL },
{ NULL }
};
@ -127,7 +129,7 @@ ostree_builtin_find_remotes (int argc,
g_autoptr(GPtrArray) refs = NULL; /* (element-type OstreeCollectionRef) */
glnx_unref_object OstreeAsyncProgress *progress = NULL;
gsize i;
g_autoptr(GAsyncResult) find_result = NULL;
g_autoptr(GAsyncResult) find_result = NULL, pull_result = NULL;
g_auto(OstreeRepoFinderResultv) results = NULL;
g_auto(GLnxConsoleRef) console = { 0, };
g_autoptr(GHashTable) refs_found = NULL; /* set (element-type OstreeCollectionRef) */
@ -251,5 +253,31 @@ ostree_builtin_find_remotes (int argc,
}
}
/* Does the user want us to pull the updates? */
if (!opt_pull)
return TRUE;
/* Run the pull operation. */
if (console.is_tty)
progress = ostree_async_progress_new_and_connect (ostree_repo_pull_default_console_progress_changed, &console);
ostree_repo_pull_from_remotes_async (repo,
(const OstreeRepoFinderResult * const *) results,
NULL, /* no options */
progress, cancellable,
get_result_cb, &pull_result);
while (pull_result == NULL)
g_main_context_iteration (NULL, TRUE);
if (!ostree_repo_pull_from_remotes_finish (repo, pull_result, error))
return FALSE;
if (progress)
ostree_async_progress_finish (progress);
/* The pull operation fails if any of the refs cant be pulled. */
g_print ("Pulled %u/%u refs successfully.\n", refs->len - 1, refs->len - 1);
return TRUE;
}