Add flatpak_dir_list_remote_refs_decomposed()

This commit is contained in:
Alexander Larsson
2020-11-04 11:27:24 +01:00
committed by Alexander Larsson
parent 7465ba0f18
commit 089a5bebd5
2 changed files with 70 additions and 4 deletions

View File

@@ -920,6 +920,11 @@ gboolean flatpak_dir_list_remote_refs (FlatpakDir *self,
GHashTable **refs,
GCancellable *cancellable,
GError **error);
gboolean flatpak_dir_list_remote_refs_decomposed (FlatpakDir *self,
FlatpakRemoteState *state,
GHashTable **refs,
GCancellable *cancellable,
GError **error);
gboolean flatpak_dir_list_all_remote_refs (FlatpakDir *self,
FlatpakRemoteState *state,
GHashTable **out_all_refs,

View File

@@ -14136,9 +14136,9 @@ flatpak_dir_modify_remote (FlatpakDir *self,
}
static gboolean
remove_unless_in_hash (gpointer key,
gpointer value,
gpointer user_data)
remove_unless_ref_in_hash (gpointer key,
gpointer value,
gpointer user_data)
{
GHashTable *table = user_data;
const char *ref_name = key;
@@ -14190,13 +14190,74 @@ flatpak_dir_list_remote_refs (FlatpakDir *self,
/* Then we remove all remote refs not in the local refs set */
g_hash_table_foreach_remove (*refs,
remove_unless_in_hash,
remove_unless_ref_in_hash,
unprefixed_local_refs);
}
return TRUE;
}
static gboolean
remove_unless_decomposed_in_hash (gpointer key,
gpointer value,
gpointer user_data)
{
GHashTable *table = user_data;
const FlatpakDecomposed *d = key;
return !g_hash_table_contains (table, d);
}
gboolean
flatpak_dir_list_remote_refs_decomposed (FlatpakDir *self,
FlatpakRemoteState *state,
GHashTable **refs,
GCancellable *cancellable,
GError **error)
{
g_autoptr(GError) my_error = NULL;
if (error == NULL)
error = &my_error;
if (!flatpak_dir_list_all_remote_refs_decomposed (self, state, refs,
cancellable, error))
return FALSE;
if (flatpak_dir_get_remote_noenumerate (self, state->remote_name))
{
g_autoptr(GHashTable) decomposed_local_refs =
g_hash_table_new_full ((GHashFunc)flatpak_decomposed_hash, (GEqualFunc)flatpak_decomposed_equal, (GDestroyNotify)flatpak_decomposed_unref, NULL);
g_autoptr(GHashTable) local_refs = NULL;
GHashTableIter hash_iter;
gpointer key;
g_autofree char *refspec_prefix = g_strconcat (state->remote_name, ":.", NULL);
/* For noenumerate remotes, only return data for already locally
* available refs */
if (!ostree_repo_list_refs (self->repo, refspec_prefix, &local_refs,
cancellable, error))
return FALSE;
g_hash_table_iter_init (&hash_iter, local_refs);
while (g_hash_table_iter_next (&hash_iter, &key, NULL))
{
const char *refspec = key;
g_autoptr(FlatpakDecomposed) d = flatpak_decomposed_new_from_refspec (refspec, NULL);
if (d)
g_hash_table_insert (decomposed_local_refs, g_steal_pointer (&d), NULL);
}
/* Then we remove all remote refs not in the local refs set */
g_hash_table_foreach_remove (*refs,
remove_unless_decomposed_in_hash,
decomposed_local_refs);
}
return TRUE;
}
static gboolean
strv_contains_prefix (const gchar * const *strv,
const gchar *str)