find-remotes: Add pull support to the find-remotes built-in command
authorPhilip Withnall <withnall@endlessm.com>
Thu, 4 May 2017 09:47:23 +0000 (10:47 +0100)
committerAtomic Bot <atomic-devel@projectatomic.io>
Mon, 26 Jun 2017 15:56:07 +0000 (15:56 +0000)
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

src/ostree/ot-builtin-find-remotes.c

index 8130ec350f2304cae786d5d573227409997cc5ef..344febb5c1d11ffc1c21aaefdd68f96d13beb9d1 100644 (file)
 
 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;
 }