|
rpm-build |
0fba15 |
/*
|
|
rpm-build |
0fba15 |
* Copyright © 2017 Endless Mobile, Inc.
|
|
rpm-build |
0fba15 |
*
|
|
rpm-build |
0fba15 |
* SPDX-License-Identifier: LGPL-2.0+
|
|
rpm-build |
0fba15 |
*
|
|
rpm-build |
0fba15 |
* This library is free software; you can redistribute it and/or
|
|
rpm-build |
0fba15 |
* modify it under the terms of the GNU Lesser General Public
|
|
rpm-build |
0fba15 |
* License as published by the Free Software Foundation; either
|
|
rpm-build |
0fba15 |
* version 2 of the License, or (at your option) any later version.
|
|
rpm-build |
0fba15 |
*
|
|
rpm-build |
0fba15 |
* This library is distributed in the hope that it will be useful,
|
|
rpm-build |
0fba15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
rpm-build |
0fba15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
rpm-build |
0fba15 |
* Lesser General Public License for more details.
|
|
rpm-build |
0fba15 |
*
|
|
rpm-build |
0fba15 |
* You should have received a copy of the GNU Lesser General Public
|
|
rpm-build |
0fba15 |
* License along with this library; if not, write to the
|
|
rpm-build |
0fba15 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
rpm-build |
0fba15 |
* Boston, MA 02111-1307, USA.
|
|
rpm-build |
0fba15 |
*
|
|
rpm-build |
0fba15 |
* Authors:
|
|
rpm-build |
0fba15 |
* - Philip Withnall <withnall@endlessm.com>
|
|
rpm-build |
0fba15 |
*/
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
#include "config.h"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
#include "ot-main.h"
|
|
rpm-build |
0fba15 |
#include "ot-builtins.h"
|
|
rpm-build |
0fba15 |
#include "ostree.h"
|
|
rpm-build |
0fba15 |
#include "otutil.h"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
#include "ostree-remote-private.h"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
static gchar *opt_cache_dir = NULL;
|
|
rpm-build |
0fba15 |
static gchar *opt_finders = NULL;
|
|
rpm-build |
0fba15 |
static gboolean opt_disable_fsync = FALSE;
|
|
rpm-build |
0fba15 |
static gboolean opt_pull = FALSE;
|
|
rpm-build |
0fba15 |
static gboolean opt_mirror = FALSE;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
static GOptionEntry options[] =
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
{ "cache-dir", 0, 0, G_OPTION_ARG_FILENAME, &opt_cache_dir, "Use custom cache dir", NULL },
|
|
rpm-build |
0fba15 |
{ "disable-fsync", 0, 0, G_OPTION_ARG_NONE, &opt_disable_fsync, "Do not invoke fsync()", NULL },
|
|
rpm-build |
0fba15 |
{ "finders", 0, 0, G_OPTION_ARG_STRING, &opt_finders, "Use the specified comma separated list of finders (e.g. config,lan,mount)", "FINDERS" },
|
|
rpm-build |
0fba15 |
{ "pull", 0, 0, G_OPTION_ARG_NONE, &opt_pull, "Pull the updates after finding them", NULL },
|
|
rpm-build |
0fba15 |
{ "mirror", 0, 0, G_OPTION_ARG_NONE, &opt_mirror, "Do a mirror pull (see ostree pull --mirror)", NULL},
|
|
rpm-build |
0fba15 |
{ NULL }
|
|
rpm-build |
0fba15 |
};
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
static gchar *
|
|
rpm-build |
0fba15 |
uint64_secs_to_iso8601 (guint64 secs)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_autoptr(GDateTime) dt = g_date_time_new_from_unix_utc (secs);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (dt != NULL)
|
|
rpm-build |
0fba15 |
return g_date_time_format (dt, "%FT%TZ");
|
|
rpm-build |
0fba15 |
else
|
|
rpm-build |
0fba15 |
return g_strdup ("invalid");
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
static gchar *
|
|
rpm-build |
0fba15 |
format_ref_to_checksum (GHashTable *ref_to_checksum /* (element-type OstreeCollectionRef utf8) */,
|
|
rpm-build |
0fba15 |
const gchar *line_prefix)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
GHashTableIter iter;
|
|
rpm-build |
0fba15 |
const OstreeCollectionRef *ref;
|
|
rpm-build |
0fba15 |
const gchar *checksum;
|
|
rpm-build |
0fba15 |
g_autoptr(GString) out = NULL;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
g_hash_table_iter_init (&iter, ref_to_checksum);
|
|
rpm-build |
0fba15 |
out = g_string_new ("");
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
while (g_hash_table_iter_next (&iter, (gpointer *) &ref, (gpointer *) &checksum))
|
|
rpm-build |
0fba15 |
g_string_append_printf (out, "%s - (%s, %s) = %s\n",
|
|
rpm-build |
0fba15 |
line_prefix, ref->collection_id, ref->ref_name,
|
|
rpm-build |
0fba15 |
(checksum != NULL) ? checksum : "(not found)");
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
return g_string_free (g_steal_pointer (&out), FALSE);
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
static gchar *
|
|
rpm-build |
0fba15 |
remote_get_uri (OstreeRemote *remote)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_autoptr(GError) error = NULL;
|
|
rpm-build |
0fba15 |
g_autofree gchar *uri = NULL;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
uri = g_key_file_get_string (remote->options, remote->group, "url", &error);
|
|
rpm-build |
0fba15 |
g_assert_no_error (error);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
return g_steal_pointer (&uri);
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
/* Add each key from @keys_input to @set iff its value is non-%NULL. */
|
|
rpm-build |
0fba15 |
static void
|
|
rpm-build |
0fba15 |
add_keys_to_set_if_non_null (GHashTable *set,
|
|
rpm-build |
0fba15 |
GHashTable *keys_input)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
GHashTableIter iter;
|
|
rpm-build |
0fba15 |
gpointer key, value;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
g_hash_table_iter_init (&iter, keys_input);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
while (g_hash_table_iter_next (&iter, &key, &value))
|
|
rpm-build |
0fba15 |
if (value != NULL)
|
|
rpm-build |
0fba15 |
g_hash_table_add (set, key);
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
static void
|
|
rpm-build |
0fba15 |
get_result_cb (GObject *obj,
|
|
rpm-build |
0fba15 |
GAsyncResult *result,
|
|
rpm-build |
0fba15 |
gpointer user_data)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
GAsyncResult **result_out = user_data;
|
|
rpm-build |
0fba15 |
*result_out = g_object_ref (result);
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
static void
|
|
rpm-build |
0fba15 |
collection_ref_free0 (OstreeCollectionRef *ref)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
if (ref == NULL)
|
|
rpm-build |
0fba15 |
return;
|
|
rpm-build |
0fba15 |
ostree_collection_ref_free (ref);
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
static gboolean
|
|
rpm-build |
0fba15 |
validate_finders_list (const char **finders,
|
|
rpm-build |
0fba15 |
GOptionContext *context,
|
|
rpm-build |
0fba15 |
GError **error)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
typedef struct {
|
|
rpm-build |
0fba15 |
gchar *finder_name;
|
|
rpm-build |
0fba15 |
gboolean already_used;
|
|
rpm-build |
0fba15 |
} Finder;
|
|
rpm-build |
0fba15 |
Finder valid_finders[] = {
|
|
rpm-build |
0fba15 |
{.finder_name = "config", .already_used = FALSE},
|
|
rpm-build |
0fba15 |
{.finder_name = "lan", .already_used = FALSE},
|
|
rpm-build |
0fba15 |
{.finder_name = "mount", .already_used = FALSE}
|
|
rpm-build |
0fba15 |
};
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (finders == NULL || *finders == NULL)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
ot_util_usage_error (context, "List of finders in --finders option must not be empty", error);
|
|
rpm-build |
0fba15 |
return FALSE;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
for (const char **iter = finders; iter && *iter; iter++)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
gboolean is_valid_finder = FALSE;
|
|
rpm-build |
0fba15 |
for (unsigned int i = 0; i < G_N_ELEMENTS (valid_finders); i++)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
if (valid_finders[i].already_used == TRUE)
|
|
rpm-build |
0fba15 |
continue;
|
|
rpm-build |
0fba15 |
if (g_strcmp0 (*iter, valid_finders[i].finder_name) == 0)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
is_valid_finder = TRUE;
|
|
rpm-build |
0fba15 |
valid_finders[i].already_used = TRUE;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
if (!is_valid_finder)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_autofree gchar *error_msg = NULL;
|
|
rpm-build |
0fba15 |
error_msg = g_strdup_printf ("Unknown or duplicate finder type given in --finders option: ‘%s’", *iter);
|
|
rpm-build |
0fba15 |
ot_util_usage_error (context, error_msg, error);
|
|
rpm-build |
0fba15 |
return FALSE;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
return TRUE;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
gboolean
|
|
rpm-build |
0fba15 |
ostree_builtin_find_remotes (int argc,
|
|
rpm-build |
0fba15 |
char **argv,
|
|
rpm-build |
0fba15 |
OstreeCommandInvocation *invocation,
|
|
rpm-build |
0fba15 |
GCancellable *cancellable,
|
|
rpm-build |
0fba15 |
GError **error)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_autoptr(GOptionContext) context = NULL;
|
|
rpm-build |
0fba15 |
g_autoptr(OstreeRepo) repo = NULL;
|
|
rpm-build |
0fba15 |
g_autoptr(GPtrArray) refs = NULL; /* (element-type OstreeCollectionRef) */
|
|
rpm-build |
0fba15 |
g_autoptr(GPtrArray) finders = NULL; /* (element-type OstreeRepoFinder) */
|
|
rpm-build |
0fba15 |
g_autoptr(OstreeRepoFinder) finder_config = NULL;
|
|
rpm-build |
0fba15 |
g_autoptr(OstreeRepoFinder) finder_mount = NULL;
|
|
rpm-build |
0fba15 |
#ifdef HAVE_AVAHI
|
|
rpm-build |
0fba15 |
g_autoptr(OstreeRepoFinder) finder_avahi = NULL;
|
|
rpm-build |
0fba15 |
#endif /* HAVE_AVAHI */
|
|
rpm-build |
0fba15 |
g_autoptr(OstreeAsyncProgress) progress = NULL;
|
|
rpm-build |
0fba15 |
gsize i;
|
|
rpm-build |
0fba15 |
g_autoptr(GAsyncResult) find_result = NULL, pull_result = NULL;
|
|
rpm-build |
0fba15 |
g_auto(OstreeRepoFinderResultv) results = NULL;
|
|
rpm-build |
0fba15 |
g_auto(GLnxConsoleRef) console = { 0, };
|
|
rpm-build |
0fba15 |
g_autoptr(GHashTable) refs_found = NULL; /* set (element-type OstreeCollectionRef) */
|
|
rpm-build |
0fba15 |
g_autoptr(GVariant) pull_options = NULL;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
context = g_option_context_new ("COLLECTION-ID REF [COLLECTION-ID REF...]");
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
/* Parse options. */
|
|
rpm-build |
0fba15 |
if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error))
|
|
rpm-build |
0fba15 |
return FALSE;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (!ostree_ensure_repo_writable (repo, error))
|
|
rpm-build |
0fba15 |
return FALSE;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (argc < 3)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
ot_util_usage_error (context, "At least one COLLECTION-ID REF pair must be specified", error);
|
|
rpm-build |
0fba15 |
return FALSE;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (argc % 2 == 0)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
ot_util_usage_error (context, "Only complete COLLECTION-ID REF pairs may be specified", error);
|
|
rpm-build |
0fba15 |
return FALSE;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (opt_mirror && !opt_pull)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
ot_util_usage_error (context, "When --mirror is specified, --pull must also be", error);
|
|
rpm-build |
0fba15 |
return FALSE;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (opt_disable_fsync)
|
|
rpm-build |
0fba15 |
ostree_repo_set_disable_fsync (repo, TRUE);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (opt_cache_dir &&
|
|
rpm-build |
0fba15 |
!ostree_repo_set_cache_dir (repo, AT_FDCWD, opt_cache_dir, cancellable, error))
|
|
rpm-build |
0fba15 |
return FALSE;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
/* Read in the refs to search for remotes for. */
|
|
rpm-build |
0fba15 |
refs = g_ptr_array_new_full (argc, (GDestroyNotify) collection_ref_free0);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
for (i = 1; i < argc; i += 2)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
if (!ostree_validate_collection_id (argv[i], error) ||
|
|
rpm-build |
0fba15 |
!ostree_validate_rev (argv[i + 1], error))
|
|
rpm-build |
0fba15 |
return FALSE;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
g_ptr_array_add (refs, ostree_collection_ref_new (argv[i], argv[i + 1]));
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
g_ptr_array_add (refs, NULL);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
/* Build the array of OstreeRepoFinder instances */
|
|
rpm-build |
0fba15 |
if (opt_finders != NULL)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_auto(GStrv) finders_strings = NULL;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
finders_strings = g_strsplit (opt_finders, ",", 0);
|
|
rpm-build |
0fba15 |
if (!validate_finders_list ((const char **)finders_strings, context, error))
|
|
rpm-build |
0fba15 |
return FALSE;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
finders = g_ptr_array_new_with_free_func (NULL);
|
|
rpm-build |
0fba15 |
for (const char **iter = (const char **)finders_strings; iter && *iter; iter++)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
if (g_strcmp0 (*iter, "config") == 0)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
finder_config = OSTREE_REPO_FINDER (ostree_repo_finder_config_new ());
|
|
rpm-build |
0fba15 |
g_ptr_array_add (finders, finder_config);
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
else if (g_strcmp0 (*iter, "mount") == 0)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
finder_mount = OSTREE_REPO_FINDER (ostree_repo_finder_mount_new (NULL));
|
|
rpm-build |
0fba15 |
g_ptr_array_add (finders, finder_mount);
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
else if (g_strcmp0 (*iter, "lan") == 0)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
#ifdef HAVE_AVAHI
|
|
rpm-build |
0fba15 |
GMainContext *main_context = g_main_context_get_thread_default ();
|
|
rpm-build |
0fba15 |
g_autoptr(GError) local_error = NULL;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
finder_avahi = OSTREE_REPO_FINDER (ostree_repo_finder_avahi_new (main_context));
|
|
rpm-build |
0fba15 |
ostree_repo_finder_avahi_start (OSTREE_REPO_FINDER_AVAHI (finder_avahi), &local_error);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (local_error != NULL)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_warning ("Avahi finder failed; removing it: %s", local_error->message);
|
|
rpm-build |
0fba15 |
g_clear_object (&finder_avahi);
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
else
|
|
rpm-build |
0fba15 |
g_ptr_array_add (finders, finder_avahi);
|
|
rpm-build |
0fba15 |
#else
|
|
rpm-build |
0fba15 |
ot_util_usage_error (context, "LAN repo finder requested but ostree was compiled without Avahi support", error);
|
|
rpm-build |
0fba15 |
return FALSE;
|
|
rpm-build |
0fba15 |
#endif /* HAVE_AVAHI */
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
else
|
|
rpm-build |
0fba15 |
g_assert_not_reached ();
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
g_ptr_array_add (finders, NULL);
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
/* Run the operation. */
|
|
rpm-build |
0fba15 |
glnx_console_lock (&console);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (console.is_tty)
|
|
rpm-build |
0fba15 |
progress = ostree_async_progress_new_and_connect (ostree_repo_pull_default_console_progress_changed, &console);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
ostree_repo_find_remotes_async (repo,
|
|
rpm-build |
0fba15 |
(const OstreeCollectionRef * const *) refs->pdata,
|
|
rpm-build |
0fba15 |
NULL /* no options */,
|
|
rpm-build |
0fba15 |
finders != NULL ? (OstreeRepoFinder **) finders->pdata : NULL,
|
|
rpm-build |
0fba15 |
progress, cancellable,
|
|
rpm-build |
0fba15 |
get_result_cb, &find_result);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
while (find_result == NULL)
|
|
rpm-build |
0fba15 |
g_main_context_iteration (NULL, TRUE);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
results = ostree_repo_find_remotes_finish (repo, find_result, error);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (results == NULL)
|
|
rpm-build |
0fba15 |
return FALSE;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (progress)
|
|
rpm-build |
0fba15 |
ostree_async_progress_finish (progress);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
/* Print results and work out which refs were not found. */
|
|
rpm-build |
0fba15 |
refs_found = g_hash_table_new_full (ostree_collection_ref_hash,
|
|
rpm-build |
0fba15 |
ostree_collection_ref_equal, NULL, NULL);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
for (i = 0; results[i] != NULL; i++)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_autofree gchar *uri = NULL;
|
|
rpm-build |
0fba15 |
g_autofree gchar *refs_string = NULL;
|
|
rpm-build |
0fba15 |
g_autofree gchar *last_modified_string = NULL;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
uri = remote_get_uri (results[i]->remote);
|
|
rpm-build |
0fba15 |
refs_string = format_ref_to_checksum (results[i]->ref_to_checksum, " ");
|
|
rpm-build |
0fba15 |
add_keys_to_set_if_non_null (refs_found, results[i]->ref_to_checksum);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (results[i]->summary_last_modified > 0)
|
|
rpm-build |
0fba15 |
last_modified_string = uint64_secs_to_iso8601 (results[i]->summary_last_modified);
|
|
rpm-build |
0fba15 |
else
|
|
rpm-build |
0fba15 |
last_modified_string = g_strdup ("unknown");
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
g_print ("Result %" G_GSIZE_FORMAT ": %s\n"
|
|
rpm-build |
0fba15 |
" - Finder: %s\n"
|
|
rpm-build |
0fba15 |
" - Keyring: %s\n"
|
|
rpm-build |
0fba15 |
" - Priority: %d\n"
|
|
rpm-build |
0fba15 |
" - Summary last modified: %s\n"
|
|
rpm-build |
0fba15 |
" - Refs:\n"
|
|
rpm-build |
0fba15 |
"%s\n",
|
|
rpm-build |
0fba15 |
i, uri, G_OBJECT_TYPE_NAME (results[i]->finder), results[i]->remote->keyring,
|
|
rpm-build |
0fba15 |
results[i]->priority, last_modified_string, refs_string);
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (results[0] == NULL)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_print ("No results.\n");
|
|
rpm-build |
0fba15 |
return TRUE;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
g_print ("%u/%u refs were found.\n", g_hash_table_size (refs_found), refs->len - 1);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
/* Print out the refs which weren’t found. */
|
|
rpm-build |
0fba15 |
if (g_hash_table_size (refs_found) != refs->len - 1 /* NULL terminator */)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_print ("Refs not found in any remote:\n");
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
for (i = 0; i < refs->len && refs->pdata[i] != NULL; i++)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
const OstreeCollectionRef *ref = g_ptr_array_index (refs, i);
|
|
rpm-build |
0fba15 |
if (!g_hash_table_contains (refs_found, ref))
|
|
rpm-build |
0fba15 |
g_print (" - (%s, %s)\n", ref->collection_id, ref->ref_name);
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
/* Does the user want us to pull the updates? */
|
|
rpm-build |
0fba15 |
if (!opt_pull)
|
|
rpm-build |
0fba15 |
return TRUE;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
GVariantBuilder builder;
|
|
rpm-build |
0fba15 |
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (opt_mirror)
|
|
rpm-build |
0fba15 |
g_variant_builder_add (&builder, "{s@v}", "flags",
|
|
rpm-build |
0fba15 |
g_variant_new_variant (g_variant_new_int32 (OSTREE_REPO_PULL_FLAGS_MIRROR)));
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
pull_options = g_variant_ref_sink (g_variant_builder_end (&builder));
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
/* Run the pull operation. */
|
|
rpm-build |
0fba15 |
if (console.is_tty)
|
|
rpm-build |
0fba15 |
progress = ostree_async_progress_new_and_connect (ostree_repo_pull_default_console_progress_changed, &console);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
ostree_repo_pull_from_remotes_async (repo,
|
|
rpm-build |
0fba15 |
(const OstreeRepoFinderResult * const *) results,
|
|
rpm-build |
0fba15 |
pull_options,
|
|
rpm-build |
0fba15 |
progress, cancellable,
|
|
rpm-build |
0fba15 |
get_result_cb, &pull_result);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
while (pull_result == NULL)
|
|
rpm-build |
0fba15 |
g_main_context_iteration (NULL, TRUE);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (!ostree_repo_pull_from_remotes_finish (repo, pull_result, error))
|
|
rpm-build |
0fba15 |
return FALSE;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (progress)
|
|
rpm-build |
0fba15 |
ostree_async_progress_finish (progress);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
/* The pull operation fails if any of the refs can’t be pulled. */
|
|
rpm-build |
0fba15 |
g_print ("Pulled %u/%u refs successfully.\n", refs->len - 1, refs->len - 1);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
return TRUE;
|
|
rpm-build |
0fba15 |
}
|