Add support for disabled remotes

If this is set we don't list them by default, and we don't
automatically update apps from them.
tingping/wmclass
Alexander Larsson 2016-04-27 13:34:14 +02:00
parent 7fd926f07e
commit f37b3261d6
10 changed files with 90 additions and 0 deletions

View File

@ -39,6 +39,8 @@ static gboolean opt_do_gpg_verify;
static gboolean opt_do_enumerate;
static gboolean opt_no_enumerate;
static gboolean opt_if_not_exists;
static gboolean opt_enable;
static gboolean opt_disable;
static int opt_prio = -1;
static char *opt_title;
static char *opt_url;
@ -54,6 +56,7 @@ static GOptionEntry modify_options[] = {
{ "gpg-verify", 0, 0, G_OPTION_ARG_NONE, &opt_do_gpg_verify, "Enable GPG verification", NULL },
{ "enumerate", 0, 0, G_OPTION_ARG_NONE, &opt_do_enumerate, "Mark the remote as enumerate", NULL },
{ "url", 0, 0, G_OPTION_ARG_STRING, &opt_url, "Set a new url", NULL },
{ "enable", 0, 0, G_OPTION_ARG_NONE, &opt_enable, "Enable the remote", },
{ NULL }
};
@ -64,6 +67,7 @@ static GOptionEntry common_options[] = {
{ "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" },
{ "disable", 0, 0, G_OPTION_ARG_NONE, &opt_disable, "Disable the remote", },
{ NULL }
};
@ -200,6 +204,11 @@ xdg_app_builtin_add_remote (int argc, char **argv,
"xa.noenumerate",
g_variant_new_variant (g_variant_new_boolean (TRUE)));
if (opt_disable)
g_variant_builder_add (optbuilder, "{s@v}",
"xa.disable",
g_variant_new_variant (g_variant_new_boolean (TRUE)));
if (opt_prio != -1)
{
prio_as_string = g_strdup_printf ("%d", opt_prio);
@ -310,6 +319,11 @@ 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_disable)
g_key_file_set_boolean (config, group, "xa.disable", TRUE);
else if (opt_enable)
g_key_file_set_boolean (config, group, "xa.disable", FALSE);
if (opt_prio != -1)
{
g_autofree char *prio_as_string = g_strdup_printf ("%d", opt_prio);

View File

@ -34,11 +34,13 @@
static gboolean opt_show_details;
static gboolean opt_user;
static gboolean opt_system;
static gboolean opt_show_disabled;
static GOptionEntry options[] = {
{ "user", 0, 0, G_OPTION_ARG_NONE, &opt_user, "Show user installations", NULL },
{ "system", 0, 0, G_OPTION_ARG_NONE, &opt_system, "Show system-wide installations", NULL },
{ "show-details", 'd', 0, G_OPTION_ARG_NONE, &opt_show_details, "Show remote details", NULL },
{ "show-disabled", 0, 0, G_OPTION_ARG_NONE, &opt_show_disabled, "Show disabled remotes", NULL },
{ NULL }
};
@ -88,6 +90,11 @@ xdg_app_builtin_list_remotes (int argc, char **argv, GCancellable *cancellable,
for (i = 0; remotes[i] != NULL; i++)
{
char *remote_name = remotes[i];
gboolean disabled;
disabled = xdg_app_dir_get_remote_disabled (dir, remote_name);
if (disabled && !opt_show_disabled)
continue;
if (opt_show_details)
{
@ -119,6 +126,8 @@ xdg_app_builtin_list_remotes (int argc, char **argv, GCancellable *cancellable,
&gpg_verify, NULL);
if (!gpg_verify)
xdg_app_table_printer_append_with_comma (printer, "no-gpg-verify");
if (disabled)
xdg_app_table_printer_append_with_comma (printer, "disabled");
if (xdg_app_dir_get_remote_noenumerate (dir, remote_name))
xdg_app_table_printer_append_with_comma (printer, "no-enumerate");

View File

@ -93,6 +93,9 @@ do_update (XdgAppDir* dir,
if (repository == NULL)
return FALSE;
if (xdg_app_dir_get_remote_disabled (dir, repository))
g_print ("Not updating %s due to disabled remote %s\n", ref, repository);
subpaths = xdg_app_dir_get_subpaths (dir, ref, cancellable, error);
if (subpaths == NULL)
return FALSE;

View File

@ -3635,6 +3635,19 @@ xdg_app_dir_get_remote_noenumerate (XdgAppDir *self,
return TRUE;
}
gboolean
xdg_app_dir_get_remote_disabled (XdgAppDir *self,
const char *remote_name)
{
GKeyFile *config = ostree_repo_get_config (self->repo);
g_autofree char *group = get_group (remote_name);
if (config)
return g_key_file_get_boolean (config, group, "xa.disable", NULL);
return TRUE;
}
gint
cmp_remote (gconstpointer a,
gconstpointer b,

View File

@ -326,6 +326,8 @@ 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_get_remote_disabled (XdgAppDir *self,
const char *remote_name);
gboolean xdg_app_dir_list_remote_refs (XdgAppDir *self,
const char *remote,
GHashTable **refs,

View File

@ -118,6 +118,14 @@
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--disable</option></term>
<listitem><para>
Disable the added remote.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--title=TITLE</option></term>

View File

@ -88,6 +88,14 @@
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--show-disabled</option></term>
<listitem><para>
Show disabled repos.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-v</option></term>
<term><option>--verbose</option></term>

View File

@ -116,6 +116,22 @@
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--disable</option></term>
<listitem><para>
Disable the remote. Disabled remotes will not be automatically updated from.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--enable</option></term>
<listitem><para>
Enable the remote.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--enumerate</option></term>

View File

@ -259,6 +259,22 @@ xdg_app_remote_get_noenumerate (XdgAppRemote *self)
return xdg_app_dir_get_remote_noenumerate (priv->dir, priv->name);
}
/**
* xdg_app_remote_get_disable:
* @self: a #XdgAppRemote
*
* Returns whether this remote is disabled.
*
* Returns: whether the remote is marked as "don't enumerate"
*/
gboolean
xdg_app_remote_get_disabled (XdgAppRemote *self)
{
XdgAppRemotePrivate *priv = xdg_app_remote_get_instance_private (self);
return xdg_app_dir_get_remote_disabled (priv->dir, priv->name);
}
/**
* xdg_app_remote_get_prio:
* @self: a #XdgAppRemote

View File

@ -57,6 +57,7 @@ XDG_APP_EXTERN char * xdg_app_remote_get_url (XdgAppRemote *sel
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 gboolean xdg_app_remote_get_disabled (XdgAppRemote *self);
XDG_APP_EXTERN int xdg_app_remote_get_prio (XdgAppRemote *self);
#endif /* __XDG_APP_REMOTE_H__ */