Support build-update-repo --redirect-url=

When clients install/update they will see this property in the
(signed) summary and update the url in the config, making this
essentially a permanent redirect.
tingping/wmclass
Alexander Larsson 2017-05-09 17:02:00 +02:00
parent c7f770bd7a
commit 7a4c82529e
4 changed files with 40 additions and 1 deletions

View File

@ -34,6 +34,7 @@
#include "flatpak-builtins-utils.h"
static char *opt_title;
static char *opt_redirect_url;
static char *opt_default_branch;
static char **opt_gpg_import;
static char *opt_generate_delta_from;
@ -46,6 +47,7 @@ static gboolean opt_generate_deltas;
static gint opt_prune_depth = -1;
static GOptionEntry options[] = {
{ "redirect-url", 0, 0, G_OPTION_ARG_STRING, &opt_redirect_url, N_("Redirect this repo to a new URL"), N_("URL") },
{ "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-import", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &opt_gpg_import, N_("Import new default GPG public key from FILE"), N_("FILE") },
@ -425,6 +427,10 @@ flatpak_builtin_build_update_repo (int argc, char **argv,
!flatpak_repo_set_title (repo, opt_title, error))
return FALSE;
if (opt_redirect_url &&
!flatpak_repo_set_redirect_url (repo, opt_redirect_url, error))
return FALSE;
if (opt_default_branch &&
!flatpak_repo_set_default_branch (repo, opt_default_branch, error))
return FALSE;

View File

@ -7750,6 +7750,7 @@ flatpak_dir_update_remote_configuration_for_summary (FlatpakDir *self,
"xa.title",
"xa.default-branch",
"xa.gpg-keys",
"xa.redirect-url",
NULL
};
@ -7793,7 +7794,10 @@ flatpak_dir_update_remote_configuration_for_summary (FlatpakDir *self,
const char *value = g_variant_get_string(value_var, NULL);
if (value != NULL && *value != 0)
{
g_ptr_array_add (updated_params, g_strdup (key));
if (strcmp (key, "xa.redirect-url") == 0)
g_ptr_array_add (updated_params, g_strdup ("url"));
else
g_ptr_array_add (updated_params, g_strdup (key));
g_ptr_array_add (updated_params, g_strdup (value));
}
}

View File

@ -2587,6 +2587,26 @@ flatpak_repo_set_title (OstreeRepo *repo,
return TRUE;
}
gboolean
flatpak_repo_set_redirect_url (OstreeRepo *repo,
const char *redirect_url,
GError **error)
{
g_autoptr(GKeyFile) config = NULL;
config = ostree_repo_copy_config (repo);
if (redirect_url)
g_key_file_set_string (config, "flatpak", "redirect-url", redirect_url);
else
g_key_file_remove_key (config, "flatpak", "redirect-url", NULL);
if (!ostree_repo_write_config (repo, config, error))
return FALSE;
return TRUE;
}
gboolean
flatpak_repo_set_gpg_keys (OstreeRepo *repo,
GBytes *bytes,
@ -2849,6 +2869,7 @@ flatpak_repo_update (OstreeRepo *repo,
GVariantBuilder ref_data_builder;
GKeyFile *config;
g_autofree char *title = NULL;
g_autofree char *redirect_url = NULL;
g_autofree char *default_branch = NULL;
g_autofree char *gpg_keys = NULL;
g_autoptr(GVariant) old_summary = NULL;
@ -2869,12 +2890,17 @@ flatpak_repo_update (OstreeRepo *repo,
title = g_key_file_get_string (config, "flatpak", "title", NULL);
default_branch = g_key_file_get_string (config, "flatpak", "default-branch", NULL);
gpg_keys = g_key_file_get_string (config, "flatpak", "gpg-keys", NULL);
redirect_url = g_key_file_get_string (config, "flatpak", "redirect-url", NULL);
}
if (title)
g_variant_builder_add (&builder, "{sv}", "xa.title",
g_variant_new_string (title));
if (redirect_url)
g_variant_builder_add (&builder, "{sv}", "xa.redirect-url",
g_variant_new_string (redirect_url));
if (default_branch)
g_variant_builder_add (&builder, "{sv}", "xa.default-branch",
g_variant_new_string (default_branch));

View File

@ -285,6 +285,9 @@ gint flatpak_mkstempat (int dir_fd,
gboolean flatpak_repo_set_title (OstreeRepo *repo,
const char *title,
GError **error);
gboolean flatpak_repo_set_redirect_url (OstreeRepo *repo,
const char *redirect_url,
GError **error);
gboolean flatpak_repo_set_default_branch (OstreeRepo *repo,
const char *branch,
GError **error);