diff options
author | Colin Walters <walters@verbum.org> | 2013-07-01 22:35:54 -0400 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2013-07-01 22:43:17 -0400 |
commit | a93f2b8d160058f7c250a0ce1b16a73b83b4f5ae (patch) | |
tree | f2500bc19f6236727b4b426ceffbedac489ebd9f | |
parent | dc0f3c3dcbdd63d6a41ebc172b38c65576db9cd3 (diff) | |
download | ostree-a93f2b8d160058f7c250a0ce1b16a73b83b4f5ae.tar.gz |
pull: Make fetcher work for file:/// URIs too
Even if very suboptimally, for now; we copy the files, then copy them
again.
The obvious long term plan is to merge pull-local and pull together,
but truly optimizing that requires the pull code to know how to use
the OstreeRepo APIs when operating on local repositories (as
pull-local does), rather than assuming the remote is an archive-z
fetched over HTTP.
-rw-r--r-- | src/ostree/ostree-fetcher.c | 62 | ||||
-rwxr-xr-x | tests/archive-test.sh | 11 |
2 files changed, 45 insertions, 28 deletions
diff --git a/src/ostree/ostree-fetcher.c b/src/ostree/ostree-fetcher.c index 6d4b5dbb..cb621310 100644 --- a/src/ostree/ostree-fetcher.c +++ b/src/ostree/ostree-fetcher.c @@ -189,49 +189,52 @@ on_request_sent (GObject *object, { OstreeFetcherPendingURI *pending = user_data; GError *local_error = NULL; - ot_lobj SoupMessage *msg = NULL; + gs_unref_object SoupMessage *msg = NULL; + GOutputStreamSpliceFlags flags = G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET; pending->request_body = soup_request_send_finish ((SoupRequest*) object, result, &local_error); - msg = soup_request_http_get_message ((SoupRequestHTTP*) object); if (!pending->request_body) { pending->state = OSTREE_FETCHER_STATE_COMPLETE; g_simple_async_result_take_error (pending->result, local_error); g_simple_async_result_complete (pending->result); + return; } - else if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) - { - g_set_error (&local_error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Server returned status %u: %s", - msg->status_code, soup_status_get_phrase (msg->status_code)); - g_simple_async_result_take_error (pending->result, local_error); - g_simple_async_result_complete (pending->result); - } - else + + if (SOUP_IS_REQUEST_HTTP (object)) { - GOutputStreamSpliceFlags flags = G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET; - - pending->state = OSTREE_FETCHER_STATE_DOWNLOADING; - - pending->content_length = soup_request_get_content_length (pending->request); - - /* TODO - make this async */ - if (!ostree_create_temp_regular_file (pending->self->tmpdir, - NULL, NULL, - &pending->tmpfile, - &pending->out_stream, - NULL, &local_error)) + msg = soup_request_http_get_message ((SoupRequestHTTP*) object); + if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) { + g_set_error (&local_error, G_IO_ERROR, G_IO_ERROR_FAILED, + "Server returned status %u: %s", + msg->status_code, soup_status_get_phrase (msg->status_code)); g_simple_async_result_take_error (pending->result, local_error); g_simple_async_result_complete (pending->result); return; } + } - g_output_stream_splice_async (pending->out_stream, pending->request_body, flags, G_PRIORITY_DEFAULT, - pending->cancellable, on_splice_complete, pending); + pending->state = OSTREE_FETCHER_STATE_DOWNLOADING; + + pending->content_length = soup_request_get_content_length (pending->request); + + /* TODO - make this async */ + if (!ostree_create_temp_regular_file (pending->self->tmpdir, + NULL, NULL, + &pending->tmpfile, + &pending->out_stream, + NULL, &local_error)) + { + g_simple_async_result_take_error (pending->result, local_error); + g_simple_async_result_complete (pending->result); + return; } + + g_output_stream_splice_async (pending->out_stream, pending->request_body, flags, G_PRIORITY_DEFAULT, + pending->cancellable, on_splice_complete, pending); } void @@ -255,9 +258,12 @@ ostree_fetcher_request_uri_async (OstreeFetcher *self, g_assert_no_error (local_error); pending->refcount++; - g_hash_table_insert (self->message_to_request, - soup_request_http_get_message ((SoupRequestHTTP*)pending->request), - pending); + if (SOUP_IS_REQUEST_HTTP (pending->request)) + { + g_hash_table_insert (self->message_to_request, + soup_request_http_get_message ((SoupRequestHTTP*)pending->request), + pending); + } pending->result = g_simple_async_result_new ((GObject*) self, callback, user_data, diff --git a/tests/archive-test.sh b/tests/archive-test.sh index cd0b2995..62595cfb 100755 --- a/tests/archive-test.sh +++ b/tests/archive-test.sh @@ -39,6 +39,8 @@ cd ${test_tmpdir} ${CMD_PREFIX} ostree --repo=repo2 checkout test2 test2-checkout-from-local-clone cd test2-checkout-from-local-clone assert_file_has_content baz/cow moo +cd ${test_tmpdir} +rm repo2 -rf echo "ok local clone checkout" $OSTREE checkout -U test2 checkout-user-test2 @@ -64,3 +66,12 @@ echo "ok cat-file" cd ${test_tmpdir} $OSTREE fsck echo "ok fsck" + +cd ${test_tmpdir} +mkdir repo2 +${CMD_PREFIX} ostree --repo=repo2 init +${CMD_PREFIX} ostree --repo=repo2 remote add aremote file://$(pwd)/repo test2 +ostree --repo=repo2 pull aremote +ostree --repo=repo2 rev-parse aremote/test2 +ostree --repo=repo2 fsck +echo "ok pull with from file:/// uri" |