forked from Mirrors/flatpak-builder
lib/app: Add support for repo priorities
New repos default to prio 1, bundle repos default to prio 0. Listing repos returns in sorted order, with add order as secondary sort key.tingping/wmclass
parent
22c1229ea8
commit
ea543c8f93
|
@ -39,6 +39,7 @@ static gboolean opt_do_gpg_verify;
|
|||
static gboolean opt_do_enumerate;
|
||||
static gboolean opt_no_enumerate;
|
||||
static gboolean opt_if_not_exists;
|
||||
static int opt_prio = -11;
|
||||
static char *opt_title;
|
||||
static char *opt_url;
|
||||
static char **opt_gpg_import;
|
||||
|
@ -59,6 +60,7 @@ static GOptionEntry modify_options[] = {
|
|||
static GOptionEntry common_options[] = {
|
||||
{ "no-gpg-verify", 0, 0, G_OPTION_ARG_NONE, &opt_no_gpg_verify, "Disable GPG verification", NULL },
|
||||
{ "no-enumerate", 0, 0, G_OPTION_ARG_NONE, &opt_do_enumerate, "Mark the remote as don't enumerate", NULL },
|
||||
{ "prio", 0, 0, G_OPTION_ARG_INT, &opt_prio, "Set priority (default 1, higher is more prioritized)", NULL },
|
||||
{ "title", 0, 0, G_OPTION_ARG_STRING, &opt_title, "A nice name to use for this remote", "TITLE" },
|
||||
{ "gpg-import", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &opt_gpg_import, "Import GPG key from FILE (- for stdin)", "FILE" },
|
||||
{ "gpg-key", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_gpg_import, "Optionally only import the named key(s) from the keyring files", "KEY" },
|
||||
|
@ -153,6 +155,7 @@ xdg_app_builtin_add_remote (int argc, char **argv,
|
|||
g_autofree char *remote_url = NULL;
|
||||
const char *remote_name;
|
||||
const char *url_or_path;
|
||||
g_autofree char *prio_as_string = NULL;
|
||||
|
||||
context = g_option_context_new ("NAME LOCATION - Add a remote repository");
|
||||
|
||||
|
@ -185,6 +188,14 @@ xdg_app_builtin_add_remote (int argc, char **argv,
|
|||
"xa.noenumerate",
|
||||
g_variant_new_variant (g_variant_new_boolean (TRUE)));
|
||||
|
||||
if (opt_prio != -1)
|
||||
{
|
||||
prio_as_string = g_strdup_printf ("%d", opt_prio);
|
||||
g_variant_builder_add (optbuilder, "{s@v}",
|
||||
"xa.prio",
|
||||
g_variant_new_variant (g_variant_new_string (prio_as_string)));
|
||||
}
|
||||
|
||||
if (opt_title)
|
||||
{
|
||||
g_free (title);
|
||||
|
@ -278,6 +289,12 @@ xdg_app_builtin_modify_remote (int argc, char **argv, GCancellable *cancellable,
|
|||
if (opt_do_enumerate)
|
||||
g_key_file_set_boolean (config, group, "xa.noenumerate", FALSE);
|
||||
|
||||
if (opt_prio != -1)
|
||||
{
|
||||
g_autofree char *prio_as_string = g_strdup_printf ("%d", opt_prio);
|
||||
g_key_file_set_string (config, group, "xa.prio", prio_as_string);
|
||||
}
|
||||
|
||||
if (!ostree_repo_write_config (xdg_app_dir_get_repo (dir), config, error))
|
||||
return FALSE;
|
||||
|
||||
|
|
|
@ -465,6 +465,10 @@ xdg_app_builtin_install_bundle (int argc, char **argv, GCancellable *cancellable
|
|||
"xa.noenumerate",
|
||||
g_variant_new_variant (g_variant_new_boolean (TRUE)));
|
||||
|
||||
g_variant_builder_add (optbuilder, "{s@v}",
|
||||
"xa.prio",
|
||||
g_variant_new_variant (g_variant_new_string ("0")));
|
||||
|
||||
if (!ostree_repo_remote_add (repo,
|
||||
remote, origin, g_variant_builder_end (optbuilder), cancellable, error))
|
||||
goto out;
|
||||
|
|
|
@ -93,6 +93,8 @@ xdg_app_builtin_list_remotes (int argc, char **argv, GCancellable *cancellable,
|
|||
{
|
||||
g_autofree char *remote_url = NULL;
|
||||
g_autofree char *title = NULL;
|
||||
int prio;
|
||||
g_autofree char *prio_as_string = NULL;
|
||||
gboolean gpg_verify = TRUE;
|
||||
|
||||
xdg_app_table_printer_add_column (printer, remote_name);
|
||||
|
@ -107,6 +109,10 @@ xdg_app_builtin_list_remotes (int argc, char **argv, GCancellable *cancellable,
|
|||
|
||||
xdg_app_table_printer_add_column (printer, remote_url);
|
||||
|
||||
prio = xdg_app_dir_get_remote_prio (dir, remote_name);
|
||||
prio_as_string = g_strdup_printf ("%d", prio);
|
||||
xdg_app_table_printer_add_column (printer, prio_as_string);
|
||||
|
||||
xdg_app_table_printer_add_column (printer, ""); /* Options */
|
||||
|
||||
ostree_repo_remote_get_gpg_verify (xdg_app_dir_get_repo (dir), remote_name,
|
||||
|
|
|
@ -2205,6 +2205,19 @@ xdg_app_dir_get_remote_title (XdgAppDir *self,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
xdg_app_dir_get_remote_prio (XdgAppDir *self,
|
||||
const char *remote_name)
|
||||
{
|
||||
GKeyFile *config = ostree_repo_get_config (self->repo);
|
||||
g_autofree char *group = get_group (remote_name);
|
||||
|
||||
if (config && g_key_file_has_key (config, group, "xa.prio", NULL))
|
||||
return g_key_file_get_integer (config, group, "xa.prio", NULL);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
gboolean
|
||||
xdg_app_dir_get_remote_noenumerate (XdgAppDir *self,
|
||||
const char *remote_name)
|
||||
|
@ -2218,6 +2231,23 @@ xdg_app_dir_get_remote_noenumerate (XdgAppDir *self,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
gint
|
||||
cmp_remote (gconstpointer a,
|
||||
gconstpointer b,
|
||||
gpointer user_data)
|
||||
{
|
||||
XdgAppDir *self = user_data;
|
||||
const char *a_name = *(const char **)a;
|
||||
const char *b_name = *(const char **)b;
|
||||
int prio_a, prio_b;
|
||||
|
||||
prio_a = xdg_app_dir_get_remote_prio (self, a_name);
|
||||
prio_b = xdg_app_dir_get_remote_prio (self, b_name);
|
||||
|
||||
return prio_b - prio_a;
|
||||
}
|
||||
|
||||
|
||||
char **
|
||||
xdg_app_dir_list_remotes (XdgAppDir *self,
|
||||
GCancellable *cancellable,
|
||||
|
@ -2232,6 +2262,9 @@ xdg_app_dir_list_remotes (XdgAppDir *self,
|
|||
if (res == NULL)
|
||||
res = g_new0 (char *, 1); /* Return empty array, not error */
|
||||
|
||||
g_qsort_with_data (res, g_strv_length (res), sizeof (char *),
|
||||
cmp_remote, self);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -210,6 +210,8 @@ char **xdg_app_dir_list_remotes (XdgAppDir *self,
|
|||
GError **error);
|
||||
char *xdg_app_dir_get_remote_title (XdgAppDir *self,
|
||||
const char *remote_name);
|
||||
int xdg_app_dir_get_remote_prio (XdgAppDir *self,
|
||||
const char *remote_name);
|
||||
gboolean xdg_app_dir_get_remote_noenumerate (XdgAppDir *self,
|
||||
const char *remote_name);
|
||||
gboolean xdg_app_dir_list_remote_refs (XdgAppDir *self,
|
||||
|
|
|
@ -91,6 +91,15 @@
|
|||
</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--prio=PRIO</option></term>
|
||||
|
||||
<listitem><para>
|
||||
Set the priority for the remote. Default is 1, higher is more prioritized. This is
|
||||
mainly used for graphical installation tools.
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--no-enumerate</option></term>
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
<title>Description</title>
|
||||
|
||||
<para>
|
||||
Lists the known remote repositories.
|
||||
Lists the known remote repositories, in priority order.
|
||||
</para>
|
||||
<para>
|
||||
By default, both per-user and system-wide installations
|
||||
|
|
|
@ -97,6 +97,15 @@
|
|||
</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--prio=PRIO</option></term>
|
||||
|
||||
<listitem><para>
|
||||
Set the priority for the remote. Default is 1, higher is more prioritized. This is
|
||||
mainly used for graphical installation tools.
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--no-enumerate</option></term>
|
||||
|
||||
|
|
|
@ -220,8 +220,9 @@ main (int argc, char *argv[])
|
|||
{
|
||||
XdgAppRemote *remote = g_ptr_array_index(remotes, i);
|
||||
g_autoptr(GPtrArray) refs = NULL;
|
||||
g_print ("\nRemote: %s %s %s %d %d\n",
|
||||
g_print ("\nRemote: %s %d %s %s %d %d\n",
|
||||
xdg_app_remote_get_name (remote),
|
||||
xdg_app_remote_get_prio (remote),
|
||||
xdg_app_remote_get_url (remote),
|
||||
xdg_app_remote_get_title (remote),
|
||||
xdg_app_remote_get_gpg_verify (remote),
|
||||
|
|
|
@ -502,7 +502,8 @@ xdg_app_installation_list_installed_refs_for_update (XdgAppInstallation *self,
|
|||
* @cancellable: (nullable): a #GCancellable
|
||||
* @error: return location for a #GError
|
||||
*
|
||||
* Lists the remotes.
|
||||
* Lists the remotes, in priority (highest first) order. For same priority,
|
||||
* earlier added remote comes before a later added one.
|
||||
*
|
||||
* Returns: (transfer container) (element-type XdgAppRemote): an GPtrArray of
|
||||
* #XdgAppRemote instances
|
||||
|
|
|
@ -158,6 +158,14 @@ xdg_app_remote_get_noenumerate (XdgAppRemote *self)
|
|||
return xdg_app_dir_get_remote_noenumerate (priv->dir, priv->name);
|
||||
}
|
||||
|
||||
int
|
||||
xdg_app_remote_get_prio (XdgAppRemote *self)
|
||||
{
|
||||
XdgAppRemotePrivate *priv = xdg_app_remote_get_instance_private (self);
|
||||
|
||||
return xdg_app_dir_get_remote_prio (priv->dir, priv->name);
|
||||
}
|
||||
|
||||
gboolean
|
||||
xdg_app_remote_get_gpg_verify (XdgAppRemote *self)
|
||||
{
|
||||
|
|
|
@ -53,5 +53,6 @@ XDG_APP_EXTERN char * xdg_app_remote_get_url (XdgAppRemote *self);
|
|||
XDG_APP_EXTERN char * xdg_app_remote_get_title (XdgAppRemote *self);
|
||||
XDG_APP_EXTERN gboolean xdg_app_remote_get_gpg_verify (XdgAppRemote *self);
|
||||
XDG_APP_EXTERN gboolean xdg_app_remote_get_noenumerate (XdgAppRemote *self);
|
||||
XDG_APP_EXTERN int xdg_app_remote_get_prio (XdgAppRemote *self);
|
||||
|
||||
#endif /* __XDG_APP_REMOTE_H__ */
|
||||
|
|
Loading…
Reference in New Issue