pull: Clean up synchronous fetching code
Fold in fetch_uri to fetch_uri_utf8(), and rename the latter to include _sync as a suffix, since it's synchronous. Improve the status line to show when we're fetching a synchronous URI; previously we just showed "Scanning metadata". https://bugzilla.gnome.org/show_bug.cgi?id=707023
This commit is contained in:
parent
c9d7050d3d
commit
8fce2513e9
|
|
@ -88,7 +88,7 @@ typedef struct {
|
||||||
|
|
||||||
gboolean transaction_resuming;
|
gboolean transaction_resuming;
|
||||||
volatile gint n_scanned_metadata;
|
volatile gint n_scanned_metadata;
|
||||||
guint outstanding_uri_requests;
|
SoupURI *fetching_sync_uri;
|
||||||
|
|
||||||
GThread *metadata_thread;
|
GThread *metadata_thread;
|
||||||
GMainContext *metadata_thread_context;
|
GMainContext *metadata_thread_context;
|
||||||
|
|
@ -187,7 +187,12 @@ uri_fetch_update_status (gpointer user_data)
|
||||||
outstanding_fetches = pull_data->n_outstanding_content_fetches + pull_data->n_outstanding_metadata_fetches;
|
outstanding_fetches = pull_data->n_outstanding_content_fetches + pull_data->n_outstanding_metadata_fetches;
|
||||||
outstanding_stages = pull_data->n_outstanding_content_stage_requests + pull_data->n_outstanding_metadata_stage_requests;
|
outstanding_stages = pull_data->n_outstanding_content_stage_requests + pull_data->n_outstanding_metadata_stage_requests;
|
||||||
|
|
||||||
if (outstanding_fetches)
|
if (pull_data->fetching_sync_uri)
|
||||||
|
{
|
||||||
|
gs_free char *uri_string = soup_uri_to_string (pull_data->fetching_sync_uri, TRUE);
|
||||||
|
g_string_append_printf (status, "Requesting %s", uri_string);
|
||||||
|
}
|
||||||
|
else if (outstanding_fetches)
|
||||||
{
|
{
|
||||||
guint64 bytes_transferred = ostree_fetcher_bytes_transferred (pull_data->fetcher);
|
guint64 bytes_transferred = ostree_fetcher_bytes_transferred (pull_data->fetcher);
|
||||||
guint fetched = pull_data->n_fetched_metadata + pull_data->n_fetched_content;
|
guint fetched = pull_data->n_fetched_metadata + pull_data->n_fetched_content;
|
||||||
|
|
@ -272,7 +277,7 @@ check_outstanding_requests_handle_error (OtPullData *pull_data,
|
||||||
/* This is true in the phase when we're fetching refs */
|
/* This is true in the phase when we're fetching refs */
|
||||||
if (pull_data->metadata_objects_to_scan == NULL)
|
if (pull_data->metadata_objects_to_scan == NULL)
|
||||||
{
|
{
|
||||||
if (pull_data->outstanding_uri_requests == 0)
|
if (!pull_data->fetching_sync_uri)
|
||||||
g_main_loop_quit (pull_data->loop);
|
g_main_loop_quit (pull_data->loop);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -325,71 +330,49 @@ run_mainloop_monitor_fetcher (OtPullData *pull_data)
|
||||||
typedef struct {
|
typedef struct {
|
||||||
OtPullData *pull_data;
|
OtPullData *pull_data;
|
||||||
GFile *result_file;
|
GFile *result_file;
|
||||||
} OstreeFetchUriData;
|
} OstreeFetchUriSyncData;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
uri_fetch_on_complete (GObject *object,
|
fetch_uri_sync_on_complete (GObject *object,
|
||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
OstreeFetchUriData *data = user_data;
|
OstreeFetchUriSyncData *data = user_data;
|
||||||
GError *local_error = NULL;
|
|
||||||
|
|
||||||
data->result_file = ostree_fetcher_request_uri_finish ((OstreeFetcher*)object,
|
data->result_file = ostree_fetcher_request_uri_finish ((OstreeFetcher*)object,
|
||||||
result, &local_error);
|
result, data->pull_data->async_error);
|
||||||
data->pull_data->outstanding_uri_requests--;
|
data->pull_data->fetching_sync_uri = NULL;
|
||||||
check_outstanding_requests_handle_error (data->pull_data, local_error);
|
g_main_loop_quit (data->pull_data->loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
fetch_uri (OtPullData *pull_data,
|
fetch_uri_contents_utf8_sync (OtPullData *pull_data,
|
||||||
SoupURI *uri,
|
|
||||||
const char *tmp_prefix,
|
|
||||||
GFile **out_temp_filename,
|
|
||||||
GCancellable *cancellable,
|
|
||||||
GError **error)
|
|
||||||
{
|
|
||||||
gboolean ret = FALSE;
|
|
||||||
gs_free char *uri_string = NULL;
|
|
||||||
gs_unref_object SoupRequest *request = NULL;
|
|
||||||
OstreeFetchUriData fetch_data = { 0, };
|
|
||||||
|
|
||||||
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
fetch_data.pull_data = pull_data;
|
|
||||||
|
|
||||||
uri_string = soup_uri_to_string (uri, FALSE);
|
|
||||||
|
|
||||||
pull_data->outstanding_uri_requests++;
|
|
||||||
ostree_fetcher_request_uri_async (pull_data->fetcher, uri, cancellable,
|
|
||||||
uri_fetch_on_complete, &fetch_data);
|
|
||||||
|
|
||||||
if (!run_mainloop_monitor_fetcher (pull_data))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
ret = TRUE;
|
|
||||||
ot_transfer_out_value (out_temp_filename, &fetch_data.result_file);
|
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
fetch_uri_contents_utf8 (OtPullData *pull_data,
|
|
||||||
SoupURI *uri,
|
SoupURI *uri,
|
||||||
char **out_contents,
|
char **out_contents,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
|
gsize len;
|
||||||
gs_unref_object GFile *tmpf = NULL;
|
gs_unref_object GFile *tmpf = NULL;
|
||||||
gs_free char *ret_contents = NULL;
|
gs_free char *ret_contents = NULL;
|
||||||
gsize len;
|
gs_unref_object SoupRequest *request = NULL;
|
||||||
|
OstreeFetchUriSyncData fetch_data = { 0, };
|
||||||
|
|
||||||
if (!fetch_uri (pull_data, uri, "tmp-", &tmpf, cancellable, error))
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
fetch_data.pull_data = pull_data;
|
||||||
|
|
||||||
|
pull_data->fetching_sync_uri = uri;
|
||||||
|
ostree_fetcher_request_uri_async (pull_data->fetcher, uri, cancellable,
|
||||||
|
fetch_uri_sync_on_complete, &fetch_data);
|
||||||
|
|
||||||
|
run_mainloop_monitor_fetcher (pull_data);
|
||||||
|
if (!fetch_data.result_file)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!g_file_load_contents (tmpf, cancellable, &ret_contents, &len, NULL, error))
|
if (!g_file_load_contents (fetch_data.result_file, cancellable, &ret_contents, &len, NULL, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!g_utf8_validate (ret_contents, -1, NULL))
|
if (!g_utf8_validate (ret_contents, -1, NULL))
|
||||||
|
|
@ -402,6 +385,7 @@ fetch_uri_contents_utf8 (OtPullData *pull_data,
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
ot_transfer_out_value (out_contents, &ret_contents);
|
ot_transfer_out_value (out_contents, &ret_contents);
|
||||||
out:
|
out:
|
||||||
|
g_clear_object (&(fetch_data.result_file));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -507,7 +491,7 @@ fetch_ref_contents (OtPullData *pull_data,
|
||||||
|
|
||||||
target_uri = suburi_new (pull_data->base_uri, "refs", "heads", ref, NULL);
|
target_uri = suburi_new (pull_data->base_uri, "refs", "heads", ref, NULL);
|
||||||
|
|
||||||
if (!fetch_uri_contents_utf8 (pull_data, target_uri, &ret_contents, cancellable, error))
|
if (!fetch_uri_contents_utf8_sync (pull_data, target_uri, &ret_contents, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
g_strchomp (ret_contents);
|
g_strchomp (ret_contents);
|
||||||
|
|
@ -1111,7 +1095,7 @@ load_remote_repo_config (OtPullData *pull_data,
|
||||||
|
|
||||||
target_uri = suburi_new (pull_data->base_uri, "config", NULL);
|
target_uri = suburi_new (pull_data->base_uri, "config", NULL);
|
||||||
|
|
||||||
if (!fetch_uri_contents_utf8 (pull_data, target_uri, &contents,
|
if (!fetch_uri_contents_utf8_sync (pull_data, target_uri, &contents,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
|
@ -1275,7 +1259,7 @@ ostree_repo_pull (OstreeRepo *self,
|
||||||
path = g_build_filename (soup_uri_get_path (summary_uri), "refs", "summary", NULL);
|
path = g_build_filename (soup_uri_get_path (summary_uri), "refs", "summary", NULL);
|
||||||
soup_uri_set_path (summary_uri, path);
|
soup_uri_set_path (summary_uri, path);
|
||||||
|
|
||||||
if (!fetch_uri_contents_utf8 (pull_data, summary_uri, &summary_data, cancellable, error))
|
if (!fetch_uri_contents_utf8_sync (pull_data, summary_uri, &summary_data, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!parse_ref_summary (summary_data, &requested_refs_to_fetch, error))
|
if (!parse_ref_summary (summary_data, &requested_refs_to_fetch, error))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue