diff options
author | Alexander Larsson <alexl@redhat.com> | 2020-10-22 11:13:15 +0200 |
---|---|---|
committer | Alexander Larsson <alexl@redhat.com> | 2020-10-26 13:50:15 +0100 |
commit | 762d096c2f9a707ed6dfae65b53db17bada35c82 (patch) | |
tree | c4fd11f832d347891d180af360bebf687319a982 | |
parent | 3b40d2f3e1833119b982d4d93552a1afb10cdb08 (diff) | |
download | flatpak-762d096c2f9a707ed6dfae65b53db17bada35c82.tar.gz |
summaries: Ensure we can support non-default arches W/ indexed summaries
We need to load the ensure the right arch whenever we need it.
Also this restructures the RemoteState handling a bit in general so that
we avoid loading the same remote state multiple times when converting
partial refs to full refs.
-rw-r--r-- | app/flatpak-builtins-install.c | 49 | ||||
-rw-r--r-- | app/flatpak-builtins-remote-info.c | 11 | ||||
-rw-r--r-- | app/flatpak-builtins-remote-ls.c | 34 | ||||
-rw-r--r-- | app/flatpak-builtins-utils.c | 81 | ||||
-rw-r--r-- | app/flatpak-builtins-utils.h | 25 | ||||
-rw-r--r-- | app/flatpak-complete.c | 22 | ||||
-rw-r--r-- | common/flatpak-dir-private.h | 7 | ||||
-rw-r--r-- | common/flatpak-dir.c | 74 |
8 files changed, 216 insertions, 87 deletions
diff --git a/app/flatpak-builtins-install.c b/app/flatpak-builtins-install.c index 9db3afb7..8665d663 100644 --- a/app/flatpak-builtins-install.c +++ b/app/flatpak-builtins-install.c @@ -33,6 +33,7 @@ #include "flatpak-builtins.h" #include "flatpak-builtins-utils.h" +#include "flatpak-transaction-private.h" #include "flatpak-cli-transaction.h" #include "flatpak-quiet-transaction.h" #include "flatpak-utils-private.h" @@ -406,15 +407,22 @@ flatpak_builtin_install (int argc, char **argv, GCancellable *cancellable, GErro matched_kinds, FIND_MATCHING_REFS_FLAGS_FUZZY, cancellable, &local_error); else - refs = flatpak_dir_find_remote_refs (this_dir, this_remote, (const char **)opt_sideload_repos, id, branch, this_default_branch, arch, - flatpak_get_default_arch (), - matched_kinds, FIND_MATCHING_REFS_FLAGS_FUZZY, - cancellable, &local_error); - - if (refs == NULL) { - g_warning ("An error was encountered searching remote ‘%s’ for ‘%s’: %s", this_remote, argv[1], local_error->message); - continue; + g_autoptr(FlatpakRemoteState) state = get_remote_state (this_dir, this_remote, FALSE, FALSE, + arch, (const char **)opt_sideload_repos, + cancellable, error); + if (state == NULL) + return FALSE; + + refs = flatpak_dir_find_remote_refs (this_dir, state, id, branch, this_default_branch, arch, + flatpak_get_default_arch (), + matched_kinds, FIND_MATCHING_REFS_FLAGS_FUZZY, + cancellable, &local_error); + if (refs == NULL) + { + g_warning ("An error was encountered searching remote ‘%s’ for ‘%s’: %s", this_remote, argv[1], local_error->message); + continue; + } } if (g_strv_length (refs) == 0) @@ -502,12 +510,25 @@ flatpak_builtin_install (int argc, char **argv, GCancellable *cancellable, GErro matched_kinds, FIND_MATCHING_REFS_FLAGS_FUZZY, cancellable, error); else - refs = flatpak_dir_find_remote_refs (dir, remote, (const char **)opt_sideload_repos, id, branch, default_branch, arch, - flatpak_get_default_arch (), - matched_kinds, FIND_MATCHING_REFS_FLAGS_FUZZY, - cancellable, error); - if (refs == NULL) - return FALSE; + { + g_autoptr(FlatpakRemoteState) state = NULL; + + state = flatpak_transaction_ensure_remote_state (transaction, FLATPAK_TRANSACTION_OPERATION_INSTALL, + remote, error); + if (state == NULL) + return FALSE; + + if (arch != NULL && + !flatpak_remote_state_ensure_subsummary (state, dir, arch, FALSE, cancellable, error)) + return FALSE; + + refs = flatpak_dir_find_remote_refs (dir, state, id, branch, default_branch, arch, + flatpak_get_default_arch (), + matched_kinds, FIND_MATCHING_REFS_FLAGS_FUZZY, + cancellable, error); + if (refs == NULL) + return FALSE; + } refs_len = g_strv_length (refs); if (refs_len == 0) diff --git a/app/flatpak-builtins-remote-info.c b/app/flatpak-builtins-remote-info.c index 77f3ba3c..e8f36620 100644 --- a/app/flatpak-builtins-remote-info.c +++ b/app/flatpak-builtins-remote-info.c @@ -107,6 +107,7 @@ flatpak_builtin_remote_info (int argc, char **argv, GCancellable *cancellable, G guint64 download_size = 0; g_autofree char *formatted_installed_size = NULL; g_autofree char *formatted_download_size = NULL; + g_autofree char *ref_arch = NULL; const gchar *subject = NULL; guint64 timestamp; g_autofree char *formatted_timestamp = NULL; @@ -138,13 +139,13 @@ flatpak_builtin_remote_info (int argc, char **argv, GCancellable *cancellable, G &matched_kinds, &id, &arch, &branch, error)) return FALSE; - ref = flatpak_dir_find_remote_ref (preferred_dir, remote, NULL, id, branch, default_branch, arch, - matched_kinds, &kind, cancellable, error); - if (ref == NULL) + state = get_remote_state (preferred_dir, remote, opt_cached, opt_sideloaded, arch, NULL, NULL, error); + if (state == NULL) return FALSE; - state = get_remote_state (preferred_dir, remote, opt_cached, opt_sideloaded, cancellable, error); - if (state == NULL) + ref = flatpak_dir_find_remote_ref (preferred_dir, state, id, branch, default_branch, arch, + matched_kinds, &kind, cancellable, error); + if (ref == NULL) return FALSE; if (opt_cached) diff --git a/app/flatpak-builtins-remote-ls.c b/app/flatpak-builtins-remote-ls.c index 65e85633..6a928586 100644 --- a/app/flatpak-builtins-remote-ls.c +++ b/app/flatpak-builtins-remote-ls.c @@ -411,6 +411,17 @@ flatpak_builtin_remote_ls (int argc, char **argv, GCancellable *cancellable, GEr has_remote = (argc == 2); + if (opt_arch != NULL) + { + if (strcmp (opt_arch, "*") == 0) + arches = NULL; + else + { + opt_arches[0] = opt_arch; + arches = opt_arches; + } + } + if (has_remote) { g_autoptr(FlatpakDir) preferred_dir = NULL; @@ -428,10 +439,14 @@ flatpak_builtin_remote_ls (int argc, char **argv, GCancellable *cancellable, GEr return FALSE; } - state = get_remote_state (preferred_dir, argv[1], opt_cached, opt_sideloaded, cancellable, error); + state = get_remote_state (preferred_dir, argv[1], opt_cached, opt_sideloaded, opt_arches[0], NULL, cancellable, error); if (state == NULL) return FALSE; + if (arches == NULL && + !ensure_remote_state_all_arches (preferred_dir, state, opt_cached, opt_sideloaded, cancellable, error)) + return FALSE; + if (!flatpak_dir_list_remote_refs (preferred_dir, state, &refs, cancellable, error)) return FALSE; @@ -463,11 +478,15 @@ flatpak_builtin_remote_ls (int argc, char **argv, GCancellable *cancellable, GEr if (flatpak_dir_get_remote_disabled (dir, remote_name)) continue; - state = get_remote_state (dir, remote_name, opt_cached, opt_sideloaded, + state = get_remote_state (dir, remote_name, opt_cached, opt_sideloaded, opt_arches[0], NULL, cancellable, error); if (state == NULL) return FALSE; + if (arches == NULL && + !ensure_remote_state_all_arches (dir, state, opt_cached, opt_sideloaded, cancellable, error)) + return FALSE; + if (!flatpak_dir_list_remote_refs (dir, state, &refs, cancellable, error)) return FALSE; @@ -478,17 +497,6 @@ flatpak_builtin_remote_ls (int argc, char **argv, GCancellable *cancellable, GEr } } - if (opt_arch != NULL) - { - if (strcmp (opt_arch, "*") == 0) - arches = NULL; - else - { - opt_arches[0] = opt_arch; - arches = opt_arches; - } - } - /* show origin by default if listing multiple remotes */ all_columns[5].def = !has_remote; diff --git a/app/flatpak-builtins-utils.c b/app/flatpak-builtins-utils.c index 3b1e4710..b42894b3 100644 --- a/app/flatpak-builtins-utils.c +++ b/app/flatpak-builtins-utils.c @@ -1336,14 +1336,17 @@ FlatpakRemoteState * get_remote_state (FlatpakDir *dir, const char *remote, gboolean cached, - gboolean sideloaded, + gboolean only_sideloaded, + const char *opt_arch, + const char **opt_sideload_repos, GCancellable *cancellable, GError **error) { g_autoptr(GError) local_error = NULL; + g_autoptr(GError) local_error2 = NULL; FlatpakRemoteState *state = NULL; - if (sideloaded) + if (only_sideloaded) { state = flatpak_dir_get_remote_state_local_only (dir, remote, cancellable, error); if (state == NULL) @@ -1351,11 +1354,11 @@ get_remote_state (FlatpakDir *dir, } else { - state = flatpak_dir_get_remote_state (dir, remote, cached, cancellable, &local_error); + state = flatpak_dir_get_remote_state_optional (dir, remote, cached, cancellable, &local_error); if (state == NULL && g_error_matches (local_error, FLATPAK_ERROR, FLATPAK_ERROR_NOT_CACHED)) { g_clear_error (&local_error); - state = flatpak_dir_get_remote_state (dir, remote, FALSE, cancellable, &local_error); + state = flatpak_dir_get_remote_state_optional (dir, remote, FALSE, cancellable, &local_error); } if (state == NULL) @@ -1365,5 +1368,75 @@ get_remote_state (FlatpakDir *dir, } } + if (opt_arch != NULL && + !ensure_remote_state_arch (dir, state, opt_arch, cached, only_sideloaded, cancellable, &local_error)) + return NULL; + + for (int i = 0; opt_sideload_repos != NULL && opt_sideload_repos[i] != NULL; i++) + { + g_autoptr(GFile) f = g_file_new_for_path (opt_sideload_repos[i]); + flatpak_remote_state_add_sideload_repo (state, f); + } + return state; } + +gboolean +ensure_remote_state_arch (FlatpakDir *dir, + FlatpakRemoteState *state, + const char *arch, + gboolean cached, + gboolean only_sideloaded, + GCancellable *cancellable, + GError **error) +{ + g_autoptr(GError) local_error = NULL; + + if (only_sideloaded) + return TRUE; + + if (flatpak_remote_state_ensure_subsummary (state, dir, arch, cached, cancellable, &local_error)) + return TRUE; + + if (!g_error_matches (local_error, FLATPAK_ERROR, FLATPAK_ERROR_NOT_CACHED)) + { + g_propagate_error (error, g_steal_pointer (&local_error)); + return FALSE; + } + + return flatpak_remote_state_ensure_subsummary (state, dir, arch, FALSE, cancellable, error); +} + +gboolean +ensure_remote_state_arch_for_ref (FlatpakDir *dir, + FlatpakRemoteState *state, + const char *ref, + gboolean cached, + gboolean only_sideloaded, + GCancellable *cancellable, + GError **error) +{ + g_autofree char *ref_arch = flatpak_get_arch_for_ref (ref); + return ensure_remote_state_arch (dir, state, ref_arch, cached, only_sideloaded,cancellable, error); +} + +gboolean +ensure_remote_state_all_arches (FlatpakDir *dir, + FlatpakRemoteState *state, + gboolean cached, + gboolean only_sideloaded, + GCancellable *cancellable, + GError **error) +{ + if (state->index_ht == NULL) + return TRUE; + + GLNX_HASH_TABLE_FOREACH (state->index_ht, const char *, arch) + { + if (!ensure_remote_state_arch (dir, state, arch, + cached, only_sideloaded, + cancellable, error)) + return FALSE; + } + return TRUE; +} diff --git a/app/flatpak-builtins-utils.h b/app/flatpak-builtins-utils.h index 2ef01680..ab9745e1 100644 --- a/app/flatpak-builtins-utils.h +++ b/app/flatpak-builtins-utils.h @@ -176,8 +176,31 @@ void print_wrapped (int columns, FlatpakRemoteState * get_remote_state (FlatpakDir *dir, const char *remote, gboolean cached, - gboolean sideloaded, + gboolean only_sideloaded, + const char *opt_arch, + const char **opt_sideload_repos, GCancellable *cancellable, GError **error); +gboolean ensure_remote_state_arch (FlatpakDir *dir, + FlatpakRemoteState *state, + const char *arch, + gboolean cached, + gboolean only_sideloaded, + GCancellable *cancellable, + GError **error); +gboolean ensure_remote_state_arch_for_ref (FlatpakDir *dir, + FlatpakRemoteState *state, + const char *ref, + gboolean cached, + gboolean only_sideloaded, + GCancellable *cancellable, + GError **error); +gboolean ensure_remote_state_all_arches (FlatpakDir *dir, + FlatpakRemoteState *state, + gboolean cached, + gboolean only_sideloaded, + GCancellable *cancellable, + GError **error); + #endif /* __FLATPAK_BUILTINS_UTILS_H__ */ diff --git a/app/flatpak-complete.c b/app/flatpak-complete.c index 9010b4b7..a61b0a0d 100644 --- a/app/flatpak-complete.c +++ b/app/flatpak-complete.c @@ -194,15 +194,19 @@ flatpak_complete_partial_ref (FlatpakCompletion *completion, if (remote) { - refs = flatpak_dir_find_remote_refs (dir, completion->argv[1], NULL, - (element > 1) ? id : NULL, - (element > 3) ? branch : NULL, - NULL, /* default branch */ - (element > 2) ? arch : only_arch, - NULL, /* default arch */ - matched_kinds, - FIND_MATCHING_REFS_FLAGS_NONE, - NULL, &error); + g_autoptr(FlatpakRemoteState) state = get_remote_state (dir, remote, TRUE, FALSE, + (element > 2) ? arch : only_arch, NULL, + NULL, &error); + if (state != NULL) + refs = flatpak_dir_find_remote_refs (dir, state, + (element > 1) ? id : NULL, + (element > 3) ? branch : NULL, + NULL, /* default branch */ + (element > 2) ? arch : only_arch, + NULL, /* default arch */ + matched_kinds, + FIND_MATCHING_REFS_FLAGS_NONE, + NULL, &error); } else { diff --git a/common/flatpak-dir-private.h b/common/flatpak-dir-private.h index 4da5a695..02291c74 100644 --- a/common/flatpak-dir-private.h +++ b/common/flatpak-dir-private.h @@ -147,6 +147,7 @@ gboolean flatpak_remote_state_ensure_summary (FlatpakRemoteState *self, gboolean flatpak_remote_state_ensure_subsummary (FlatpakRemoteState *self, FlatpakDir *dir, const char *arch, + gboolean only_cached, GCancellable *cancellable, GError **error); gboolean flatpak_remote_state_allow_ref (FlatpakRemoteState *self, @@ -508,8 +509,7 @@ gboolean flatpak_dir_ref_is_masked (FlatpakDir *self, gboolean flatpak_dir_ref_is_pinned (FlatpakDir *self, const char *ref); char * flatpak_dir_find_remote_ref (FlatpakDir *self, - const char *remote, - const char **opt_sideload_repos, + FlatpakRemoteState *state, const char *name, const char *opt_branch, const char *opt_default_branch, @@ -519,8 +519,7 @@ char * flatpak_dir_find_remote_ref (FlatpakDir *self, GCancellable *cancellable, GError **error); char ** flatpak_dir_find_remote_refs (FlatpakDir *self, - const char *remote, - const char **opt_sideload_repos, + FlatpakRemoteState *state, const char *name, const char *opt_branch, const char *opt_default_branch, diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c index 9c6c72a7..b8e42b7a 100644 --- a/common/flatpak-dir.c +++ b/common/flatpak-dir.c @@ -447,6 +447,7 @@ gboolean flatpak_remote_state_ensure_subsummary (FlatpakRemoteState *self, FlatpakDir *dir, const char *arch, + gboolean only_cached, GCancellable *cancellable, GError **error) { @@ -476,7 +477,7 @@ flatpak_remote_state_ensure_subsummary (FlatpakRemoteState *self, if (digest == NULL) return TRUE; /* No refs for this arch */ - if (!flatpak_dir_remote_fetch_indexed_summary (dir, self->remote_name, digest, FALSE, + if (!flatpak_dir_remote_fetch_indexed_summary (dir, self->remote_name, digest, only_cached, &bytes, cancellable, error)) return FALSE; @@ -689,28 +690,40 @@ flatpak_remote_state_match_subrefs (FlatpakRemoteState *self, return flatpak_summary_match_subrefs (summary, NULL, ref); } -/* 0 if not specified */ -static guint32 -flatpak_remote_state_get_cache_version (FlatpakRemoteState *self) +static VarMetadataRef +flatpak_remote_state_get_main_metadata (FlatpakRemoteState *self) { - VarMetadataRef meta; VarSummaryRef summary; VarSummaryIndexRef index; - - if (!flatpak_remote_state_ensure_summary (self, NULL)) - return 0; + VarMetadataRef meta; if (self->index) { index = var_summary_index_from_gvariant (self->index); meta = var_summary_index_get_metadata (index); } - else + else if (self->summary) { summary = var_summary_from_gvariant (self->summary); meta = var_summary_get_metadata (summary); } + else + g_assert_not_reached (); + + return meta; +} + + +/* 0 if not specified */ +static guint32 +flatpak_remote_state_get_cache_version (FlatpakRemoteState *self) +{ + VarMetadataRef meta; + if (!flatpak_remote_state_ensure_summary (self, NULL)) + return 0; + + meta = flatpak_remote_state_get_main_metadata (self); return GUINT32_FROM_LE (var_metadata_lookup_uint32 (meta, "xa.cache-version", 0)); } @@ -11653,7 +11666,7 @@ _flatpak_dir_get_remote_state (FlatpakDir *self, /* Always load default (or specified) arch subsummary. Further arches can be manually loaded with flatpak_remote_state_ensure_subsummary. */ if (opt_summary == NULL && - !flatpak_remote_state_ensure_subsummary (state, self, arch, cancellable, error)) + !flatpak_remote_state_ensure_subsummary (state, self, arch, only_cached, cancellable, error)) return NULL; } @@ -11667,10 +11680,9 @@ _flatpak_dir_get_remote_state (FlatpakDir *self, state->default_token_type = 1; } - if (state->summary != NULL) /* In the optional case we might not have a summary */ + if (state->summary != NULL || state->index != NULL) /* In the optional case we might not have a summary */ { - VarSummaryRef summary = var_summary_from_gvariant (state->summary); - VarMetadataRef meta = var_summary_get_metadata (summary); + VarMetadataRef meta = flatpak_remote_state_get_main_metadata (state); VarVariantRef res; if (var_metadata_lookup (meta, "xa.default-token-type", NULL, &res) && @@ -12104,8 +12116,7 @@ flatpak_dir_get_remote_collection_id (FlatpakDir *self, char ** flatpak_dir_find_remote_refs (FlatpakDir *self, - const char *remote, - const char **opt_sideload_repos, + FlatpakRemoteState *state, const char *name, const char *opt_branch, const char *opt_default_branch, @@ -12117,19 +12128,8 @@ flatpak_dir_find_remote_refs (FlatpakDir *self, GError **error) { g_autoptr(GHashTable) remote_refs = NULL; - g_autoptr(FlatpakRemoteState) state = NULL; GPtrArray *matched_refs; - state = flatpak_dir_get_remote_state_optional (self, remote, FALSE, cancellable, error); - if (state == NULL) - return NULL; - - for (int i = 0; opt_sideload_repos != NULL && opt_sideload_repos[i] != NULL; i++) - { - g_autoptr(GFile) f = g_file_new_for_path (opt_sideload_repos[i]); - flatpak_remote_state_add_sideload_repo (state, f); - } - if (!flatpak_dir_list_all_remote_refs (self, state, &remote_refs, cancellable, error)) return NULL; @@ -12211,8 +12211,7 @@ find_ref_for_refs_set (GHashTable *refs, char * flatpak_dir_find_remote_ref (FlatpakDir *self, - const char *remote, - const char **opt_sideload_repos, + FlatpakRemoteState *state, const char *name, const char *opt_branch, const char *opt_default_branch, @@ -12224,17 +12223,18 @@ flatpak_dir_find_remote_ref (FlatpakDir *self, { g_autofree char *remote_ref = NULL; g_autoptr(GHashTable) remote_refs = NULL; - g_autoptr(FlatpakRemoteState) state = NULL; g_autoptr(GError) my_error = NULL; - state = flatpak_dir_get_remote_state_optional (self, remote, FALSE, cancellable, error); - if (state == NULL) - return NULL; - - for (int i = 0; opt_sideload_repos != NULL && opt_sideload_repos[i] != NULL; i++) + /* Avoid work if the entire ref was specified */ + if (opt_branch != NULL && opt_arch != NULL && (kinds == FLATPAK_KINDS_APP || kinds == FLATPAK_KINDS_RUNTIME)) { - g_autoptr(GFile) f = g_file_new_for_path (opt_sideload_repos[i]); - flatpak_remote_state_add_sideload_repo (state, f); + if (out_kind) + *out_kind = kinds; + + if (kinds == FLATPAK_KINDS_APP) + return flatpak_build_app_ref (name, opt_branch, opt_arch); + else + return flatpak_build_runtime_ref (name, opt_branch, opt_arch); } if (!flatpak_dir_list_all_remote_refs (self, state, @@ -12250,7 +12250,7 @@ flatpak_dir_find_remote_ref (FlatpakDir *self, { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, _("Error searching remote %s: %s"), - remote, + state->remote_name, my_error->message); return NULL; } |