Skip to content

Commit 7e8f8fc

Browse files
committed
builder-manifest: Prevent writing duplicate groups to metadata file
A locale or debug extension group may already be written by `builder_extension_add_finish_args()` if the user specified them via `add-extensions` or similar manifest properties. In this case, we should not attempt to write our automatic extension groups again. These extensions should either be user supplied or the user should let flatpak-builder handle them, not both at the same time. Fixes one issue in #618
1 parent d3c4c31 commit 7e8f8fc

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/builder-manifest.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3395,8 +3395,18 @@ builder_manifest_finish (BuilderManifest *self,
33953395
g_autoptr(GFile) metadata_locale_file = NULL;
33963396
g_autofree char *metadata_contents = NULL;
33973397
g_autofree char *locale_id = builder_manifest_get_locale_id (self);
3398+
g_autoptr(GKeyFile) old_keyfile = g_key_file_new ();
3399+
g_autofree char *locale_group = NULL;
33983400

33993401
metadata_file = g_file_get_child (app_dir, "metadata");
3402+
locale_group = g_strdup_printf ("Extension %s", locale_id);
3403+
3404+
if (g_key_file_load_from_file (old_keyfile,
3405+
flatpak_file_get_path_cached (metadata_file),
3406+
G_KEY_FILE_KEEP_COMMENTS|G_KEY_FILE_KEEP_TRANSLATIONS,
3407+
NULL) &&
3408+
g_key_file_has_group (old_keyfile, locale_group))
3409+
return flatpak_fail (error, "Group '%s' already exists in metadata", locale_group);
34003410

34013411
extension_contents = g_strdup_printf ("\n"
34023412
"[Extension %s]\n"
@@ -3439,9 +3449,19 @@ builder_manifest_finish (BuilderManifest *self,
34393449
g_autofree char *extension_contents = NULL;
34403450
g_autoptr(GFileOutputStream) output = NULL;
34413451
g_autofree char *debug_id = builder_manifest_get_debug_id (self);
3452+
g_autoptr(GKeyFile) old_keyfile = g_key_file_new ();
3453+
g_autofree char *debug_group = NULL;
34423454

34433455
metadata_file = g_file_get_child (app_dir, "metadata");
34443456
metadata_debuginfo_file = g_file_get_child (app_dir, "metadata.debuginfo");
3457+
debug_group = g_strdup_printf ("Extension %s", debug_id);
3458+
3459+
if (g_key_file_load_from_file (old_keyfile,
3460+
flatpak_file_get_path_cached (metadata_file),
3461+
G_KEY_FILE_KEEP_COMMENTS|G_KEY_FILE_KEEP_TRANSLATIONS,
3462+
NULL) &&
3463+
g_key_file_has_group (old_keyfile, debug_group))
3464+
return flatpak_fail (error, "Group %s already exists in metadata", debug_group);
34453465

34463466
extension_contents = g_strdup_printf ("\n"
34473467
"[Extension %s]\n"
@@ -3896,8 +3916,18 @@ builder_manifest_finish_platform (BuilderManifest *self,
38963916
g_autoptr(GFile) metadata_locale_file = NULL;
38973917
g_autofree char *metadata_contents = NULL;
38983918
g_autofree char *locale_id = builder_manifest_get_locale_id_platform (self);
3919+
g_autoptr(GKeyFile) old_keyfile = g_key_file_new ();
3920+
g_autofree char *locale_group = NULL;
38993921

39003922
metadata_file = g_file_get_child (app_dir, "metadata.platform");
3923+
locale_group = g_strdup_printf ("Extension %s", locale_id);
3924+
3925+
if (g_key_file_load_from_file (old_keyfile,
3926+
flatpak_file_get_path_cached (metadata_file),
3927+
G_KEY_FILE_KEEP_COMMENTS|G_KEY_FILE_KEEP_TRANSLATIONS,
3928+
NULL) &&
3929+
g_key_file_has_group (old_keyfile, locale_group))
3930+
return flatpak_fail (error, "Group '%s' already exists in metadata.platform", locale_group);
39013931

39023932
extension_contents = g_strdup_printf ("\n"
39033933
"[Extension %s]\n"

0 commit comments

Comments
 (0)