Support --default-branch when updating the repository summary file

Add support for this flag in build-update-repo, so that we can define
a default branch in the server side, to be picked by the clients.

https://github.com/flatpak/flatpak/issues/221
tingping/wmclass
Mario Sanchez Prada 2016-10-11 14:16:42 +01:00
parent 69831c60ca
commit 81d1bef4a0
3 changed files with 38 additions and 1 deletions

View File

@ -33,6 +33,7 @@
#include "flatpak-utils.h"
static char *opt_title;
static char *opt_default_branch;
static char *opt_gpg_homedir;
static char **opt_gpg_key_ids;
static gboolean opt_prune;
@ -41,6 +42,7 @@ static gint opt_prune_depth = -1;
static GOptionEntry options[] = {
{ "title", 0, 0, G_OPTION_ARG_STRING, &opt_title, N_("A nice name to use for this repository"), N_("TITLE") },
{ "default-branch", 0, 0, G_OPTION_ARG_STRING, &opt_default_branch, N_("Default branch to use for this repository"), N_("BRANCH") },
{ "gpg-sign", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_gpg_key_ids, N_("GPG Key ID to sign the summary with"), N_("KEY-ID") },
{ "gpg-homedir", 0, 0, G_OPTION_ARG_STRING, &opt_gpg_homedir, N_("GPG Homedir to use when looking for keyrings"), N_("HOMEDIR") },
{ "generate-static-deltas", 0, 0, G_OPTION_ARG_NONE, &opt_generate_deltas, N_("Generate delta files"), NULL },
@ -376,6 +378,10 @@ flatpak_builtin_build_update_repo (int argc, char **argv,
!flatpak_repo_set_title (repo, opt_title, error))
return FALSE;
if (opt_default_branch &&
!flatpak_repo_set_default_branch (repo, opt_default_branch, error))
return FALSE;
g_print (_("Updating appstream branch\n"));
if (!flatpak_repo_generate_appstream (repo, (const char **) opt_gpg_key_ids, opt_gpg_homedir, cancellable, error))
return FALSE;

View File

@ -2179,6 +2179,27 @@ flatpak_repo_set_title (OstreeRepo *repo,
return TRUE;
}
gboolean
flatpak_repo_set_default_branch (OstreeRepo *repo,
const char *branch,
GError **error)
{
g_autoptr(GKeyFile) config = NULL;
config = ostree_repo_copy_config (repo);
if (branch)
g_key_file_set_string (config, "flatpak", "default-branch", branch);
else
g_key_file_remove_key (config, "flatpak", "default-branch", NULL);
if (!ostree_repo_write_config (repo, config, error))
return FALSE;
return TRUE;
}
#define OSTREE_GIO_FAST_QUERYINFO ("standard::name,standard::type,standard::size,standard::is-symlink,standard::symlink-target," \
"unix::device,unix::inode,unix::mode,unix::uid,unix::gid,unix::rdev")
@ -2299,6 +2320,7 @@ flatpak_repo_update (OstreeRepo *repo,
GVariantBuilder ref_data_builder;
GKeyFile *config;
g_autofree char *title = NULL;
g_autofree char *default_branch = NULL;
g_autoptr(GVariant) old_summary = NULL;
g_autoptr(GHashTable) refs = NULL;
const char *prefixes[] = { "appstream", "app", "runtime", NULL };
@ -2312,12 +2334,18 @@ flatpak_repo_update (OstreeRepo *repo,
config = ostree_repo_get_config (repo);
if (config)
title = g_key_file_get_string (config, "flatpak", "title", NULL);
{
title = g_key_file_get_string (config, "flatpak", "title", NULL);
default_branch = g_key_file_get_string (config, "flatpak", "default-branch", NULL);
}
if (title)
g_variant_builder_add (&builder, "{sv}", "xa.title",
g_variant_new_string (title));
if (default_branch)
g_variant_builder_add (&builder, "{sv}", "xa.default-branch",
g_variant_new_string (default_branch));
g_variant_builder_init (&ref_data_builder, G_VARIANT_TYPE ("a{s(tts)}"));

View File

@ -229,6 +229,9 @@ void flatpak_table_printer_print (FlatpakTablePrinter *printer);
gboolean flatpak_repo_set_title (OstreeRepo *repo,
const char *title,
GError **error);
gboolean flatpak_repo_set_default_branch (OstreeRepo *repo,
const char *branch,
GError **error);
gboolean flatpak_repo_update (OstreeRepo *repo,
const char **gpg_key_ids,
const char *gpg_homedir,