pull: drop fetching_sync_uri

This made sense back when we used a main loop even when we needed to
fetch objects synchronously. Nowadays, we no longer actually update
progress before the FETCHING_OBJECTS phase, which is only for async
requests.

This allows us to get rid of fetch_uri_contents_membuf_sync() and to
generalize fetch_uri_contents_utf8_sync() so that it only requires a
fetcher. This will be needed later.

Closes: #469
Approved by: cgwalters
This commit is contained in:
Jonathan Lebon 2016-08-22 16:14:52 -04:00 committed by Atomic Bot
parent bfa8eaccd3
commit 9546b93382
3 changed files with 31 additions and 67 deletions

View File

@ -593,7 +593,6 @@ gboolean
_ostree_metalink_request_sync (OstreeMetalink *self, _ostree_metalink_request_sync (OstreeMetalink *self,
SoupURI **out_target_uri, SoupURI **out_target_uri,
GBytes **out_data, GBytes **out_data,
SoupURI **fetching_sync_uri,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
@ -604,9 +603,6 @@ _ostree_metalink_request_sync (OstreeMetalink *self,
gsize len; gsize len;
const guint8 *data; const guint8 *data;
if (fetching_sync_uri != NULL)
*fetching_sync_uri = _ostree_metalink_get_uri (self);
mainctx = g_main_context_new (); mainctx = g_main_context_new ();
g_main_context_push_thread_default (mainctx); g_main_context_push_thread_default (mainctx);

View File

@ -53,7 +53,6 @@ SoupURI *_ostree_metalink_get_uri (OstreeMetalink *self);
gboolean _ostree_metalink_request_sync (OstreeMetalink *self, gboolean _ostree_metalink_request_sync (OstreeMetalink *self,
SoupURI **out_target_uri, SoupURI **out_target_uri,
GBytes **out_data, GBytes **out_data,
SoupURI **fetching_sync_uri,
GCancellable *cancellable, GCancellable *cancellable,
GError **error); GError **error);
G_END_DECLS G_END_DECLS

View File

@ -62,7 +62,6 @@ typedef struct {
OSTREE_PULL_PHASE_FETCHING_OBJECTS OSTREE_PULL_PHASE_FETCHING_OBJECTS
} phase; } phase;
gint n_scanned_metadata; gint n_scanned_metadata;
SoupURI *fetching_sync_uri;
gboolean gpg_verify; gboolean gpg_verify;
gboolean gpg_verify_summary; gboolean gpg_verify_summary;
@ -246,14 +245,7 @@ update_progress (gpointer user_data)
ostree_async_progress_set_uint (pull_data->progress, "outstanding-metadata-fetches", pull_data->n_outstanding_metadata_fetches); ostree_async_progress_set_uint (pull_data->progress, "outstanding-metadata-fetches", pull_data->n_outstanding_metadata_fetches);
ostree_async_progress_set_uint (pull_data->progress, "metadata-fetched", pull_data->n_fetched_metadata); ostree_async_progress_set_uint (pull_data->progress, "metadata-fetched", pull_data->n_fetched_metadata);
if (pull_data->fetching_sync_uri) ostree_async_progress_set_status (pull_data->progress, NULL);
{
g_autofree char *uri_string = soup_uri_to_string (pull_data->fetching_sync_uri, TRUE);
g_autofree char *status_string = g_strconcat ("Requesting ", uri_string, NULL);
ostree_async_progress_set_status (pull_data->progress, status_string);
}
else
ostree_async_progress_set_status (pull_data->progress, NULL);
if (pull_data->dry_run) if (pull_data->dry_run)
pull_data->dry_run_emitted_progress = TRUE; pull_data->dry_run_emitted_progress = TRUE;
@ -274,27 +266,19 @@ pull_termination_condition (OtPullData *pull_data)
gboolean current_scan_idle = g_queue_is_empty (&pull_data->scan_object_queue); gboolean current_scan_idle = g_queue_is_empty (&pull_data->scan_object_queue);
gboolean current_idle = current_fetch_idle && current_write_idle && current_scan_idle; gboolean current_idle = current_fetch_idle && current_write_idle && current_scan_idle;
/* we only enter the main loop when we're fetching objects */
g_assert (pull_data->phase == OSTREE_PULL_PHASE_FETCHING_OBJECTS);
if (pull_data->caught_error) if (pull_data->caught_error)
return TRUE; return TRUE;
if (pull_data->dry_run) if (pull_data->dry_run)
return pull_data->dry_run_emitted_progress; return pull_data->dry_run_emitted_progress;
switch (pull_data->phase) if (current_idle)
{ g_debug ("pull: idle, exiting mainloop");
case OSTREE_PULL_PHASE_FETCHING_REFS:
if (!pull_data->fetching_sync_uri) return current_idle;
return TRUE;
break;
case OSTREE_PULL_PHASE_FETCHING_OBJECTS:
if (current_idle && !pull_data->fetching_sync_uri)
{
g_debug ("pull: idle, exiting mainloop");
return TRUE;
}
break;
}
return FALSE;
} }
static void static void
@ -362,30 +346,7 @@ typedef struct {
} OstreeFetchUriSyncData; } OstreeFetchUriSyncData;
static gboolean static gboolean
fetch_uri_contents_membuf_sync (OtPullData *pull_data, fetch_uri_contents_utf8_sync (OstreeFetcher *fetcher,
SoupURI *uri,
gboolean add_nul,
gboolean allow_noent,
GBytes **out_contents,
GCancellable *cancellable,
GError **error)
{
gboolean ret;
pull_data->fetching_sync_uri = uri;
ret = _ostree_fetcher_request_uri_to_membuf (pull_data->fetcher,
uri,
add_nul,
allow_noent,
out_contents,
OSTREE_MAX_METADATA_SIZE,
cancellable,
error);
pull_data->fetching_sync_uri = NULL;
return ret;
}
static gboolean
fetch_uri_contents_utf8_sync (OtPullData *pull_data,
SoupURI *uri, SoupURI *uri,
char **out_contents, char **out_contents,
GCancellable *cancellable, GCancellable *cancellable,
@ -396,8 +357,10 @@ fetch_uri_contents_utf8_sync (OtPullData *pull_data,
g_autofree char *ret_contents = NULL; g_autofree char *ret_contents = NULL;
gsize len; gsize len;
if (!fetch_uri_contents_membuf_sync (pull_data, uri, TRUE, FALSE, if (!_ostree_fetcher_request_uri_to_membuf (fetcher, uri, TRUE,
&bytes, cancellable, error)) FALSE, &bytes,
OSTREE_MAX_METADATA_SIZE,
cancellable, error))
goto out; goto out;
ret_contents = g_bytes_unref_to_data (bytes, &len); ret_contents = g_bytes_unref_to_data (bytes, &len);
@ -586,7 +549,8 @@ 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_sync (pull_data, target_uri, &ret_contents, cancellable, error)) if (!fetch_uri_contents_utf8_sync (pull_data->fetcher, target_uri,
&ret_contents, cancellable, error))
goto out; goto out;
g_strchomp (ret_contents); g_strchomp (ret_contents);
@ -1398,7 +1362,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_sync (pull_data, target_uri, &contents, if (!fetch_uri_contents_utf8_sync (pull_data->fetcher, target_uri, &contents,
cancellable, error)) cancellable, error))
goto out; goto out;
@ -1434,9 +1398,11 @@ request_static_delta_superblock_sync (OtPullData *pull_data,
target_uri = suburi_new (pull_data->base_content_uri, delta_name, NULL); target_uri = suburi_new (pull_data->base_content_uri, delta_name, NULL);
if (!fetch_uri_contents_membuf_sync (pull_data, target_uri, FALSE, TRUE, if (!_ostree_fetcher_request_uri_to_membuf (pull_data->fetcher, target_uri,
&delta_superblock_data, FALSE, TRUE,
pull_data->cancellable, error)) &delta_superblock_data,
OSTREE_MAX_METADATA_SIZE,
pull_data->cancellable, error))
goto out; goto out;
if (delta_superblock_data) if (delta_superblock_data)
@ -1999,7 +1965,7 @@ _ostree_preload_metadata_file (OstreeRepo *self,
OSTREE_MAX_METADATA_SIZE, OSTREE_MAX_METADATA_SIZE,
base_uri); base_uri);
_ostree_metalink_request_sync (metalink, NULL, out_bytes, NULL, _ostree_metalink_request_sync (metalink, NULL, out_bytes,
cancellable, &local_error); cancellable, &local_error);
if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
@ -2368,7 +2334,6 @@ ostree_repo_pull_with_options (OstreeRepo *self,
if (! _ostree_metalink_request_sync (metalink, if (! _ostree_metalink_request_sync (metalink,
&target_uri, &target_uri,
&summary_bytes, &summary_bytes,
&pull_data->fetching_sync_uri,
cancellable, cancellable,
error)) error))
goto out; goto out;
@ -2465,8 +2430,10 @@ ostree_repo_pull_with_options (OstreeRepo *self,
if (!pull_data->summary_data_sig) if (!pull_data->summary_data_sig)
{ {
uri = suburi_new (pull_data->base_uri, "summary.sig", NULL); uri = suburi_new (pull_data->base_uri, "summary.sig", NULL);
if (!fetch_uri_contents_membuf_sync (pull_data, uri, FALSE, TRUE, if (!_ostree_fetcher_request_uri_to_membuf (pull_data->fetcher, uri,
&bytes_sig, cancellable, error)) FALSE, TRUE, &bytes_sig,
OSTREE_MAX_METADATA_SIZE,
cancellable, error))
goto out; goto out;
soup_uri_free (uri); soup_uri_free (uri);
} }
@ -2487,8 +2454,10 @@ ostree_repo_pull_with_options (OstreeRepo *self,
if (!pull_data->summary && !bytes_summary) if (!pull_data->summary && !bytes_summary)
{ {
uri = suburi_new (pull_data->base_uri, "summary", NULL); uri = suburi_new (pull_data->base_uri, "summary", NULL);
if (!fetch_uri_contents_membuf_sync (pull_data, uri, FALSE, TRUE, if (!_ostree_fetcher_request_uri_to_membuf (pull_data->fetcher, uri,
&bytes_summary, cancellable, error)) FALSE, TRUE, &bytes_summary,
OSTREE_MAX_METADATA_SIZE,
cancellable, error))
goto out; goto out;
soup_uri_free (uri); soup_uri_free (uri);
} }