summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGiuseppe Scrivano <gscrivan@redhat.com>2014-11-06 13:37:30 +0100
committerColin Walters <walters@verbum.org>2014-11-12 21:20:28 -0500
commit5546c4d2fc5f804854c4ff3e1d31b7c951e26825 (patch)
tree69539af3ef0f13099250b90e743682677295c57f /src
parentd48aca5645807c33fb1d6be466b891989aeca067 (diff)
downloadostree-5546c4d2fc5f804854c4ff3e1d31b7c951e26825.tar.gz
ostree-metalink: use _ostree_fetcher_contents_membuf_sync
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Diffstat (limited to 'src')
-rw-r--r--src/libostree/ostree-metalink.c103
1 files changed, 38 insertions, 65 deletions
diff --git a/src/libostree/ostree-metalink.c b/src/libostree/ostree-metalink.c
index ee798fa9..7e37c8c9 100644
--- a/src/libostree/ostree-metalink.c
+++ b/src/libostree/ostree-metalink.c
@@ -579,67 +579,6 @@ start_target_request_phase (OstreeMetalinkRequest *self,
}
static void
-on_metalink_bytes_read (GObject *src,
- GAsyncResult *result,
- gpointer user_data)
-{
- GError *local_error = NULL;
- GTask *task = user_data;
- OstreeMetalinkRequest *self = g_task_get_task_data (task);
- gs_unref_bytes GBytes *bytes = NULL;
- gsize len;
- const guint8 *data;
-
- bytes = g_input_stream_read_bytes_finish ((GInputStream*)src,
- result, &local_error);
- if (!bytes)
- goto out;
-
- data = g_bytes_get_data (bytes, &len);
-
- if (len == 0)
- {
- if (!start_target_request_phase (self, &local_error))
- goto out;
- }
- else
- {
- if (!g_markup_parse_context_parse (self->parser, (const char*)data, len, &local_error))
- goto out;
-
- g_input_stream_read_bytes_async ((GInputStream*)src, 8192, G_PRIORITY_DEFAULT,
- g_task_get_cancellable (task),
- on_metalink_bytes_read, task);
- }
-
- out:
- if (local_error)
- g_task_return_error (task, local_error);
-}
-
-static void
-on_retrieved_metalink (GObject *src,
- GAsyncResult *result,
- gpointer user_data)
-{
- GError *local_error = NULL;
- GTask *task = user_data;
- gs_unref_object GInputStream *metalink_stream = NULL;
-
- metalink_stream = _ostree_fetcher_stream_uri_finish ((OstreeFetcher*)src, result, &local_error);
- if (!metalink_stream)
- goto out;
-
- g_input_stream_read_bytes_async (metalink_stream, 8192, G_PRIORITY_DEFAULT,
- g_task_get_cancellable (task),
- on_metalink_bytes_read, task);
-
- out:
- if (local_error)
- g_task_return_error (task, local_error);
-}
-
-static void
ostree_metalink_request_unref (gpointer data)
{
OstreeMetalinkRequest *request = data;
@@ -706,6 +645,24 @@ on_metalink_fetched (GObject *src,
g_main_loop_quit (data->loop);
}
+static gboolean
+on_metalink_bytes_read (OstreeMetalinkRequest *self,
+ OstreeMetalinkRequest *request,
+ FetchMetalinkSyncData *sync_data,
+ GBytes *bytes,
+ GError **error)
+{
+ gsize len;
+ const guint8 *data = g_bytes_get_data (bytes, &len);
+ if (!g_markup_parse_context_parse (self->parser, (const char*)data, len, error))
+ return FALSE;
+
+ if (!start_target_request_phase (self, error))
+ return FALSE;
+
+ return TRUE;
+}
+
gboolean
_ostree_metalink_request_sync (OstreeMetalink *self,
GMainLoop *loop,
@@ -718,6 +675,7 @@ _ostree_metalink_request_sync (OstreeMetalink *self,
OstreeMetalinkRequest *request = g_new0 (OstreeMetalinkRequest, 1);
FetchMetalinkSyncData data = { 0, };
GTask *task = g_task_new (self, cancellable, on_metalink_fetched, &data);
+ GBytes *out_contents = NULL;
data.out_target_uri = out_target_uri;
data.out_data = out_data;
@@ -732,10 +690,25 @@ _ostree_metalink_request_sync (OstreeMetalink *self,
request->parser = g_markup_parse_context_new (&metalink_parser, G_MARKUP_PREFIX_ERROR_POSITION, task, NULL);
g_task_set_task_data (task, request, ostree_metalink_request_unref);
- _ostree_fetcher_stream_uri_async (self->fetcher, self->uri,
- self->max_size, cancellable,
- on_retrieved_metalink, task);
- g_main_loop_run (loop);
+
+ if (! _ostree_fetcher_contents_membuf_sync (self->fetcher,
+ self->uri,
+ FALSE,
+ FALSE,
+ &out_contents,
+ loop,
+ NULL,
+ self->max_size,
+ cancellable,
+ error))
+ goto out;
+
+ if (! on_metalink_bytes_read (request, request, &data, out_contents, error))
+ goto out;
+
+ g_main_loop_run (data.loop);
+
+ out:
return data.success;
}