extensions: Support enable/install-if=active-gl-driver

Only use/download this extension if it matches an active gl driver.
This commit is contained in:
Alexander Larsson 2017-02-02 15:51:19 +01:00
parent d4d15c7211
commit 2e453048e0
3 changed files with 60 additions and 14 deletions

View File

@ -7398,6 +7398,7 @@ add_related (FlatpakDir *self,
const char *extension_ref,
const char *checksum,
gboolean no_autodownload,
const char *download_if,
gboolean autodelete)
{
g_autoptr(GVariant) deploy_data = NULL;
@ -7405,19 +7406,20 @@ add_related (FlatpakDir *self,
g_autoptr(GPtrArray) subpaths = g_ptr_array_new_with_free_func (g_free);
int i;
FlatpakRelated *rel;
gboolean download = TRUE;
gboolean download;
gboolean delete = autodelete;
g_auto(GStrv) ref_parts = g_strsplit (extension_ref, "/", -1);
deploy_data = flatpak_dir_get_deploy_data (self, extension_ref, NULL, NULL);
if (deploy_data)
old_subpaths = flatpak_deploy_data_get_subpaths (deploy_data);
/* Only apply no-autodownload for uninstalled refs, we want to update
if you manually installed them */
if (no_autodownload && deploy_data == NULL)
download = FALSE;
/* Only respect no-autodownload/download-if for uninstalled refs, we
always want to update if you manually installed something */
download =
flatpak_extension_matches_reason (ref_parts[1], download_if, !no_autodownload) ||
deploy_data != NULL;
if (g_str_has_suffix (extension, ".Debug"))
{
@ -7523,6 +7525,8 @@ flatpak_dir_find_remote_related (FlatpakDir *self,
"subdirectories", NULL);
gboolean no_autodownload = g_key_file_get_boolean (metakey, groups[i],
"no-autodownload", NULL);
g_autofree char *download_if = g_key_file_get_string (metakey, groups[i],
"download-if", NULL);
gboolean autodelete = g_key_file_get_boolean (metakey, groups[i],
"autodelete", NULL);
const char *branch;
@ -7540,7 +7544,7 @@ flatpak_dir_find_remote_related (FlatpakDir *self,
extension_ref,
&checksum))
{
add_related (self, related, extension, extension_ref, checksum, no_autodownload, autodelete);
add_related (self, related, extension, extension_ref, checksum, no_autodownload, download_if, autodelete);
}
else if (subdirectories)
{
@ -7551,7 +7555,7 @@ flatpak_dir_find_remote_related (FlatpakDir *self,
if (flatpak_summary_lookup_ref (summary,
refs[j],
&checksum))
add_related (self, related, extension, refs[j], checksum, no_autodownload, autodelete);
add_related (self, related, extension, refs[j], checksum, no_autodownload, download_if, autodelete);
}
}
}
@ -7657,6 +7661,8 @@ flatpak_dir_find_local_related (FlatpakDir *self,
"subdirectories", NULL);
gboolean no_autodownload = g_key_file_get_boolean (metakey, groups[i],
"no-autodownload", NULL);
g_autofree char *download_if = g_key_file_get_string (metakey, groups[i],
"download-if", NULL);
gboolean autodelete = g_key_file_get_boolean (metakey, groups[i],
"autodelete", NULL);
const char *branch;
@ -7678,7 +7684,7 @@ flatpak_dir_find_local_related (FlatpakDir *self,
NULL))
{
add_related (self, related, extension, extension_ref,
checksum, no_autodownload, autodelete);
checksum, no_autodownload, download_if, autodelete);
}
else if (subdirectories)
{
@ -7700,7 +7706,7 @@ flatpak_dir_find_local_related (FlatpakDir *self,
{
add_related (self, related, extension,
match, match_checksum,
no_autodownload, autodelete);
no_autodownload, download_if, autodelete);
}
}
}

View File

@ -3544,6 +3544,39 @@ flatpak_extension_new (const char *id,
return ext;
}
gboolean
flatpak_extension_matches_reason (const char *extension_id,
const char *reason,
gboolean default_value)
{
const char *extension_basename;
if (reason == NULL || *reason == 0)
return default_value;
extension_basename = strrchr (extension_id, '.');
if (extension_basename == NULL)
return FALSE;
extension_basename += 1;
if (strcmp (reason, "active-gl-driver") == 0)
{
/* handled below */
const char **gl_drivers = flatpak_get_gl_drivers ();
int i;
for (i = 0; gl_drivers[i] != NULL; i++)
{
if (strcmp (gl_drivers[i], extension_basename) == 0)
return TRUE;
}
return FALSE;
}
return FALSE;
}
GList *
flatpak_list_extensions (GKeyFile *metakey,
const char *arch,
@ -3571,6 +3604,7 @@ flatpak_list_extensions (GKeyFile *metakey,
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;
@ -3597,8 +3631,11 @@ flatpak_list_extensions (GKeyFile *metakey,
/* Prefer a full extension (org.freedesktop.Locale) over subdirectory ones (org.freedesktop.Locale.sv) */
if (files != NULL)
{
ext = flatpak_extension_new (extension, extension, ref, directory, add_ld_path, subdir_suffix, merge_dirs, files, is_unmaintained);
res = g_list_prepend (res, ext);
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))
@ -3616,7 +3653,7 @@ flatpak_list_extensions (GKeyFile *metakey,
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)
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;
@ -3632,7 +3669,7 @@ flatpak_list_extensions (GKeyFile *metakey,
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)
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;

View File

@ -65,6 +65,9 @@ const char * flatpak_get_arch (void);
const char ** flatpak_get_arches (void);
const char ** flatpak_get_gl_drivers (void);
gboolean flatpak_extension_matches_reason (const char *extension_id,
const char *reason,
gboolean default_value);
const char * flatpak_get_bwrap (void);