forked from Mirrors/flatpak-builder
flatpak_list_extensions: Break out code into helper
This is a minor restructure to make the code more readable and extensible.tingping/wmclass
parent
d6f4ea424d
commit
3122d1c014
|
@ -3764,6 +3764,90 @@ flatpak_extension_matches_reason (const char *extension_id,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
static GList *
|
||||
add_extension (GKeyFile *metakey,
|
||||
const char *group,
|
||||
const char *extension,
|
||||
const char *arch,
|
||||
const char *branch,
|
||||
GList *res)
|
||||
{
|
||||
FlatpakExtension *ext;
|
||||
g_autofree char *directory = g_key_file_get_string (metakey, group, "directory", NULL);
|
||||
g_autofree char *add_ld_path = g_key_file_get_string (metakey, group, "add-ld-path", NULL);
|
||||
g_auto(GStrv) merge_dirs = g_key_file_get_string_list (metakey, group, "merge-dirs", NULL, NULL);
|
||||
g_autofree char *enable_if = g_key_file_get_string (metakey, group, "enable-if", NULL);
|
||||
g_autofree char *subdir_suffix = g_key_file_get_string (metakey, group, "subdirectory-suffix", NULL);
|
||||
g_autofree char *ref = NULL;
|
||||
gboolean is_unmaintained = FALSE;
|
||||
g_autoptr(GFile) files = NULL;
|
||||
|
||||
if (directory == NULL)
|
||||
return res;
|
||||
|
||||
ref = g_build_filename ("runtime", extension, arch, branch, NULL);
|
||||
|
||||
files = flatpak_find_unmaintained_extension_dir_if_exists (extension, arch, branch, NULL);
|
||||
|
||||
if (files == NULL)
|
||||
files = flatpak_find_files_dir_for_ref (ref, NULL, NULL);
|
||||
else
|
||||
is_unmaintained = TRUE;
|
||||
|
||||
/* Prefer a full extension (org.freedesktop.Locale) over subdirectory ones (org.freedesktop.Locale.sv) */
|
||||
if (files != NULL)
|
||||
{
|
||||
if (flatpak_extension_matches_reason (extension, enable_if, TRUE))
|
||||
{
|
||||
ext = flatpak_extension_new (extension, extension, ref, directory, add_ld_path, subdir_suffix, merge_dirs, files, is_unmaintained);
|
||||
res = g_list_prepend (res, ext);
|
||||
}
|
||||
}
|
||||
else if (g_key_file_get_boolean (metakey, group,
|
||||
"subdirectories", NULL))
|
||||
{
|
||||
g_autofree char *prefix = g_strconcat (extension, ".", NULL);
|
||||
g_auto(GStrv) refs = NULL;
|
||||
g_auto(GStrv) unmaintained_refs = NULL;
|
||||
int j;
|
||||
|
||||
refs = flatpak_list_deployed_refs ("runtime", prefix, arch, branch,
|
||||
NULL, NULL);
|
||||
for (j = 0; refs != NULL && refs[j] != NULL; j++)
|
||||
{
|
||||
g_autofree char *extended_dir = g_build_filename (directory, refs[j] + strlen (prefix), NULL);
|
||||
g_autofree char *dir_ref = g_build_filename ("runtime", refs[j], arch, branch, NULL);
|
||||
g_autoptr(GFile) subdir_files = flatpak_find_files_dir_for_ref (dir_ref, NULL, NULL);
|
||||
|
||||
if (subdir_files && flatpak_extension_matches_reason (refs[j], enable_if, TRUE))
|
||||
{
|
||||
ext = flatpak_extension_new (extension, refs[j], dir_ref, extended_dir, add_ld_path, subdir_suffix, merge_dirs, subdir_files, FALSE);
|
||||
ext->needs_tmpfs = TRUE;
|
||||
res = g_list_prepend (res, ext);
|
||||
}
|
||||
}
|
||||
|
||||
unmaintained_refs = flatpak_list_unmaintained_refs (prefix, arch, branch,
|
||||
NULL, NULL);
|
||||
for (j = 0; unmaintained_refs != NULL && unmaintained_refs[j] != NULL; j++)
|
||||
{
|
||||
g_autofree char *extended_dir = g_build_filename (directory, unmaintained_refs[j] + strlen (prefix), NULL);
|
||||
g_autofree char *dir_ref = g_build_filename ("runtime", unmaintained_refs[j], arch, branch, NULL);
|
||||
g_autoptr(GFile) subdir_files = flatpak_find_unmaintained_extension_dir_if_exists (unmaintained_refs[j], arch, branch, NULL);
|
||||
|
||||
if (subdir_files && flatpak_extension_matches_reason (unmaintained_refs[j], enable_if, TRUE))
|
||||
{
|
||||
ext = flatpak_extension_new (extension, unmaintained_refs[j], dir_ref, extended_dir, add_ld_path, subdir_suffix, merge_dirs, subdir_files, TRUE);
|
||||
ext->needs_tmpfs = TRUE;
|
||||
res = g_list_prepend (res, ext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
GList *
|
||||
flatpak_list_extensions (GKeyFile *metakey,
|
||||
const char *arch,
|
||||
|
@ -3781,89 +3865,20 @@ flatpak_list_extensions (GKeyFile *metakey,
|
|||
groups = g_key_file_get_groups (metakey, NULL);
|
||||
for (i = 0; groups[i] != NULL; i++)
|
||||
{
|
||||
FlatpakExtension *ext;
|
||||
char *extension;
|
||||
|
||||
if (g_str_has_prefix (groups[i], "Extension ") &&
|
||||
*(extension = (groups[i] + strlen ("Extension "))) != 0)
|
||||
{
|
||||
g_autofree char *directory = g_key_file_get_string (metakey, groups[i], "directory", NULL);
|
||||
g_autofree char *version = g_key_file_get_string (metakey, groups[i], "version", NULL);
|
||||
g_autofree char *add_ld_path = g_key_file_get_string (metakey, groups[i], "add-ld-path", NULL);
|
||||
g_auto(GStrv) merge_dirs = g_key_file_get_string_list (metakey, groups[i], "merge-dirs", NULL, NULL);
|
||||
g_autofree char *enable_if = g_key_file_get_string (metakey, groups[i], "enable-if", NULL);
|
||||
g_autofree char *subdir_suffix = g_key_file_get_string (metakey, groups[i], "subdirectory-suffix", NULL);
|
||||
g_autofree char *ref = NULL;
|
||||
const char *branch;
|
||||
gboolean is_unmaintained = FALSE;
|
||||
g_autoptr(GFile) files = NULL;
|
||||
|
||||
if (directory == NULL)
|
||||
continue;
|
||||
|
||||
if (version)
|
||||
branch = version;
|
||||
else
|
||||
branch = default_branch;
|
||||
|
||||
ref = g_build_filename ("runtime", extension, arch, branch, NULL);
|
||||
|
||||
files = flatpak_find_unmaintained_extension_dir_if_exists (extension, arch, branch, NULL);
|
||||
|
||||
if (files == NULL)
|
||||
files = flatpak_find_files_dir_for_ref (ref, NULL, NULL);
|
||||
else
|
||||
is_unmaintained = TRUE;
|
||||
|
||||
/* Prefer a full extension (org.freedesktop.Locale) over subdirectory ones (org.freedesktop.Locale.sv) */
|
||||
if (files != NULL)
|
||||
{
|
||||
if (flatpak_extension_matches_reason (extension, enable_if, TRUE))
|
||||
{
|
||||
ext = flatpak_extension_new (extension, extension, ref, directory, add_ld_path, subdir_suffix, merge_dirs, files, is_unmaintained);
|
||||
res = g_list_prepend (res, ext);
|
||||
}
|
||||
}
|
||||
else if (g_key_file_get_boolean (metakey, groups[i],
|
||||
"subdirectories", NULL))
|
||||
{
|
||||
g_autofree char *prefix = g_strconcat (extension, ".", NULL);
|
||||
g_auto(GStrv) refs = NULL;
|
||||
g_auto(GStrv) unmaintained_refs = NULL;
|
||||
int j;
|
||||
|
||||
refs = flatpak_list_deployed_refs ("runtime", prefix, arch, branch,
|
||||
NULL, NULL);
|
||||
for (j = 0; refs != NULL && refs[j] != NULL; j++)
|
||||
{
|
||||
g_autofree char *extended_dir = g_build_filename (directory, refs[j] + strlen (prefix), NULL);
|
||||
g_autofree char *dir_ref = g_build_filename ("runtime", refs[j], arch, branch, NULL);
|
||||
g_autoptr(GFile) subdir_files = flatpak_find_files_dir_for_ref (dir_ref, NULL, NULL);
|
||||
|
||||
if (subdir_files && flatpak_extension_matches_reason (refs[j], enable_if, TRUE))
|
||||
{
|
||||
ext = flatpak_extension_new (extension, refs[j], dir_ref, extended_dir, add_ld_path, subdir_suffix, merge_dirs, subdir_files, FALSE);
|
||||
ext->needs_tmpfs = TRUE;
|
||||
res = g_list_prepend (res, ext);
|
||||
}
|
||||
}
|
||||
|
||||
unmaintained_refs = flatpak_list_unmaintained_refs (prefix, arch, branch,
|
||||
NULL, NULL);
|
||||
for (j = 0; unmaintained_refs != NULL && unmaintained_refs[j] != NULL; j++)
|
||||
{
|
||||
g_autofree char *extended_dir = g_build_filename (directory, unmaintained_refs[j] + strlen (prefix), NULL);
|
||||
g_autofree char *dir_ref = g_build_filename ("runtime", unmaintained_refs[j], arch, branch, NULL);
|
||||
g_autoptr(GFile) subdir_files = flatpak_find_unmaintained_extension_dir_if_exists (unmaintained_refs[j], arch, branch, NULL);
|
||||
|
||||
if (subdir_files && flatpak_extension_matches_reason (unmaintained_refs[j], enable_if, TRUE))
|
||||
{
|
||||
ext = flatpak_extension_new (extension, unmaintained_refs[j], dir_ref, extended_dir, add_ld_path, subdir_suffix, merge_dirs, subdir_files, TRUE);
|
||||
ext->needs_tmpfs = TRUE;
|
||||
res = g_list_prepend (res, ext);
|
||||
}
|
||||
}
|
||||
}
|
||||
res = add_extension (metakey, groups[i], extension, arch, branch, res);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue