transaction: Use FlatpakRemoteState to look up metadata

Closes: #1575
Approved by: alexlarsson
This commit is contained in:
Alexander Larsson
2018-04-13 11:48:30 +02:00
committed by Atomic Bot
parent 37cdfa1d1d
commit d791625d77
4 changed files with 17 additions and 78 deletions

View File

@@ -563,7 +563,7 @@ flatpak_transaction_add_ref (FlatpakTransaction *self,
if (metadata == NULL && remote != NULL)
{
if (flatpak_dir_fetch_ref_cache (self->dir, remote, ref, NULL, NULL, &remote_metadata, NULL, &local_error))
if (flatpak_remote_state_lookup_cache (state, ref, NULL, NULL, &remote_metadata, NULL, &local_error))
metadata = remote_metadata;
else
{

View File

@@ -10714,66 +10714,6 @@ flatpak_dir_fetch_remote_commit (FlatpakDir *self,
return g_steal_pointer (&commit_variant);
}
gboolean
flatpak_dir_fetch_ref_cache (FlatpakDir *self,
const char *remote_name,
const char *ref,
guint64 *download_size,
guint64 *installed_size,
char **metadata,
GCancellable *cancellable,
GError **error)
{
g_autoptr(GVariant) cache_v = NULL;
g_autoptr(GVariant) cache = NULL;
g_autoptr(GVariant) res = NULL;
g_autoptr(GVariant) refdata = NULL;
int pos;
g_autoptr(GError) local_error = NULL;
if (!flatpak_dir_lookup_repo_metadata (self, remote_name, cancellable, &local_error,
"xa.cache", "@*", &cache_v))
{
if (local_error == NULL)
g_set_error_literal (&local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
_("No flatpak cache in remote summary"));
g_propagate_error (error, g_steal_pointer (&local_error));
return FALSE;
}
cache = g_variant_get_child_value (cache_v, 0);
if (!flatpak_variant_bsearch_str (cache, ref, &pos))
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
_("No entry for %s in remote summary flatpak cache "), ref);
return FALSE;
}
refdata = g_variant_get_child_value (cache, pos);
res = g_variant_get_child_value (refdata, 1);
if (installed_size)
{
guint64 v;
g_variant_get_child (res, 0, "t", &v);
*installed_size = GUINT64_FROM_BE (v);
}
if (download_size)
{
guint64 v;
g_variant_get_child (res, 1, "t", &v);
*download_size = GUINT64_FROM_BE (v);
}
if (metadata)
g_variant_get_child (res, 2, "s", metadata);
return TRUE;
}
void
flatpak_related_free (FlatpakRelated *self)
{

View File

@@ -690,14 +690,6 @@ FlatpakRemoteState * flatpak_dir_get_remote_state_optional (FlatpakDir *self,
const char *remote,
GCancellable *cancellable,
GError **error);
gboolean flatpak_dir_fetch_ref_cache (FlatpakDir *self,
const char *remote_name,
const char *ref,
guint64 *download_size,
guint64 *installed_size,
char **metadata,
GCancellable *cancellable,
GError **error);
GPtrArray * flatpak_dir_find_remote_related (FlatpakDir *dir,
const char *remote_name,
const char *ref,

View File

@@ -1936,17 +1936,20 @@ flatpak_installation_fetch_remote_size_sync (FlatpakInstallation *self,
GError **error)
{
g_autoptr(FlatpakDir) dir = NULL;
g_autoptr(FlatpakRemoteState) state = NULL;
g_autofree char *full_ref = flatpak_ref_format_ref (ref);
dir = flatpak_installation_get_dir (self, error);
if (dir == NULL)
return FALSE;
return flatpak_dir_fetch_ref_cache (dir, remote_name, full_ref,
download_size, installed_size,
NULL,
cancellable,
error);
state = flatpak_dir_get_remote_state (dir, remote_name, cancellable, error);
if (state == NULL)
return FALSE;
return flatpak_remote_state_lookup_cache (state, full_ref,
download_size, installed_size, NULL,
cancellable, error);
}
/**
@@ -1970,6 +1973,7 @@ flatpak_installation_fetch_remote_metadata_sync (FlatpakInstallation *self,
GError **error)
{
g_autoptr(FlatpakDir) dir = NULL;
g_autoptr(FlatpakRemoteState) state = NULL;
g_autofree char *full_ref = flatpak_ref_format_ref (ref);
char *res = NULL;
@@ -1977,10 +1981,13 @@ flatpak_installation_fetch_remote_metadata_sync (FlatpakInstallation *self,
if (dir == NULL)
return NULL;
if (!flatpak_dir_fetch_ref_cache (dir, remote_name, full_ref,
NULL, NULL,
&res,
cancellable, error))
state = flatpak_dir_get_remote_state (dir, remote_name, cancellable, error);
if (state == NULL)
return FALSE;
if (!flatpak_remote_state_lookup_cache (state, full_ref,
NULL, NULL, &res,
cancellable, error))
return NULL;
return g_bytes_new_take (res, strlen (res));