common: Add (and use) xdg_app_summary_lookup_ref helper

This commit is contained in:
Alexander Larsson
2016-04-25 13:32:01 +02:00
parent f340105b4c
commit 2d74810cbc
3 changed files with 33 additions and 3 deletions

View File

@@ -2791,7 +2791,6 @@ xdg_app_dir_find_remote_ref (XdgAppDir *self,
g_autoptr(GVariant) summary = NULL;
g_autoptr(GVariant) refs = NULL;
g_autoptr(GBytes) summary_bytes = NULL;
int pos;
if (!xdg_app_dir_ensure_repo (self, NULL, error))
return NULL;
@@ -2847,14 +2846,14 @@ xdg_app_dir_find_remote_ref (XdgAppDir *self,
summary = g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT, summary_bytes, FALSE);
refs = g_variant_get_child_value (summary, 0);
if (app_ref && xdg_app_variant_bsearch_str (refs, app_ref, &pos))
if (app_ref && xdg_app_summary_lookup_ref (summary, app_ref, NULL))
{
if (is_app)
*is_app = TRUE;
return g_steal_pointer (&app_ref);
}
if (runtime_ref && xdg_app_variant_bsearch_str (refs, runtime_ref, &pos))
if (runtime_ref && xdg_app_summary_lookup_ref (summary, runtime_ref, NULL))
{
if (is_app)
*is_app = FALSE;

View File

@@ -1456,6 +1456,34 @@ xdg_app_variant_bsearch_str (GVariant *array,
return FALSE;
}
gboolean
xdg_app_summary_lookup_ref (GVariant *summary, const char *ref, char **out_checksum)
{
g_autoptr(GVariant) refs = g_variant_get_child_value (summary, 0);
int pos;
g_autoptr(GVariant) refdata = NULL;
g_autoptr(GVariant) reftargetdata = NULL;
g_autoptr(GVariant) commit_data = NULL;
guint64 commit_size;
g_autoptr(GVariant) commit_csum_v = NULL;
g_autoptr(GBytes) commit_bytes = NULL;
if (!xdg_app_variant_bsearch_str (refs, ref, &pos))
return FALSE;
refdata = g_variant_get_child_value (refs, pos);
reftargetdata = g_variant_get_child_value (refdata, 1);
g_variant_get (reftargetdata, "(t@ay@a{sv})", &commit_size, &commit_csum_v, NULL);
if (!ostree_validate_structureof_csum_v (commit_csum_v, NULL))
return FALSE;
if (out_checksum)
*out_checksum = ostree_checksum_from_bytes_v (commit_csum_v);
return TRUE;
}
gboolean
xdg_app_repo_set_title (OstreeRepo *repo,
const char *title,

View File

@@ -48,6 +48,9 @@ GBytes * xdg_app_read_stream (GInputStream *in,
gboolean xdg_app_variant_bsearch_str (GVariant *array,
const char *str,
int *out_pos);
gboolean xdg_app_summary_lookup_ref (GVariant *summary,
const char *ref,
char **out_checksum);
gboolean xdg_app_has_name_prefix (const char *string,
const char *name);