Skip to content

Commit

Permalink
Optionally return commit id in flatpak_remote_state_lookup_cache
Browse files Browse the repository at this point in the history
This will only work if xa.commits is in the metadata, which is only
available in the p2p case and was only added recently.
  • Loading branch information
alexlarsson committed Oct 16, 2019
1 parent ebd7e36 commit 654c4d8
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/flatpak-builtins-remote-ls.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ ls_remote (GHashTable *refs_hash, const char **arches, const char *app_runtime,

if (!flatpak_remote_state_lookup_cache (state, ref,
&download_size, &installed_size, &metadata,
error))
NULL, error))
return FALSE;

metakey = g_key_file_new ();
Expand Down
1 change: 1 addition & 0 deletions common/flatpak-dir-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ gboolean flatpak_remote_state_lookup_cache (FlatpakRemoteState *self,
guint64 *download_size,
guint64 *installed_size,
const char **metadata,
GVariant **maybe_commit,
GError **error);
GVariant *flatpak_remote_state_lookup_sparse_cache (FlatpakRemoteState *self,
const char *ref,
Expand Down
19 changes: 17 additions & 2 deletions common/flatpak-dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ flatpak_remote_state_lookup_ref (FlatpakRemoteState *self,
if (!flatpak_remote_state_ensure_metadata (self, error))
return FALSE;

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

Expand Down Expand Up @@ -442,10 +442,12 @@ flatpak_remote_state_lookup_cache (FlatpakRemoteState *self,
guint64 *download_size,
guint64 *installed_size,
const char **metadata,
GVariant **maybe_commit,
GError **error)
{
g_autoptr(GVariant) cache_v = NULL;
g_autoptr(GVariant) cache = NULL;
g_autoptr(GVariant) commits = NULL;
g_autoptr(GVariant) res = NULL;
g_autoptr(GVariant) refdata = NULL;
int pos;
Expand All @@ -461,6 +463,8 @@ flatpak_remote_state_lookup_cache (FlatpakRemoteState *self,
return FALSE;
}

commits = g_variant_lookup_value (self->metadata, "xa.commits", NULL);

cache = g_variant_get_child_value (cache_v, 0);

if (!flatpak_variant_bsearch_str (cache, ref, &pos))
Expand Down Expand Up @@ -490,6 +494,17 @@ flatpak_remote_state_lookup_cache (FlatpakRemoteState *self,
if (metadata)
g_variant_get_child (res, 2, "&s", metadata);


refdata = g_variant_get_child_value (cache, pos);

if (maybe_commit)
{
if (commits)
*maybe_commit = g_variant_get_child_value (commits, pos);
else
*maybe_commit = NULL;
}

return TRUE;
}

Expand Down Expand Up @@ -14141,7 +14156,7 @@ flatpak_dir_find_remote_related (FlatpakDir *self,

if (flatpak_remote_state_lookup_cache (state, ref,
NULL, NULL, &metadata,
NULL) &&
NULL, NULL) &&
g_key_file_load_from_data (metakey, metadata, -1, 0, NULL))
related = flatpak_dir_find_remote_related_for_metadata (self, state, ref, metakey, cancellable, error);
else
Expand Down
4 changes: 2 additions & 2 deletions common/flatpak-installation.c
Original file line number Diff line number Diff line change
Expand Up @@ -2406,7 +2406,7 @@ flatpak_installation_fetch_remote_size_sync (FlatpakInstallation *self,

return flatpak_remote_state_lookup_cache (state, full_ref,
download_size, installed_size, NULL,
error);
NULL, error);
}

/**
Expand Down Expand Up @@ -2447,7 +2447,7 @@ flatpak_installation_fetch_remote_metadata_sync (FlatpakInstallation *self,

if (!flatpak_remote_state_lookup_cache (state, full_ref,
NULL, NULL, &res,
error))
NULL, error))
return NULL;

return g_bytes_new (res, strlen (res));
Expand Down
2 changes: 1 addition & 1 deletion common/flatpak-remote-ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ flatpak_remote_ref_new (FlatpakCollectionRef *coll_ref,
if (state &&
!flatpak_remote_state_lookup_cache (state, full_ref,
&download_size, &installed_size, &metadata,
NULL))
NULL, NULL))
{
g_debug ("Can't find metadata for ref %s", full_ref);
}
Expand Down
2 changes: 1 addition & 1 deletion common/flatpak-transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -2384,7 +2384,7 @@ resolve_ops (FlatpakTransaction *self,

/* TODO: This only gets the metadata for the latest only, we need to handle the case
where the user specified a commit, or p2p doesn't have the latest commit available */
if (!flatpak_remote_state_lookup_cache (state, op->ref, &download_size, &installed_size, &metadata, &local_error))
if (!flatpak_remote_state_lookup_cache (state, op->ref, &download_size, &installed_size, &metadata, NULL, &local_error))
{
g_message (_("Warning: Can't find %s metadata for dependencies: %s"), op->ref, local_error->message);
g_clear_error (&local_error);
Expand Down

0 comments on commit 654c4d8

Please sign in to comment.