diff options
author | Philip Withnall <withnall@endlessm.com> | 2017-05-04 10:47:23 +0100 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2017-06-26 15:56:07 +0000 |
commit | 37fc49f36da045348c12281878c296b2d44835f5 (patch) | |
tree | ac3777faddfb17f2c4a9da5e85bb7026a4f0213f /src/ostree/ot-builtin-find-remotes.c | |
parent | 6453203f54c429baa963cf5662313a3be030af9e (diff) | |
download | ostree-37fc49f36da045348c12281878c296b2d44835f5.tar.gz |
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
Diffstat (limited to 'src/ostree/ot-builtin-find-remotes.c')
-rw-r--r-- | src/ostree/ot-builtin-find-remotes.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/ostree/ot-builtin-find-remotes.c b/src/ostree/ot-builtin-find-remotes.c index 8130ec35..344febb5 100644 --- a/src/ostree/ot-builtin-find-remotes.c +++ b/src/ostree/ot-builtin-find-remotes.c @@ -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 can’t be pulled. */ + g_print ("Pulled %u/%u refs successfully.\n", refs->len - 1, refs->len - 1); + return TRUE; } |