Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[merged] Fetcher cleanup #636

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 12 additions & 27 deletions src/libostree/ostree-fetcher-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

typedef struct
{
GInputStream *result_stream;
GBytes *result_buf;
gboolean done;
GError **error;
}
Expand All @@ -41,9 +41,9 @@ fetch_uri_sync_on_complete (GObject *object,
{
FetchUriSyncData *data = user_data;

(void)_ostree_fetcher_request_finish ((OstreeFetcher*)object,
result, NULL, &data->result_stream,
data->error);
(void)_ostree_fetcher_request_to_membuf_finish ((OstreeFetcher*)object,
result, &data->result_buf,
data->error);
data->done = TRUE;
}

Expand All @@ -60,12 +60,11 @@ _ostree_fetcher_mirrored_request_to_membuf (OstreeFetcher *fetcher,
{
gboolean ret = FALSE;
const guint8 nulchar = 0;
g_autoptr(GMemoryOutputStream) buf = NULL;
g_autoptr(GMainContext) mainctx = NULL;
FetchUriSyncData data;
g_assert (error != NULL);

data.result_stream = NULL;
memset (&data, 0, sizeof (data));

if (g_cancellable_set_error_if_cancelled (cancellable, error))
return FALSE;
Expand All @@ -76,13 +75,14 @@ _ostree_fetcher_mirrored_request_to_membuf (OstreeFetcher *fetcher,
data.done = FALSE;
data.error = error;

_ostree_fetcher_request_async (fetcher, mirrorlist, filename, 0, max_size,
OSTREE_FETCHER_DEFAULT_PRIORITY, cancellable,
fetch_uri_sync_on_complete, &data);
_ostree_fetcher_request_to_membuf (fetcher, mirrorlist, filename,
add_nul ? OSTREE_FETCHER_REQUEST_NUL_TERMINATION : 0,
max_size, OSTREE_FETCHER_DEFAULT_PRIORITY,
cancellable, fetch_uri_sync_on_complete, &data);
while (!data.done)
g_main_context_iteration (mainctx, TRUE);

if (!data.result_stream)
if (!data.result_buf)
{
if (allow_noent)
{
Expand All @@ -96,27 +96,12 @@ _ostree_fetcher_mirrored_request_to_membuf (OstreeFetcher *fetcher,
goto out;
}

buf = (GMemoryOutputStream*)g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
if (g_output_stream_splice ((GOutputStream*)buf, data.result_stream,
G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE,
cancellable, error) < 0)
goto out;

if (add_nul)
{
if (!g_output_stream_write ((GOutputStream*)buf, &nulchar, 1, cancellable, error))
goto out;
}

if (!g_output_stream_close ((GOutputStream*)buf, cancellable, error))
goto out;

ret = TRUE;
*out_contents = g_memory_output_stream_steal_as_bytes (buf);
*out_contents = g_steal_pointer (&data.result_buf);
out:
if (mainctx)
g_main_context_pop_thread_default (mainctx);
g_clear_object (&(data.result_stream));
g_clear_pointer (&data.result_buf, (GDestroyNotify)g_bytes_unref);
return ret;
}

Expand Down
Loading