diff options
Diffstat (limited to 'src/libostree/ostree-fetcher-util.c')
-rw-r--r-- | src/libostree/ostree-fetcher-util.c | 170 |
1 files changed, 65 insertions, 105 deletions
diff --git a/src/libostree/ostree-fetcher-util.c b/src/libostree/ostree-fetcher-util.c index ecd6bc23..b797bee7 100644 --- a/src/libostree/ostree-fetcher-util.c +++ b/src/libostree/ostree-fetcher-util.c @@ -32,49 +32,36 @@ typedef struct { - GBytes *result_buf; - gboolean result_not_modified; - char *result_etag; - guint64 result_last_modified; /* second since the epoch */ - gboolean done; - GMainContext *main_context; /* (owned) */ - GError **error; -} - FetchUriSyncData; + GBytes *result_buf; + gboolean result_not_modified; + char *result_etag; + guint64 result_last_modified; /* second since the epoch */ + gboolean done; + GMainContext *main_context; /* (owned) */ + GError **error; +} FetchUriSyncData; static void -fetch_uri_sync_on_complete (GObject *object, - GAsyncResult *result, - gpointer user_data) +fetch_uri_sync_on_complete (GObject *object, GAsyncResult *result, gpointer user_data) { FetchUriSyncData *data = user_data; - (void)_ostree_fetcher_request_to_membuf_finish ((OstreeFetcher*)object, - result, &data->result_buf, - &data->result_not_modified, - &data->result_etag, &data->result_last_modified, - data->error); + (void)_ostree_fetcher_request_to_membuf_finish ( + (OstreeFetcher *)object, result, &data->result_buf, &data->result_not_modified, + &data->result_etag, &data->result_last_modified, data->error); data->done = TRUE; g_main_context_wakeup (data->main_context); } static gboolean -_ostree_fetcher_mirrored_request_to_membuf_once (OstreeFetcher *fetcher, - GPtrArray *mirrorlist, - const char *filename, - OstreeFetcherRequestFlags flags, - const char *if_none_match, - guint64 if_modified_since, - GBytes **out_contents, - gboolean *out_not_modified, - char **out_etag, - guint64 *out_last_modified, - guint64 max_size, - GCancellable *cancellable, - GError **error) +_ostree_fetcher_mirrored_request_to_membuf_once ( + OstreeFetcher *fetcher, GPtrArray *mirrorlist, const char *filename, + OstreeFetcherRequestFlags flags, const char *if_none_match, guint64 if_modified_since, + GBytes **out_contents, gboolean *out_not_modified, char **out_etag, guint64 *out_last_modified, + guint64 max_size, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; - g_autoptr(GMainContext) mainctx = NULL; + g_autoptr (GMainContext) mainctx = NULL; FetchUriSyncData data; g_assert (error != NULL); @@ -90,9 +77,8 @@ _ostree_fetcher_mirrored_request_to_membuf_once (OstreeFetcher *fe data.done = FALSE; data.error = error; - _ostree_fetcher_request_to_membuf (fetcher, mirrorlist, filename, - flags, if_none_match, if_modified_since, - max_size, OSTREE_FETCHER_DEFAULT_PRIORITY, + _ostree_fetcher_request_to_membuf (fetcher, mirrorlist, filename, flags, if_none_match, + if_modified_since, max_size, OSTREE_FETCHER_DEFAULT_PRIORITY, cancellable, fetch_uri_sync_on_complete, &data); while (!data.done) g_main_context_iteration (mainctx, TRUE); @@ -125,7 +111,7 @@ _ostree_fetcher_mirrored_request_to_membuf_once (OstreeFetcher *fe *out_etag = g_steal_pointer (&data.result_etag); if (out_last_modified != NULL) *out_last_modified = data.result_last_modified; - out: +out: if (mainctx) g_main_context_pop_thread_default (mainctx); g_clear_pointer (&data.result_buf, g_bytes_unref); @@ -135,33 +121,23 @@ _ostree_fetcher_mirrored_request_to_membuf_once (OstreeFetcher *fe } gboolean -_ostree_fetcher_mirrored_request_to_membuf (OstreeFetcher *fetcher, - GPtrArray *mirrorlist, - const char *filename, - OstreeFetcherRequestFlags flags, - const char *if_none_match, - guint64 if_modified_since, - guint n_network_retries, - GBytes **out_contents, - gboolean *out_not_modified, - char **out_etag, - guint64 *out_last_modified, - guint64 max_size, - GCancellable *cancellable, - GError **error) +_ostree_fetcher_mirrored_request_to_membuf (OstreeFetcher *fetcher, GPtrArray *mirrorlist, + const char *filename, OstreeFetcherRequestFlags flags, + const char *if_none_match, guint64 if_modified_since, + guint n_network_retries, GBytes **out_contents, + gboolean *out_not_modified, char **out_etag, + guint64 *out_last_modified, guint64 max_size, + GCancellable *cancellable, GError **error) { - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; guint n_retries_remaining = n_network_retries; do { g_clear_error (&local_error); - if (_ostree_fetcher_mirrored_request_to_membuf_once (fetcher, mirrorlist, - filename, flags, - if_none_match, if_modified_since, - out_contents, out_not_modified, out_etag, - out_last_modified, max_size, - cancellable, &local_error)) + if (_ostree_fetcher_mirrored_request_to_membuf_once ( + fetcher, mirrorlist, filename, flags, if_none_match, if_modified_since, out_contents, + out_not_modified, out_etag, out_last_modified, max_size, cancellable, &local_error)) return TRUE; } while (_ostree_fetcher_should_retry_request (local_error, n_retries_remaining--)); @@ -173,46 +149,33 @@ _ostree_fetcher_mirrored_request_to_membuf (OstreeFetcher *fetcher /* Helper for callers who just want to fetch single one-off URIs */ gboolean -_ostree_fetcher_request_uri_to_membuf (OstreeFetcher *fetcher, - OstreeFetcherURI *uri, - OstreeFetcherRequestFlags flags, - const char *if_none_match, - guint64 if_modified_since, - guint n_network_retries, - GBytes **out_contents, - gboolean *out_not_modified, - char **out_etag, - guint64 *out_last_modified, - guint64 max_size, - GCancellable *cancellable, - GError **error) +_ostree_fetcher_request_uri_to_membuf (OstreeFetcher *fetcher, OstreeFetcherURI *uri, + OstreeFetcherRequestFlags flags, const char *if_none_match, + guint64 if_modified_since, guint n_network_retries, + GBytes **out_contents, gboolean *out_not_modified, + char **out_etag, guint64 *out_last_modified, + guint64 max_size, GCancellable *cancellable, GError **error) { - g_autoptr(GPtrArray) mirrorlist = g_ptr_array_new (); + g_autoptr (GPtrArray) mirrorlist = g_ptr_array_new (); g_ptr_array_add (mirrorlist, uri); /* no transfer */ - return _ostree_fetcher_mirrored_request_to_membuf (fetcher, mirrorlist, NULL, flags, - if_none_match, if_modified_since, - n_network_retries, out_contents, - out_not_modified, out_etag, out_last_modified, max_size, - cancellable, error); + return _ostree_fetcher_mirrored_request_to_membuf ( + fetcher, mirrorlist, NULL, flags, if_none_match, if_modified_since, n_network_retries, + out_contents, out_not_modified, out_etag, out_last_modified, max_size, cancellable, error); } -#define OSTREE_HTTP_FAILURE_ID SD_ID128_MAKE(f0,2b,ce,89,a5,4e,4e,fa,b3,a9,4a,79,7d,26,20,4a) +#define OSTREE_HTTP_FAILURE_ID \ + SD_ID128_MAKE (f0, 2b, ce, 89, a5, 4e, 4e, fa, b3, a9, 4a, 79, 7d, 26, 20, 4a) void -_ostree_fetcher_journal_failure (const char *remote_name, - const char *url, - const char *msg) +_ostree_fetcher_journal_failure (const char *remote_name, const char *url, const char *msg) { /* Sanity - we don't want to log this when doing local/file pulls */ if (!remote_name) return; - ot_journal_send ("MESSAGE=libostree HTTP error from remote %s for <%s>: %s", - remote_name, url, msg, - "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(OSTREE_HTTP_FAILURE_ID), - "OSTREE_REMOTE=%s", remote_name, - "OSTREE_URL=%s", url, - "PRIORITY=%i", LOG_ERR, - NULL); + ot_journal_send ("MESSAGE=libostree HTTP error from remote %s for <%s>: %s", remote_name, url, + msg, "MESSAGE_ID=" SD_ID128_FORMAT_STR, + SD_ID128_FORMAT_VAL (OSTREE_HTTP_FAILURE_ID), "OSTREE_REMOTE=%s", remote_name, + "OSTREE_URL=%s", url, "PRIORITY=%i", LOG_ERR, NULL); } /* Check whether a particular operation should be retried. This is entirely @@ -224,33 +187,30 @@ _ostree_fetcher_journal_failure (const char *remote_name, * FIXME: In future, we may decide to use transient failures like this as a hint * to prioritise other mirrors for a particular pull operation (for example). */ gboolean -_ostree_fetcher_should_retry_request (const GError *error, - guint n_retries_remaining) +_ostree_fetcher_should_retry_request (const GError *error, guint n_retries_remaining) { if (error == NULL) - g_debug ("%s: error: unset, n_retries_remaining: %u", - G_STRFUNC, n_retries_remaining); + g_debug ("%s: error: unset, n_retries_remaining: %u", G_STRFUNC, n_retries_remaining); else - g_debug ("%s: error: %u:%u %s, n_retries_remaining: %u", - G_STRFUNC, error->domain, error->code, error->message, - n_retries_remaining); + g_debug ("%s: error: %u:%u %s, n_retries_remaining: %u", G_STRFUNC, error->domain, error->code, + error->message, n_retries_remaining); if (error == NULL || n_retries_remaining == 0) return FALSE; /* Return TRUE for transient errors. */ - if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_TIMED_OUT) || - g_error_matches (error, G_IO_ERROR, G_IO_ERROR_HOST_NOT_FOUND) || - g_error_matches (error, G_IO_ERROR, G_IO_ERROR_HOST_UNREACHABLE) || - g_error_matches (error, G_IO_ERROR, G_IO_ERROR_PARTIAL_INPUT) || - g_error_matches (error, G_IO_ERROR, G_IO_ERROR_BUSY) || + if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_TIMED_OUT) + || g_error_matches (error, G_IO_ERROR, G_IO_ERROR_HOST_NOT_FOUND) + || g_error_matches (error, G_IO_ERROR, G_IO_ERROR_HOST_UNREACHABLE) + || g_error_matches (error, G_IO_ERROR, G_IO_ERROR_PARTIAL_INPUT) + || g_error_matches (error, G_IO_ERROR, G_IO_ERROR_BUSY) || #if !GLIB_CHECK_VERSION(2, 44, 0) g_error_matches (error, G_IO_ERROR, G_IO_ERROR_BROKEN_PIPE) || #else g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CONNECTION_CLOSED) || #endif - g_error_matches (error, G_RESOLVER_ERROR, G_RESOLVER_ERROR_NOT_FOUND) || - g_error_matches (error, G_RESOLVER_ERROR, G_RESOLVER_ERROR_TEMPORARY_FAILURE)) + g_error_matches (error, G_RESOLVER_ERROR, G_RESOLVER_ERROR_NOT_FOUND) + || g_error_matches (error, G_RESOLVER_ERROR, G_RESOLVER_ERROR_TEMPORARY_FAILURE)) { g_debug ("Should retry request (remaining: %u retries), due to transient error: %s", n_retries_remaining, error->message); @@ -268,13 +228,13 @@ _ostree_fetcher_http_status_code_to_io_error (guint status_code) { switch (status_code) { - case 403: /* SOUP_STATUS_FORBIDDEN */ - case 404: /* SOUP_STATUS_NOT_FOUND */ - case 410: /* SOUP_STATUS_GONE */ + case 403: /* SOUP_STATUS_FORBIDDEN */ + case 404: /* SOUP_STATUS_NOT_FOUND */ + case 410: /* SOUP_STATUS_GONE */ return G_IO_ERROR_NOT_FOUND; - case 408: /* SOUP_STATUS_REQUEST_TIMEOUT */ + case 408: /* SOUP_STATUS_REQUEST_TIMEOUT */ return G_IO_ERROR_TIMED_OUT; - case 500: /* SOUP_STATUS_INTERNAL_SERVER_ERROR */ + case 500: /* SOUP_STATUS_INTERNAL_SERVER_ERROR */ return G_IO_ERROR_BUSY; default: return G_IO_ERROR_FAILED; |