extensions: Minor cleanup

We now store the path to the extension files in the FlatpakExtension
returned from list_extensions instead of having each called look
them up.
tingping/wmclass
Alexander Larsson 2016-06-29 10:24:50 +02:00
parent ab64f70c59
commit 853227a3d6
4 changed files with 53 additions and 57 deletions

View File

@ -54,7 +54,6 @@ gboolean
flatpak_builtin_build_init (int argc, char **argv, GCancellable *cancellable, GError **error)
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(GFile) var_deploy_base = NULL;
g_autoptr(GFile) var_deploy_files = NULL;
g_autoptr(GFile) base = NULL;
g_autoptr(GFile) files_dir = NULL;
@ -171,35 +170,29 @@ flatpak_builtin_build_init (int argc, char **argv, GCancellable *cancellable, GE
if (strcmp (ext->installed_id, requested_extension) == 0 ||
strcmp (ext->id, requested_extension) == 0)
{
g_autoptr(GFile) ext_deploy_dir = flatpak_find_deploy_dir_for_ref (ext->ref, cancellable, NULL);
if (ext_deploy_dir != NULL)
{
g_autoptr(GFile) ext_deploy_files = g_file_get_child (ext_deploy_dir, "files");
g_autoptr(GFile) target = g_file_resolve_relative_path (usr_dir, ext->directory);
g_autoptr(GFile) target_parent = g_file_get_parent (target);
g_autoptr(GFile) ext_deploy_files = g_file_new_for_path (ext->files_path);
g_autoptr(GFile) target = g_file_resolve_relative_path (usr_dir, ext->directory);
g_autoptr(GFile) target_parent = g_file_get_parent (target);
if (!gs_file_ensure_directory (target_parent, TRUE, cancellable, error))
return FALSE;
if (!gs_file_ensure_directory (target_parent, TRUE, cancellable, error))
return FALSE;
/* An extension overrides whatever is there before, so we clean up first */
if (!gs_shutil_rm_rf (target, cancellable, error))
return FALSE;
/* An extension overrides whatever is there before, so we clean up first */
if (!gs_shutil_rm_rf (target, cancellable, error))
return FALSE;
if (!flatpak_cp_a (ext_deploy_files, target, FLATPAK_CP_FLAGS_NO_CHOWN, cancellable, error))
return FALSE;
if (!flatpak_cp_a (ext_deploy_files, target, FLATPAK_CP_FLAGS_NO_CHOWN, cancellable, error))
return FALSE;
found = TRUE;
}
else
{
g_list_free_full (extensions, (GDestroyNotify) flatpak_extension_free);
return flatpak_fail (error, "Requested extension %s not installed\n", requested_extension);
}
found = TRUE;
}
}
if (!found)
return flatpak_fail (error, "No extension %s in sdk\n", requested_extension);
{
g_list_free_full (extensions, (GDestroyNotify) flatpak_extension_free);
return flatpak_fail (error, "Requested extension %s not installed\n", requested_extension);
}
}
g_list_free_full (extensions, (GDestroyNotify) flatpak_extension_free);
}
@ -209,11 +202,9 @@ flatpak_builtin_build_init (int argc, char **argv, GCancellable *cancellable, GE
{
var_ref = flatpak_build_runtime_ref (opt_var, branch, opt_arch);
var_deploy_base = flatpak_find_deploy_dir_for_ref (var_ref, cancellable, error);
if (var_deploy_base == NULL)
var_deploy_files = flatpak_find_files_dir_for_ref (var_ref, cancellable, error);
if (var_deploy_files == NULL)
return FALSE;
var_deploy_files = g_file_get_child (var_deploy_base, "files");
}
if (opt_update)

View File

@ -1713,20 +1713,18 @@ flatpak_run_add_extension_args (GPtrArray *argv_array,
for (l = extensions; l != NULL; l = l->next)
{
FlatpakExtension *ext = l->data;
g_autoptr(GFile) deploy = NULL;
g_autofree char *full_directory = g_build_filename (is_app ? "/app" : "/usr", ext->directory, NULL);
g_autofree char *ref = g_build_filename (full_directory, ".ref", NULL);
g_autofree char *real_ref = g_build_filename (ext->files_path, ext->directory, ".ref", NULL);
deploy = flatpak_find_deploy_dir_for_ref (ext->ref, cancellable, NULL);
if (deploy != NULL)
{
g_autoptr(GFile) files = g_file_get_child (deploy, "files");
g_autofree char *full_directory = g_build_filename (is_app ? "/app" : "/usr", ext->directory, NULL);
g_autofree char *ref = g_build_filename (full_directory, ".ref", NULL);
add_args (argv_array,
"--bind", ext->files_path, full_directory,
NULL);
add_args (argv_array,
"--bind", gs_file_get_path_cached (files), full_directory,
"--lock-file", ref,
NULL);
}
if (g_file_test (real_ref, G_FILE_TEST_EXISTS))
add_args (argv_array,
"--lock-file", ref,
NULL);
}
g_list_free_full (extensions, (GDestroyNotify) flatpak_extension_free);

View File

@ -672,13 +672,13 @@ out:
}
GFile *
flatpak_find_deploy_dir_for_ref (const char *ref,
GCancellable *cancellable,
GError **error)
flatpak_find_files_dir_for_ref (const char *ref,
GCancellable *cancellable,
GError **error)
{
g_autoptr(FlatpakDir) user_dir = NULL;
g_autoptr(FlatpakDir) system_dir = NULL;
GFile *deploy = NULL;
g_autoptr(GFile) deploy = NULL;
user_dir = flatpak_dir_get_user ();
system_dir = flatpak_dir_get_system ();
@ -692,8 +692,7 @@ flatpak_find_deploy_dir_for_ref (const char *ref,
return NULL;
}
return deploy;
return g_file_get_child (deploy, "files");
}
FlatpakDeploy *
@ -2419,22 +2418,24 @@ flatpak_extension_free (FlatpakExtension *extension)
g_free (extension->installed_id);
g_free (extension->ref);
g_free (extension->directory);
g_free (extension->files_path);
g_free (extension);
}
static FlatpakExtension *
flatpak_extension_new (const char *id,
const char *extension,
const char *arch,
const char *branch,
const char *directory)
const char *ref,
const char *directory,
GFile *files)
{
FlatpakExtension *ext = g_new0 (FlatpakExtension, 1);
ext->id = g_strdup (id);
ext->installed_id = g_strdup (extension);
ext->ref = g_build_filename ("runtime", extension, arch, branch, NULL);
ext->ref = g_strdup (ref);
ext->directory = g_strdup (directory);
ext->files_path = g_file_get_path (files);
return ext;
}
@ -2465,7 +2466,7 @@ flatpak_list_extensions (GKeyFile *metakey,
g_autofree char *version = g_key_file_get_string (metakey, groups[i], "version", NULL);
g_autofree char *ref = NULL;
const char *branch;
g_autoptr(GFile) deploy = NULL;
g_autoptr(GFile) files = NULL;
if (directory == NULL)
continue;
@ -2477,11 +2478,11 @@ flatpak_list_extensions (GKeyFile *metakey,
ref = g_build_filename ("runtime", extension, arch, branch, NULL);
deploy = flatpak_find_deploy_dir_for_ref (ref, NULL, NULL);
files = flatpak_find_files_dir_for_ref (ref, NULL, NULL);
/* Prefer a full extension (org.freedesktop.Locale) over subdirectory ones (org.freedesktop.Locale.sv) */
if (deploy != NULL)
if (files != NULL)
{
ext = flatpak_extension_new (extension, extension, arch, branch, directory);
ext = flatpak_extension_new (extension, extension, ref, directory, files);
res = g_list_prepend (res, ext);
}
else if (g_key_file_get_boolean (metakey, groups[i],
@ -2496,9 +2497,14 @@ flatpak_list_extensions (GKeyFile *metakey,
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);
ext = flatpak_extension_new (extension, refs[j], arch, branch, extended_dir);
res = g_list_prepend (res, ext);
if (subdir_files)
{
ext = flatpak_extension_new (extension, refs[j], dir_ref, extended_dir, subdir_files);
res = g_list_prepend (res, ext);
}
}
}
}

View File

@ -86,9 +86,9 @@ char * flatpak_build_runtime_ref (const char *runtime,
char * flatpak_build_app_ref (const char *app,
const char *branch,
const char *arch);
GFile * flatpak_find_deploy_dir_for_ref (const char *ref,
GCancellable *cancellable,
GError **error);
GFile * flatpak_find_files_dir_for_ref (const char *ref,
GCancellable *cancellable,
GError **error);
FlatpakDeploy * flatpak_find_deploy_for_ref (const char *ref,
GCancellable *cancellable,
GError **error);
@ -231,6 +231,7 @@ typedef struct
char *installed_id;
char *ref;
char *directory;
char *files_path;
} FlatpakExtension;
void flatpak_extension_free (FlatpakExtension *extension);