Skip to content

Commit

Permalink
Convert flatpak_summary_lookup_ref from GVariants
Browse files Browse the repository at this point in the history
Now it returns a VarRefInfoRef instead of a GVariant
  • Loading branch information
alexlarsson committed Feb 17, 2020
1 parent 9f6c604 commit 61da44a
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 43 deletions.
2 changes: 1 addition & 1 deletion app/flatpak-builtins-remote-info.c
Expand Up @@ -151,7 +151,7 @@ flatpak_builtin_remote_info (int argc, char **argv, GCancellable *cancellable, G
commit = g_strdup (opt_commit);
else
{
flatpak_remote_state_lookup_ref (state, ref, &commit, NULL, error);
flatpak_remote_state_lookup_ref (state, ref, &commit, NULL, NULL, error);
if (commit == NULL)
{
if (error != NULL && *error == NULL)
Expand Down
4 changes: 3 additions & 1 deletion common/flatpak-dir-private.h
Expand Up @@ -25,6 +25,7 @@

#include "flatpak-common-types-private.h"
#include "flatpak-context-private.h"
#include "flatpak-variant-private.h"
#include "libglnx/libglnx.h"

/* Version history:
Expand Down Expand Up @@ -135,7 +136,8 @@ gboolean flatpak_remote_state_allow_ref (FlatpakRemoteState *self,
gboolean flatpak_remote_state_lookup_ref (FlatpakRemoteState *self,
const char *ref,
char **out_checksum,
GVariant **out_variant,
gboolean *out_has_info,
VarRefInfoRef *out_info,
GError **error);
char **flatpak_remote_state_match_subrefs (FlatpakRemoteState *self,
const char *ref);
Expand Down
57 changes: 34 additions & 23 deletions common/flatpak-dir.c
Expand Up @@ -357,12 +357,14 @@ flatpak_remote_state_allow_ref (FlatpakRemoteState *self,
}

/* Returns TRUE if the ref is found in the summary or cache. out_checksum and
* out_variant are not guaranteed to be set even when the ref is found. */
* out_variant are not guaranteed to be set even when the ref is found.
* Only use out_info if out_has_info is set. */
gboolean
flatpak_remote_state_lookup_ref (FlatpakRemoteState *self,
const char *ref,
char **out_checksum,
GVariant **out_variant,
gboolean *out_has_info,
VarRefInfoRef *out_info,
GError **error)
{
if (!flatpak_remote_state_allow_ref (self, ref))
Expand All @@ -377,7 +379,9 @@ flatpak_remote_state_lookup_ref (FlatpakRemoteState *self,
if (!flatpak_remote_state_ensure_summary (self, error))
return FALSE;

if (!flatpak_summary_lookup_ref (self->summary, self->collection_id, ref, out_checksum, out_variant))
if (out_has_info)
*out_has_info = TRUE;
if (!flatpak_summary_lookup_ref (self->summary, self->collection_id, ref, out_checksum, out_info))
{
if (self->collection_id != NULL)
return flatpak_fail_error (error, FLATPAK_ERROR_REF_NOT_FOUND,
Expand All @@ -396,6 +400,11 @@ flatpak_remote_state_lookup_ref (FlatpakRemoteState *self,

if (!flatpak_remote_state_lookup_cache (self, ref, NULL, NULL, NULL, NULL, error))
return FALSE;

if (out_checksum)
*out_checksum = NULL;
if (out_has_info)
*out_has_info = FALSE;
}

return TRUE;
Expand Down Expand Up @@ -3692,7 +3701,7 @@ flatpak_dir_find_latest_rev (FlatpakDir *self,
}
else
{
if (!flatpak_remote_state_lookup_ref (state, ref, &latest_rev, NULL, error))
if (!flatpak_remote_state_lookup_ref (state, ref, &latest_rev, NULL, NULL, error))
return FALSE;
if (latest_rev == NULL)
return flatpak_fail_error (error, FLATPAK_ERROR_REF_NOT_FOUND,
Expand Down Expand Up @@ -5285,15 +5294,16 @@ flatpak_dir_mirror_oci (FlatpakDir *self,
g_autofree char *registry_uri = NULL;
g_autofree char *oci_digest = NULL;
g_autofree char *latest_rev = NULL;
g_autoptr(GVariant) summary_element = NULL;
g_autoptr(GVariant) metadata = NULL;
g_autofree char *oci_repository = NULL;
VarRefInfoRef latest_rev_info;
VarMetadataRef metadata;
gboolean has_info;
const char *oci_repository = NULL;
gboolean res;

/* We use the summary so that we can reuse any cached json */
if (!flatpak_remote_state_lookup_ref (state, ref, &latest_rev, &summary_element, error))
if (!flatpak_remote_state_lookup_ref (state, ref, &latest_rev, &has_info, &latest_rev_info, error))
return FALSE;
if (latest_rev == NULL)
if (latest_rev == NULL || !has_info)
return flatpak_fail_error (error, FLATPAK_ERROR_REF_NOT_FOUND,
_("Couldn't find latest checksum for ref %s in remote %s"),
ref, state->remote_name);
Expand All @@ -5305,8 +5315,8 @@ flatpak_dir_mirror_oci (FlatpakDir *self,
ref, latest_rev);
}

metadata = g_variant_get_child_value (summary_element, 2);
g_variant_lookup (metadata, "xa.oci-repository", "s", &oci_repository);
metadata = var_ref_info_get_metadata (latest_rev_info);
oci_repository = var_metadata_lookup_string (metadata, "xa.oci-repository", NULL);

oci_digest = g_strconcat ("sha256:", latest_rev, NULL);

Expand Down Expand Up @@ -5351,27 +5361,28 @@ flatpak_dir_pull_oci (FlatpakDir *self,
g_autoptr(FlatpakOciImage) image_config = NULL;
g_autofree char *full_ref = NULL;
g_autofree char *registry_uri = NULL;
g_autofree char *oci_repository = NULL;
const char *oci_repository = NULL;
g_autofree char *oci_digest = NULL;
g_autofree char *checksum = NULL;
g_autoptr(GVariant) summary_element = NULL;
VarRefInfoRef latest_rev_info;
g_autofree char *latest_alt_commit = NULL;
g_autoptr(GVariant) metadata = NULL;
VarMetadataRef metadata;
g_autofree char *latest_rev = NULL;
gboolean has_info;
G_GNUC_UNUSED g_autofree char *latest_commit =
flatpak_dir_read_latest (self, state->remote_name, ref, &latest_alt_commit, cancellable, NULL);
g_autofree char *name = NULL;

/* We use the summary so that we can reuse any cached json */
if (!flatpak_remote_state_lookup_ref (state, ref, &latest_rev, &summary_element, error))
if (!flatpak_remote_state_lookup_ref (state, ref, &latest_rev, &has_info, &latest_rev_info, error))
return FALSE;
if (latest_rev == NULL)
if (latest_rev == NULL || !has_info)
return flatpak_fail_error (error, FLATPAK_ERROR_REF_NOT_FOUND,
_("Couldn't find latest checksum for ref %s in remote %s"),
ref, state->remote_name);

metadata = g_variant_get_child_value (summary_element, 2);
g_variant_lookup (metadata, "xa.oci-repository", "s", &oci_repository);
metadata = var_ref_info_get_metadata (latest_rev_info);
oci_repository = var_metadata_lookup_string (metadata, "xa.oci-repository", NULL);

oci_digest = g_strconcat ("sha256:", latest_rev, NULL);

Expand Down Expand Up @@ -5569,7 +5580,7 @@ flatpak_dir_pull (FlatpakDir *self,
}
else
{
flatpak_remote_state_lookup_ref (state, ref, &rev, NULL, error);
flatpak_remote_state_lookup_ref (state, ref, &rev, NULL, NULL, error);
if (rev == NULL && error != NULL && *error == NULL)
flatpak_fail_error (error, FLATPAK_ERROR_REF_NOT_FOUND, _("Couldn't find latest checksum for ref %s in remote %s"),
ref, state->remote_name);
Expand Down Expand Up @@ -11351,7 +11362,7 @@ flatpak_dir_remote_has_ref (FlatpakDir *self,
return FALSE;
}

return flatpak_remote_state_lookup_ref (state, ref, NULL, NULL, NULL);
return flatpak_remote_state_lookup_ref (state, ref, NULL, NULL, NULL, NULL);
}

static void
Expand Down Expand Up @@ -13970,7 +13981,7 @@ flatpak_dir_fetch_remote_commit (FlatpakDir *self,
if (state == NULL)
return NULL;

if (!flatpak_remote_state_lookup_ref (state, ref, &latest_commit, NULL, error))
if (!flatpak_remote_state_lookup_ref (state, ref, &latest_commit, NULL, NULL, error))
return NULL;
if (latest_commit == NULL)
{
Expand Down Expand Up @@ -14272,7 +14283,7 @@ flatpak_dir_find_remote_related_for_metadata (FlatpakDir *self,

extension_ref = g_build_filename ("runtime", extension, parts[2], branch, NULL);

if (flatpak_remote_state_lookup_ref (state, extension_ref, &checksum, NULL, NULL))
if (flatpak_remote_state_lookup_ref (state, extension_ref, &checksum, NULL, NULL, NULL))
{
if (flatpak_filters_allow_ref (NULL, masked, extension_ref))
add_related (self, related, extension, extension_collection_id, extension_ref, checksum,
Expand All @@ -14286,7 +14297,7 @@ flatpak_dir_find_remote_related_for_metadata (FlatpakDir *self,
{
g_autofree char *subref_checksum = NULL;

if (flatpak_remote_state_lookup_ref (state, refs[j], &subref_checksum, NULL, NULL) &&
if (flatpak_remote_state_lookup_ref (state, refs[j], &subref_checksum, NULL, NULL, NULL) &&
flatpak_filters_allow_ref (NULL, masked, refs[j]))
add_related (self, related, extension, extension_collection_id, refs[j], subref_checksum,
no_autodownload, download_if, autoprune_unless, autodelete, locale_subset);
Expand Down
11 changes: 6 additions & 5 deletions common/flatpak-transaction.c
Expand Up @@ -29,6 +29,7 @@
#include "flatpak-installation-private.h"
#include "flatpak-transaction-private.h"
#include "flatpak-utils-private.h"
#include "flatpak-variant-impl-private.h"

/**
* SECTION:flatpak-transaction
Expand Down Expand Up @@ -2315,7 +2316,7 @@ flatpak_transaction_add_auto_install (FlatpakTransaction *self,
g_autoptr(FlatpakRemoteState) state = flatpak_transaction_ensure_remote_state (self, FLATPAK_TRANSACTION_OPERATION_UPDATE, remote, NULL);

if (state != NULL &&
flatpak_remote_state_lookup_ref (state, ref, NULL, NULL, NULL))
flatpak_remote_state_lookup_ref (state, ref, NULL, NULL, NULL, NULL))
{
g_debug ("Auto adding install of %s from remote %s", ref, remote);
if (!flatpak_transaction_add_ref (self, remote, ref, NULL, NULL, NULL,
Expand Down Expand Up @@ -2503,7 +2504,8 @@ resolve_op_from_metadata (FlatpakTransaction *self,
const char *metadata = NULL;
g_autoptr(GVariant) sparse_cache = NULL;
g_autoptr(GError) local_error = NULL;
g_autoptr(GVariant) summary_metadata = NULL;
VarRefInfoRef info;
gboolean has_info;

if (!flatpak_remote_state_lookup_cache (state, op->ref, &download_size, &installed_size, &metadata, NULL, &local_error))
{
Expand All @@ -2513,9 +2515,8 @@ resolve_op_from_metadata (FlatpakTransaction *self,
else
metadata_bytes = g_bytes_new (metadata, strlen (metadata) + 1);

flatpak_remote_state_lookup_ref (state, op->ref, NULL, &summary_metadata, NULL);
if (summary_metadata)
op->summary_metadata = g_variant_get_child_value (summary_metadata, 2);
if (flatpak_remote_state_lookup_ref (state, op->ref, NULL, &has_info, &info, NULL) && has_info)
op->summary_metadata = var_metadata_dup_to_gvariant (var_ref_info_get_metadata (info));

op->installed_size = installed_size;
op->download_size = download_size;
Expand Down
11 changes: 6 additions & 5 deletions common/flatpak-utils-private.h
Expand Up @@ -32,6 +32,7 @@
#include "flatpak-context-private.h"
#include "flatpak-error.h"
#include "flatpak-utils-http-private.h"
#include "flatpak-variant-private.h"
#include <ostree.h>
#include <json-glib/json-glib.h>

Expand Down Expand Up @@ -157,11 +158,11 @@ GVariant *flatpak_repo_load_summary (OstreeRepo *repo,
char ** flatpak_summary_match_subrefs (GVariant *summary,
const char *collection_id,
const char *ref);
gboolean flatpak_summary_lookup_ref (GVariant *summary,
const char *collection_id,
const char *ref,
char **out_checksum,
GVariant **out_variant);
gboolean flatpak_summary_lookup_ref (GVariant *summary,
const char *collection_id,
const char *ref,
char **out_checksum,
VarRefInfoRef *out_info);

gboolean flatpak_name_matches_one_wildcard_prefix (const char *string,
const char * const *maybe_wildcard_prefixes,
Expand Down
15 changes: 7 additions & 8 deletions common/flatpak-utils.c
Expand Up @@ -48,7 +48,6 @@
#include "flatpak-run-private.h"
#include "flatpak-utils-base-private.h"
#include "flatpak-utils-private.h"
#include "flatpak-variant-private.h"
#include "flatpak-variant-impl-private.h"
#include "libglnx/libglnx.h"
#include "valgrind-private.h"
Expand Down Expand Up @@ -2727,11 +2726,11 @@ flatpak_summary_match_subrefs (GVariant *summary_v,
}

gboolean
flatpak_summary_lookup_ref (GVariant *summary_v,
const char *collection_id,
const char *ref,
char **out_checksum,
GVariant **out_variant)
flatpak_summary_lookup_ref (GVariant *summary_v,
const char *collection_id,
const char *ref,
char **out_checksum,
VarRefInfoRef *out_info)
{
VarSummaryRef summary;
VarRefMapRef ref_map;
Expand All @@ -2755,8 +2754,8 @@ flatpak_summary_lookup_ref (GVariant *summary_v,
if (out_checksum)
*out_checksum = ostree_checksum_from_bytes (checksum_bytes);

if (out_variant)
*out_variant = var_ref_info_dup_to_gvariant (info);
if (out_info)
*out_info = info;

return TRUE;
}
Expand Down

0 comments on commit 61da44a

Please sign in to comment.