mirror of
https://github.com/flatpak/flatpak.git
synced 2026-05-04 05:56:28 -04:00
Move flatpak_dir_parse_repofile to utils (and drop the unused dir)
Closes: #2884 Approved by: alexlarsson
This commit is contained in:
committed by
Atomic Bot
parent
e1ffc0e730
commit
e31023c32f
@@ -777,14 +777,6 @@ gboolean flatpak_dir_create_remote_for_ref_file (FlatpakDir *self,
|
||||
gboolean flatpak_dir_create_suggested_remote_for_ref_file (FlatpakDir *self,
|
||||
GBytes *data,
|
||||
GError **error);
|
||||
GKeyFile * flatpak_dir_parse_repofile (FlatpakDir *self,
|
||||
const char *remote_name,
|
||||
gboolean from_ref,
|
||||
GKeyFile *keyfile,
|
||||
GBytes **gpg_data_out,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
char *flatpak_dir_find_remote_by_uri (FlatpakDir *self,
|
||||
const char *uri,
|
||||
const char *collection_id);
|
||||
|
||||
@@ -11912,154 +11912,6 @@ flatpak_dir_create_origin_remote (FlatpakDir *self,
|
||||
return g_steal_pointer (&remote);
|
||||
}
|
||||
|
||||
GKeyFile *
|
||||
flatpak_dir_parse_repofile (FlatpakDir *self,
|
||||
const char *remote_name,
|
||||
gboolean from_ref,
|
||||
GKeyFile *keyfile,
|
||||
GBytes **gpg_data_out,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr(GBytes) gpg_data = NULL;
|
||||
g_autofree char *uri = NULL;
|
||||
g_autofree char *title = NULL;
|
||||
g_autofree char *gpg_key = NULL;
|
||||
g_autofree char *collection_id = NULL;
|
||||
g_autofree char *default_branch = NULL;
|
||||
g_autofree char *comment = NULL;
|
||||
g_autofree char *description = NULL;
|
||||
g_autofree char *icon = NULL;
|
||||
g_autofree char *homepage = NULL;
|
||||
g_autofree char *filter = NULL;
|
||||
gboolean nodeps;
|
||||
const char *source_group;
|
||||
g_autofree char *version = NULL;
|
||||
|
||||
if (from_ref)
|
||||
source_group = FLATPAK_REF_GROUP;
|
||||
else
|
||||
source_group = FLATPAK_REPO_GROUP;
|
||||
|
||||
GKeyFile *config = g_key_file_new ();
|
||||
g_autofree char *group = g_strdup_printf ("remote \"%s\"", remote_name);
|
||||
|
||||
if (!g_key_file_has_group (keyfile, source_group))
|
||||
{
|
||||
flatpak_fail_error (error, FLATPAK_ERROR_INVALID_DATA, _("Invalid %s: Missing group ‘%s’"),
|
||||
from_ref ? ".flatpakref" : ".flatpakrepo", source_group);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uri = g_key_file_get_string (keyfile, source_group,
|
||||
FLATPAK_REPO_URL_KEY, NULL);
|
||||
if (uri == NULL)
|
||||
{
|
||||
flatpak_fail_error (error, FLATPAK_ERROR_INVALID_DATA, _("Invalid %s: Missing key ‘%s’"),
|
||||
from_ref ? ".flatpakref" : ".flatpakrepo", FLATPAK_REPO_URL_KEY);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
version = g_key_file_get_string (keyfile, FLATPAK_REPO_GROUP,
|
||||
FLATPAK_REPO_VERSION_KEY, NULL);
|
||||
if (version != NULL && strcmp (version, "1") != 0)
|
||||
{
|
||||
flatpak_fail_error (error, FLATPAK_ERROR_INVALID_DATA,
|
||||
_("Invalid version %s, only 1 supported"), version);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_key_file_set_string (config, group, "url", uri);
|
||||
|
||||
title = g_key_file_get_locale_string (keyfile, source_group,
|
||||
FLATPAK_REPO_TITLE_KEY, NULL, NULL);
|
||||
if (title != NULL)
|
||||
g_key_file_set_string (config, group, "xa.title", title);
|
||||
|
||||
default_branch = g_key_file_get_locale_string (keyfile, source_group,
|
||||
FLATPAK_REPO_DEFAULT_BRANCH_KEY, NULL, NULL);
|
||||
if (default_branch != NULL)
|
||||
g_key_file_set_string (config, group, "xa.default-branch", default_branch);
|
||||
|
||||
nodeps = g_key_file_get_boolean (keyfile, source_group,
|
||||
FLATPAK_REPO_NODEPS_KEY, NULL);
|
||||
if (nodeps)
|
||||
g_key_file_set_boolean (config, group, "xa.nodeps", TRUE);
|
||||
|
||||
gpg_key = g_key_file_get_string (keyfile, source_group,
|
||||
FLATPAK_REPO_GPGKEY_KEY, NULL);
|
||||
if (gpg_key != NULL)
|
||||
{
|
||||
guchar *decoded;
|
||||
gsize decoded_len;
|
||||
|
||||
gpg_key = g_strstrip (gpg_key);
|
||||
decoded = g_base64_decode (gpg_key, &decoded_len);
|
||||
if (decoded_len < 10) /* Check some minimal size so we don't get crap */
|
||||
{
|
||||
flatpak_fail_error (error, FLATPAK_ERROR_INVALID_DATA, _("Invalid gpg key"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gpg_data = g_bytes_new_take (decoded, decoded_len);
|
||||
g_key_file_set_boolean (config, group, "gpg-verify", TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_key_file_set_boolean (config, group, "gpg-verify", FALSE);
|
||||
}
|
||||
|
||||
collection_id = g_key_file_get_string (keyfile, source_group,
|
||||
FLATPAK_REPO_DEPLOY_COLLECTION_ID_KEY, NULL);
|
||||
if (collection_id == NULL || *collection_id == '\0')
|
||||
collection_id = g_key_file_get_string (keyfile, source_group,
|
||||
FLATPAK_REPO_COLLECTION_ID_KEY, NULL);
|
||||
if (collection_id != NULL)
|
||||
{
|
||||
if (gpg_key == NULL)
|
||||
{
|
||||
flatpak_fail_error (error, FLATPAK_ERROR_INVALID_DATA, _("Collection ID requires GPG key to be provided"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_key_file_set_string (config, group, "collection-id", collection_id);
|
||||
}
|
||||
|
||||
/* If a collection ID is set, refs are verified from commit metadata rather
|
||||
* than the summary file. */
|
||||
g_key_file_set_boolean (config, group, "gpg-verify-summary",
|
||||
(gpg_key != NULL && collection_id == NULL));
|
||||
|
||||
comment = g_key_file_get_string (keyfile, FLATPAK_REPO_GROUP,
|
||||
FLATPAK_REPO_COMMENT_KEY, NULL);
|
||||
if (comment)
|
||||
g_key_file_set_string (config, group, "xa.comment", comment);
|
||||
|
||||
description = g_key_file_get_string (keyfile, FLATPAK_REPO_GROUP,
|
||||
FLATPAK_REPO_DESCRIPTION_KEY, NULL);
|
||||
if (description)
|
||||
g_key_file_set_string (config, group, "xa.description", description);
|
||||
|
||||
icon = g_key_file_get_string (keyfile, FLATPAK_REPO_GROUP,
|
||||
FLATPAK_REPO_ICON_KEY, NULL);
|
||||
if (icon)
|
||||
g_key_file_set_string (config, group, "xa.icon", icon);
|
||||
|
||||
homepage = g_key_file_get_string (keyfile, FLATPAK_REPO_GROUP,
|
||||
FLATPAK_REPO_HOMEPAGE_KEY, NULL);
|
||||
if (homepage)
|
||||
g_key_file_set_string (config, group, "xa.homepage", homepage);
|
||||
|
||||
filter = g_key_file_get_string (keyfile, FLATPAK_REPO_GROUP,
|
||||
FLATPAK_REPO_FILTER_KEY, NULL);
|
||||
if (filter)
|
||||
g_key_file_set_string (config, group, "xa.filter", filter);
|
||||
|
||||
*gpg_data_out = g_steal_pointer (&gpg_data);
|
||||
|
||||
return g_steal_pointer (&config);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
parse_ref_file (GKeyFile *keyfile,
|
||||
char **name_out,
|
||||
|
||||
@@ -2572,7 +2572,7 @@ handle_suggested_remote_name (FlatpakTransaction *self, GKeyFile *keyfile, GErro
|
||||
name, suggested_name, url, &res);
|
||||
if (res)
|
||||
{
|
||||
config = flatpak_dir_parse_repofile (priv->dir, suggested_name, TRUE, keyfile, &gpg_key, NULL, error);
|
||||
config = flatpak_parse_repofile (suggested_name, TRUE, keyfile, &gpg_key, NULL, error);
|
||||
if (config == NULL)
|
||||
return FALSE;
|
||||
|
||||
@@ -2655,7 +2655,7 @@ handle_runtime_repo_deps (FlatpakTransaction *self,
|
||||
}
|
||||
while (remotes != NULL && g_strv_contains ((const char * const *) remotes, new_remote));
|
||||
|
||||
config = flatpak_dir_parse_repofile (priv->dir, new_remote, FALSE, dep_keyfile, &gpg_key, NULL, error);
|
||||
config = flatpak_parse_repofile (new_remote, FALSE, dep_keyfile, &gpg_key, NULL, error);
|
||||
if (config == NULL)
|
||||
{
|
||||
g_prefix_error (error, "Can't parse dependent file %s: ", dep_url);
|
||||
|
||||
@@ -408,6 +408,13 @@ gboolean flatpak_switch_symlink_and_remove (const char *symlink_path,
|
||||
const char *target,
|
||||
GError **error);
|
||||
|
||||
GKeyFile * flatpak_parse_repofile (const char *remote_name,
|
||||
gboolean from_ref,
|
||||
GKeyFile *keyfile,
|
||||
GBytes **gpg_data_out,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
gboolean flatpak_repo_set_title (OstreeRepo *repo,
|
||||
const char *title,
|
||||
GError **error);
|
||||
|
||||
@@ -2796,6 +2796,153 @@ flatpak_summary_lookup_ref (GVariant *summary,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GKeyFile *
|
||||
flatpak_parse_repofile (const char *remote_name,
|
||||
gboolean from_ref,
|
||||
GKeyFile *keyfile,
|
||||
GBytes **gpg_data_out,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr(GBytes) gpg_data = NULL;
|
||||
g_autofree char *uri = NULL;
|
||||
g_autofree char *title = NULL;
|
||||
g_autofree char *gpg_key = NULL;
|
||||
g_autofree char *collection_id = NULL;
|
||||
g_autofree char *default_branch = NULL;
|
||||
g_autofree char *comment = NULL;
|
||||
g_autofree char *description = NULL;
|
||||
g_autofree char *icon = NULL;
|
||||
g_autofree char *homepage = NULL;
|
||||
g_autofree char *filter = NULL;
|
||||
gboolean nodeps;
|
||||
const char *source_group;
|
||||
g_autofree char *version = NULL;
|
||||
|
||||
if (from_ref)
|
||||
source_group = FLATPAK_REF_GROUP;
|
||||
else
|
||||
source_group = FLATPAK_REPO_GROUP;
|
||||
|
||||
GKeyFile *config = g_key_file_new ();
|
||||
g_autofree char *group = g_strdup_printf ("remote \"%s\"", remote_name);
|
||||
|
||||
if (!g_key_file_has_group (keyfile, source_group))
|
||||
{
|
||||
flatpak_fail_error (error, FLATPAK_ERROR_INVALID_DATA, _("Invalid %s: Missing group ‘%s’"),
|
||||
from_ref ? ".flatpakref" : ".flatpakrepo", source_group);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uri = g_key_file_get_string (keyfile, source_group,
|
||||
FLATPAK_REPO_URL_KEY, NULL);
|
||||
if (uri == NULL)
|
||||
{
|
||||
flatpak_fail_error (error, FLATPAK_ERROR_INVALID_DATA, _("Invalid %s: Missing key ‘%s’"),
|
||||
from_ref ? ".flatpakref" : ".flatpakrepo", FLATPAK_REPO_URL_KEY);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
version = g_key_file_get_string (keyfile, FLATPAK_REPO_GROUP,
|
||||
FLATPAK_REPO_VERSION_KEY, NULL);
|
||||
if (version != NULL && strcmp (version, "1") != 0)
|
||||
{
|
||||
flatpak_fail_error (error, FLATPAK_ERROR_INVALID_DATA,
|
||||
_("Invalid version %s, only 1 supported"), version);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_key_file_set_string (config, group, "url", uri);
|
||||
|
||||
title = g_key_file_get_locale_string (keyfile, source_group,
|
||||
FLATPAK_REPO_TITLE_KEY, NULL, NULL);
|
||||
if (title != NULL)
|
||||
g_key_file_set_string (config, group, "xa.title", title);
|
||||
|
||||
default_branch = g_key_file_get_locale_string (keyfile, source_group,
|
||||
FLATPAK_REPO_DEFAULT_BRANCH_KEY, NULL, NULL);
|
||||
if (default_branch != NULL)
|
||||
g_key_file_set_string (config, group, "xa.default-branch", default_branch);
|
||||
|
||||
nodeps = g_key_file_get_boolean (keyfile, source_group,
|
||||
FLATPAK_REPO_NODEPS_KEY, NULL);
|
||||
if (nodeps)
|
||||
g_key_file_set_boolean (config, group, "xa.nodeps", TRUE);
|
||||
|
||||
gpg_key = g_key_file_get_string (keyfile, source_group,
|
||||
FLATPAK_REPO_GPGKEY_KEY, NULL);
|
||||
if (gpg_key != NULL)
|
||||
{
|
||||
guchar *decoded;
|
||||
gsize decoded_len;
|
||||
|
||||
gpg_key = g_strstrip (gpg_key);
|
||||
decoded = g_base64_decode (gpg_key, &decoded_len);
|
||||
if (decoded_len < 10) /* Check some minimal size so we don't get crap */
|
||||
{
|
||||
flatpak_fail_error (error, FLATPAK_ERROR_INVALID_DATA, _("Invalid gpg key"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gpg_data = g_bytes_new_take (decoded, decoded_len);
|
||||
g_key_file_set_boolean (config, group, "gpg-verify", TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_key_file_set_boolean (config, group, "gpg-verify", FALSE);
|
||||
}
|
||||
|
||||
collection_id = g_key_file_get_string (keyfile, source_group,
|
||||
FLATPAK_REPO_DEPLOY_COLLECTION_ID_KEY, NULL);
|
||||
if (collection_id == NULL || *collection_id == '\0')
|
||||
collection_id = g_key_file_get_string (keyfile, source_group,
|
||||
FLATPAK_REPO_COLLECTION_ID_KEY, NULL);
|
||||
if (collection_id != NULL)
|
||||
{
|
||||
if (gpg_key == NULL)
|
||||
{
|
||||
flatpak_fail_error (error, FLATPAK_ERROR_INVALID_DATA, _("Collection ID requires GPG key to be provided"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_key_file_set_string (config, group, "collection-id", collection_id);
|
||||
}
|
||||
|
||||
/* If a collection ID is set, refs are verified from commit metadata rather
|
||||
* than the summary file. */
|
||||
g_key_file_set_boolean (config, group, "gpg-verify-summary",
|
||||
(gpg_key != NULL && collection_id == NULL));
|
||||
|
||||
comment = g_key_file_get_string (keyfile, FLATPAK_REPO_GROUP,
|
||||
FLATPAK_REPO_COMMENT_KEY, NULL);
|
||||
if (comment)
|
||||
g_key_file_set_string (config, group, "xa.comment", comment);
|
||||
|
||||
description = g_key_file_get_string (keyfile, FLATPAK_REPO_GROUP,
|
||||
FLATPAK_REPO_DESCRIPTION_KEY, NULL);
|
||||
if (description)
|
||||
g_key_file_set_string (config, group, "xa.description", description);
|
||||
|
||||
icon = g_key_file_get_string (keyfile, FLATPAK_REPO_GROUP,
|
||||
FLATPAK_REPO_ICON_KEY, NULL);
|
||||
if (icon)
|
||||
g_key_file_set_string (config, group, "xa.icon", icon);
|
||||
|
||||
homepage = g_key_file_get_string (keyfile, FLATPAK_REPO_GROUP,
|
||||
FLATPAK_REPO_HOMEPAGE_KEY, NULL);
|
||||
if (homepage)
|
||||
g_key_file_set_string (config, group, "xa.homepage", homepage);
|
||||
|
||||
filter = g_key_file_get_string (keyfile, FLATPAK_REPO_GROUP,
|
||||
FLATPAK_REPO_FILTER_KEY, NULL);
|
||||
if (filter)
|
||||
g_key_file_set_string (config, group, "xa.filter", filter);
|
||||
|
||||
*gpg_data_out = g_steal_pointer (&gpg_data);
|
||||
|
||||
return g_steal_pointer (&config);
|
||||
}
|
||||
|
||||
gboolean
|
||||
flatpak_repo_set_title (OstreeRepo *repo,
|
||||
const char *title,
|
||||
|
||||
Reference in New Issue
Block a user