[ostree] metalink: have a single entry to the metalink module
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] metalink: have a single entry to the metalink module
- Date: Thu, 13 Nov 2014 02:42:08 +0000 (UTC)
commit c832e9b7516ae6dfc33a8ff59fceba081872a8d9
Author: Giuseppe Scrivano <gscrivan redhat com>
Date: Tue Nov 4 17:33:41 2014 +0100
metalink: have a single entry to the metalink module
Replace _ostree_metalink_request_async with a synchronous version.
Signed-off-by: Giuseppe Scrivano <gscrivan redhat com>
src/libostree/ostree-metalink.c | 86 +++++++++++++++++++++++++++-----------
src/libostree/ostree-metalink.h | 18 +++-----
src/libostree/ostree-repo-pull.c | 52 +++--------------------
3 files changed, 75 insertions(+), 81 deletions(-)
---
diff --git a/src/libostree/ostree-metalink.c b/src/libostree/ostree-metalink.c
index 00cfb2c..ee798fa 100644
--- a/src/libostree/ostree-metalink.c
+++ b/src/libostree/ostree-metalink.c
@@ -658,33 +658,21 @@ static const GMarkupParser metalink_parser = {
NULL
};
-void
-_ostree_metalink_request_async (OstreeMetalink *self,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+typedef struct
{
- GTask *task = g_task_new (self, cancellable, callback, user_data);
- OstreeMetalinkRequest *request = g_new0 (OstreeMetalinkRequest, 1);
-
- request->metalink = g_object_ref (self);
- request->urls = g_ptr_array_new_with_free_func ((GDestroyNotify) soup_uri_free);
- request->task = task; /* Unowned */
+ SoupURI **out_target_uri;
+ GFile **out_data;
+ gboolean success;
+ GError **error;
+ GMainLoop *loop;
+} FetchMetalinkSyncData;
- 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);
-}
-
-gboolean
-_ostree_metalink_request_finish (OstreeMetalink *self,
- GAsyncResult *result,
- SoupURI **out_target_uri,
- GFile **out_data,
- GError **error)
+static gboolean
+ostree_metalink_request_finish (OstreeMetalink *self,
+ GAsyncResult *result,
+ SoupURI **out_target_uri,
+ GFile **out_data,
+ GError **error)
{
OstreeMetalinkRequest *request;
@@ -703,6 +691,54 @@ _ostree_metalink_request_finish (OstreeMetalink *self,
return FALSE;
}
+static void
+on_metalink_fetched (GObject *src,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ FetchMetalinkSyncData *data = user_data;
+
+ data->success = ostree_metalink_request_finish ((OstreeMetalink*)src,
+ result,
+ data->out_target_uri,
+ data->out_data,
+ data->error);
+ g_main_loop_quit (data->loop);
+}
+
+gboolean
+_ostree_metalink_request_sync (OstreeMetalink *self,
+ GMainLoop *loop,
+ SoupURI **out_target_uri,
+ GFile **out_data,
+ SoupURI **fetching_sync_uri,
+ GCancellable *cancellable,
+ GError **error)
+{
+ OstreeMetalinkRequest *request = g_new0 (OstreeMetalinkRequest, 1);
+ FetchMetalinkSyncData data = { 0, };
+ GTask *task = g_task_new (self, cancellable, on_metalink_fetched, &data);
+
+ data.out_target_uri = out_target_uri;
+ data.out_data = out_data;
+ data.loop = loop;
+ data.error = error;
+ *fetching_sync_uri = _ostree_metalink_get_uri (self);
+
+ request->metalink = g_object_ref (self);
+ request->urls = g_ptr_array_new_with_free_func ((GDestroyNotify) soup_uri_free);
+ request->task = task; /* Unowned */
+
+ 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);
+ return data.success;
+}
+
SoupURI *
_ostree_metalink_get_uri (OstreeMetalink *self)
{
diff --git a/src/libostree/ostree-metalink.h b/src/libostree/ostree-metalink.h
index 0c26ade..6eb59e5 100644
--- a/src/libostree/ostree-metalink.h
+++ b/src/libostree/ostree-metalink.h
@@ -50,17 +50,13 @@ OstreeMetalink *_ostree_metalink_new (OstreeFetcher *fetcher,
SoupURI *_ostree_metalink_get_uri (OstreeMetalink *self);
-void _ostree_metalink_request_async (OstreeMetalink *self,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-
-gboolean _ostree_metalink_request_finish (OstreeMetalink *self,
- GAsyncResult *result,
- SoupURI **out_target_uri,
- GFile **out_data,
- GError **error);
-
+gboolean _ostree_metalink_request_sync (OstreeMetalink *self,
+ GMainLoop *loop,
+ SoupURI **out_target_uri,
+ GFile **out_data,
+ SoupURI **fetching_sync_uri,
+ GCancellable *cancellable,
+ GError **error);
G_END_DECLS
#endif
diff --git a/src/libostree/ostree-repo-pull.c b/src/libostree/ostree-repo-pull.c
index 7bd1557..7a7ed46 100644
--- a/src/libostree/ostree-repo-pull.c
+++ b/src/libostree/ostree-repo-pull.c
@@ -303,49 +303,6 @@ fetch_uri_contents_utf8_sync (OtPullData *pull_data,
return ret;
}
-typedef struct
-{
- OtPullData *pull_data;
- SoupURI **out_target_uri;
- GFile **out_data;
- gboolean success;
-} FetchMetalinkSyncData;
-
-static void
-on_metalink_fetched (GObject *src,
- GAsyncResult *result,
- gpointer user_data)
-{
- FetchMetalinkSyncData *data = user_data;
-
- data->success = _ostree_metalink_request_finish ((OstreeMetalink*)src, result,
- data->out_target_uri, data->out_data,
- data->pull_data->async_error);
- g_main_loop_quit (data->pull_data->loop);
-}
-
-static gboolean
-request_metalink_sync (OtPullData *pull_data,
- OstreeMetalink *metalink,
- SoupURI **out_target_uri,
- GFile **out_data,
- GCancellable *cancellable,
- GError **error)
-{
- FetchMetalinkSyncData data = { 0, };
-
- data.pull_data = pull_data;
- data.out_target_uri = out_target_uri;
- data.out_data = out_data;
-
- pull_data->fetching_sync_uri = _ostree_metalink_get_uri (metalink);
- _ostree_metalink_request_async (metalink, cancellable, on_metalink_fetched, &data);
-
- g_main_loop_run (pull_data->loop);
-
- return data.success;
-}
-
static void
enqueue_one_object_request (OtPullData *pull_data,
const char *checksum,
@@ -1387,8 +1344,13 @@ ostree_repo_pull_with_options (OstreeRepo *self,
OSTREE_MAX_METADATA_SIZE, metalink_uri);
soup_uri_free (metalink_uri);
- if (!request_metalink_sync (pull_data, metalink, &target_uri, &metalink_data,
- cancellable, error))
+ if (! _ostree_metalink_request_sync (metalink,
+ pull_data->loop,
+ &target_uri,
+ &metalink_data,
+ &pull_data->fetching_sync_uri,
+ cancellable,
+ error))
goto out;
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]