Skip to content

Commit

Permalink
decompose: Convert more FlatpakDir functions to use FlatpakDecomposed
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlarsson committed Nov 10, 2020
1 parent 409fa1e commit c5b2c60
Show file tree
Hide file tree
Showing 14 changed files with 271 additions and 249 deletions.
6 changes: 3 additions & 3 deletions app/flatpak-builtins-build-finish.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,14 +451,14 @@ update_metadata (GFile *base, FlatpakContext *arg_context, gboolean is_runtime,
if (!opt_no_inherit_permissions)
{
g_autofree char *runtime_pref = NULL;
g_autofree char *runtime_ref = NULL;
g_autoptr(GFile) runtime_deploy_dir = NULL;

runtime_pref = g_key_file_get_string (keyfile, group, FLATPAK_METADATA_KEY_RUNTIME, NULL);
if (runtime_pref != NULL)
{
runtime_ref = g_strconcat ("runtime/", runtime_pref, NULL);
runtime_deploy_dir = flatpak_find_deploy_dir_for_ref (runtime_ref, NULL, cancellable, NULL);
g_autoptr(FlatpakDecomposed) runtime_ref = flatpak_decomposed_new_from_pref (FLATPAK_KINDS_RUNTIME, runtime_pref, NULL);
if (runtime_ref)
runtime_deploy_dir = flatpak_find_deploy_dir_for_ref (runtime_ref, NULL, cancellable, NULL);
}

/* This is optional, because some weird uses of flatpak build-finish (like the test suite)
Expand Down
6 changes: 4 additions & 2 deletions app/flatpak-builtins-build-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ flatpak_builtin_build_init (int argc, char **argv, GCancellable *cancellable, GE
g_autofree char *base_ref = NULL;
g_autoptr(FlatpakDecomposed) runtime_ref = NULL;
g_autofree char *extension_runtime_pref = NULL;
g_autofree char *var_ref = NULL;
g_autoptr(FlatpakDecomposed) var_ref = NULL;
g_autoptr(FlatpakDecomposed) sdk_ref = NULL;
FlatpakKinds kinds;
int i;
Expand Down Expand Up @@ -325,7 +325,9 @@ flatpak_builtin_build_init (int argc, char **argv, GCancellable *cancellable, GE

if (opt_var)
{
var_ref = flatpak_build_runtime_ref (opt_var, default_branch, opt_arch);
var_ref = flatpak_decomposed_new_from_parts (FLATPAK_KINDS_RUNTIME, opt_var, opt_arch, default_branch, error);
if (var_ref == NULL)
return FALSE;

var_deploy_files = flatpak_find_files_dir_for_ref (var_ref, cancellable, error);
if (var_deploy_files == NULL)
Expand Down
20 changes: 10 additions & 10 deletions app/flatpak-builtins-create-usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ add_related (GHashTable *all_refs,
arch = flatpak_decomposed_dup_arch (ref);
branch = flatpak_decomposed_dup_branch (ref);

deploy_data = flatpak_dir_get_deploy_data (dir, flatpak_decomposed_get_ref (ref), FLATPAK_DEPLOY_VERSION_ANY, cancellable, error);
deploy_data = flatpak_dir_get_deploy_data (dir, ref, FLATPAK_DEPLOY_VERSION_ANY, cancellable, error);
if (deploy_data == NULL)
return FALSE;

Expand Down Expand Up @@ -154,14 +154,14 @@ add_related (GHashTable *all_refs,
if (ext_deploy_data == NULL)
{
g_printerr (_("Warning: Omitting related ref ‘%s’ because it is not installed.\n"),
ext->ref);
flatpak_decomposed_get_ref (ext->ref));
continue;
}

if (flatpak_deploy_data_has_subpaths (ext_deploy_data) && !opt_allow_partial)
{
g_printerr (_("Warning: Related ref ‘%s’ is partially installed. Use --allow-partial to suppress this message.\n"),
ext->ref);
flatpak_decomposed_get_ref (ext->ref));
}

ext_remote = flatpak_deploy_data_get_origin (ext_deploy_data);
Expand All @@ -171,7 +171,7 @@ add_related (GHashTable *all_refs,
if (ext_collection_id == NULL)
{
g_printerr (_("Warning: Omitting related ref ‘%s’ because its remote ‘%s’ does not have a collection ID set.\n"),
ext->ref, ext_remote);
flatpak_decomposed_get_ref (ext->ref), ext_remote);
continue;
}

Expand All @@ -181,7 +181,7 @@ add_related (GHashTable *all_refs,
c_s = commit_and_subpaths_new (ext_commit, (const char * const *) resolved_ext_subpaths);

g_hash_table_insert (all_collection_ids, g_strdup (ext_collection_id), g_strdup (ext_remote));
ext_collection_ref = ostree_collection_ref_new (ext_collection_id, ext->ref);
ext_collection_ref = ostree_collection_ref_new (ext_collection_id, flatpak_decomposed_get_ref (ext->ref));
g_hash_table_insert (all_refs, g_steal_pointer (&ext_collection_ref), c_s);
}

Expand Down Expand Up @@ -218,7 +218,7 @@ add_runtime (GHashTable *all_refs,

g_debug ("Finding the runtime for ‘%s’", flatpak_decomposed_get_ref (ref));

deploy_data = flatpak_dir_get_deploy_data (dir, flatpak_decomposed_get_ref (ref), FLATPAK_DEPLOY_VERSION_ANY, cancellable, error);
deploy_data = flatpak_dir_get_deploy_data (dir, ref, FLATPAK_DEPLOY_VERSION_ANY, cancellable, error);
if (deploy_data == NULL)
return FALSE;

Expand All @@ -237,10 +237,10 @@ add_runtime (GHashTable *all_refs,
if (runtime_ref == NULL)
return FALSE;

runtime_deploy_data = flatpak_dir_get_deploy_data (dir, flatpak_decomposed_get_ref (runtime_ref), FLATPAK_DEPLOY_VERSION_ANY, cancellable, error);
runtime_deploy_data = flatpak_dir_get_deploy_data (dir, runtime_ref, FLATPAK_DEPLOY_VERSION_ANY, cancellable, error);
if (runtime_deploy_data == NULL)
return FALSE;
runtime_remote = flatpak_dir_get_origin (dir, flatpak_decomposed_get_ref (runtime_ref), cancellable, error);
runtime_remote = flatpak_dir_get_origin (dir, runtime_ref, cancellable, error);
if (runtime_remote == NULL)
return FALSE;
runtime_collection_id = flatpak_dir_get_remote_collection_id (dir, runtime_remote);
Expand Down Expand Up @@ -602,7 +602,7 @@ flatpak_builtin_create_usb (int argc, char **argv, GCancellable *cancellable, GE
if (branch == NULL)
branch = flatpak_decomposed_dup_branch (installed_ref);

remote = flatpak_dir_get_origin (dir, flatpak_decomposed_get_ref (installed_ref), cancellable, error);
remote = flatpak_dir_get_origin (dir, installed_ref, cancellable, error);
if (remote == NULL)
return FALSE;

Expand Down Expand Up @@ -636,7 +636,7 @@ flatpak_builtin_create_usb (int argc, char **argv, GCancellable *cancellable, GE
const char *commit;
CommitAndSubpaths *c_s;

deploy_data = flatpak_dir_get_deploy_data (dir, flatpak_decomposed_get_ref (installed_ref), FLATPAK_DEPLOY_VERSION_ANY, cancellable, error);
deploy_data = flatpak_dir_get_deploy_data (dir, installed_ref, FLATPAK_DEPLOY_VERSION_ANY, cancellable, error);
if (deploy_data == NULL)
return FALSE;

Expand Down
4 changes: 2 additions & 2 deletions app/flatpak-builtins-info.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ flatpak_builtin_info (int argc, char **argv, GCancellable *cancellable, GError *
if (dir == NULL)
return FALSE;

deploy_data = flatpak_dir_get_deploy_data (dir, flatpak_decomposed_get_ref (ref), FLATPAK_DEPLOY_VERSION_CURRENT, cancellable, error);
deploy_data = flatpak_dir_get_deploy_data (dir, ref, FLATPAK_DEPLOY_VERSION_CURRENT, cancellable, error);
if (deploy_data == NULL)
return FALSE;

Expand Down Expand Up @@ -494,7 +494,7 @@ flatpak_builtin_info (int argc, char **argv, GCancellable *cancellable, GError *
}

g_print ("\n");
print_aligned (len, _("Extension:"), ext->ref);
print_aligned (len, _("Extension:"), flatpak_decomposed_get_ref (ext->ref));
print_aligned (len, _("ID:"), ext->id);
print_aligned (len, _("Origin:"), origin ? origin : "-");
print_aligned (len, _("Commit:"), formatted_commit);
Expand Down
2 changes: 1 addition & 1 deletion app/flatpak-builtins-remote-delete.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ flatpak_builtin_remote_delete (int argc, char **argv, GCancellable *cancellable,
for (i = 0; refs != NULL && i < refs->len; i++)
{
FlatpakDecomposed *ref = g_ptr_array_index (refs, i);
g_autofree char *origin = flatpak_dir_get_origin (preferred_dir, flatpak_decomposed_get_ref (ref), NULL, NULL);
g_autofree char *origin = flatpak_dir_get_origin (preferred_dir, ref, NULL, NULL);
if (g_strcmp0 (origin, remote_name) == 0)
g_ptr_array_add (refs_to_remove, flatpak_decomposed_dup_ref (ref));
}
Expand Down
4 changes: 1 addition & 3 deletions app/flatpak-builtins-remote-ls.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,9 @@ ls_remote (GHashTable *refs_hash, const char **arches, const char *app_runtime,

GLNX_HASH_TABLE_FOREACH_KV (refs, FlatpakDecomposed *, ref, const char *, checksum)
{
const char *ref_str = flatpak_decomposed_get_ref (ref);

if (opt_only_updates)
{
g_autoptr(GBytes) deploy_data = flatpak_dir_get_deploy_data (dir, ref_str, FLATPAK_DEPLOY_VERSION_ANY, cancellable, NULL);
g_autoptr(GBytes) deploy_data = flatpak_dir_get_deploy_data (dir, ref, FLATPAK_DEPLOY_VERSION_ANY, cancellable, NULL);

if (deploy_data == NULL)
continue;
Expand Down
33 changes: 18 additions & 15 deletions app/flatpak-builtins-repair.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ transaction_add_local_ref (FlatpakDir *dir,
const char *origin;
const char **subpaths;

deploy_data = flatpak_dir_get_deploy_data (dir, flatpak_decomposed_get_ref (ref), FLATPAK_DEPLOY_VERSION_ANY, NULL, &local_error);
deploy_data = flatpak_dir_get_deploy_data (dir, ref, FLATPAK_DEPLOY_VERSION_ANY, NULL, &local_error);
if (deploy_data == NULL)
{
if (!g_error_matches (local_error, FLATPAK_ERROR, FLATPAK_ERROR_NOT_INSTALLED))
Expand Down Expand Up @@ -355,28 +355,31 @@ flatpak_builtin_repair (int argc, char **argv, GCancellable *cancellable, GError
g_autofree char *remote = NULL;
g_autofree char *ref_name = NULL;
FsckStatus status;
g_autoptr(FlatpakDecomposed) ref = NULL;
g_autofree char *origin = NULL;

if (!ostree_parse_refspec (refspec, &remote, &ref_name, error))
return FALSE;

/* Does this look like a regular ref? */
if (g_str_has_prefix (ref_name, "app/") || g_str_has_prefix (ref_name, "runtime/"))
{
g_autofree char *origin = flatpak_dir_get_origin (dir, ref_name, cancellable, NULL);
ref = flatpak_decomposed_new_from_ref (ref_name, NULL);
if (ref == NULL)
continue;

/* If so, is it deployed, and from this remote? */
if (remote == NULL || g_strcmp0 (origin, remote) != 0)
{
if (!opt_dry_run)
{
g_print (_("Removing non-deployed ref %s…\n"), refspec);
(void) ostree_repo_set_ref_immediate (repo, remote, ref_name, NULL, cancellable, NULL);
}
else
g_print (_("Skipping non-deployed ref %s…\n"), refspec);
origin = flatpak_dir_get_origin (dir, ref, cancellable, NULL);

continue;
/* If so, is it deployed, and from this remote? */
if (remote == NULL || g_strcmp0 (origin, remote) != 0)
{
if (!opt_dry_run)
{
g_print (_("Removing non-deployed ref %s…\n"), refspec);
(void) ostree_repo_set_ref_immediate (repo, remote, ref_name, NULL, cancellable, NULL);
}
else
g_print (_("Skipping non-deployed ref %s…\n"), refspec);

continue;
}

/* When printing progress, we have to print a newline character at the end, otherwise errors printing in
Expand Down
42 changes: 21 additions & 21 deletions common/flatpak-dir-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -472,23 +472,23 @@ GFile * flatpak_dir_get_unmaintained_extension_dir (FlatpakDir *self,
const char *name,
const char *arch,
const char *branch);
GBytes * flatpak_dir_get_deploy_data (FlatpakDir *dir,
const char *ref,
int required_version,
GCancellable *cancellable,
GError **error);
char * flatpak_dir_get_origin (FlatpakDir *self,
const char *ref,
GCancellable *cancellable,
GError **error);
GBytes * flatpak_dir_get_deploy_data (FlatpakDir *dir,
FlatpakDecomposed *ref,
int required_version,
GCancellable *cancellable,
GError **error);
char * flatpak_dir_get_origin (FlatpakDir *self,
FlatpakDecomposed *ref,
GCancellable *cancellable,
GError **error);
GFile * flatpak_dir_get_exports_dir (FlatpakDir *self);
GFile * flatpak_dir_get_removed_dir (FlatpakDir *self);
GFile * flatpak_dir_get_sideload_repos_dir (FlatpakDir *self);
GFile * flatpak_dir_get_runtime_sideload_repos_dir (FlatpakDir *self);
GFile * flatpak_dir_get_if_deployed (FlatpakDir *self,
const char *ref,
const char *checksum,
GCancellable *cancellable);
GFile * flatpak_dir_get_if_deployed (FlatpakDir *self,
FlatpakDecomposed *ref,
const char *checksum,
GCancellable *cancellable);
GFile * flatpak_dir_get_unmaintained_extension_dir_if_exists (FlatpakDir *self,
const char *name,
const char *arch,
Expand Down Expand Up @@ -738,14 +738,14 @@ gboolean flatpak_dir_install_bundle (FlatpakDir *self,
char **out_ref,
GCancellable *cancellable,
GError **error);
gboolean flatpak_dir_needs_update_for_commit_and_subpaths (FlatpakDir *self,
const char *remote,
const char *ref,
const char *target_commit,
const char **opt_subpaths);
gboolean flatpak_dir_needs_update_for_commit_and_subpaths (FlatpakDir *self,
const char *remote,
FlatpakDecomposed *ref,
const char *target_commit,
const char **opt_subpaths);
char * flatpak_dir_check_for_update (FlatpakDir *self,
FlatpakRemoteState *state,
const char *ref,
FlatpakDecomposed *ref,
const char *checksum_or_latest,
const char **opt_subpaths,
gboolean no_pull,
Expand Down Expand Up @@ -1004,8 +1004,8 @@ gboolean flatpak_dir_find_latest_rev (FlatpakDir *self,
GFile **out_sideload_path,
GCancellable *cancellable,
GError **error);
char * flatpak_dir_get_remote_auto_install_authenticator_ref (FlatpakDir *self,
const char *remote_name);
FlatpakDecomposed * flatpak_dir_get_remote_auto_install_authenticator_ref (FlatpakDir *self,
const char *remote_name);

char ** flatpak_dir_get_default_locales (FlatpakDir *self);
char ** flatpak_dir_get_default_locale_languages (FlatpakDir *self);
Expand Down

0 comments on commit c5b2c60

Please sign in to comment.