diff --git a/src/libostree/ostree-fetcher.c b/src/libostree/ostree-fetcher.c index 34a9dcef..851237a5 100644 --- a/src/libostree/ostree-fetcher.c +++ b/src/libostree/ostree-fetcher.c @@ -42,6 +42,7 @@ typedef struct { guint refcount; OstreeFetcher *self; SoupURI *uri; + int priority; OstreeFetcherState state; @@ -60,6 +61,18 @@ typedef struct { GSimpleAsyncResult *result; } OstreeFetcherPendingURI; +static int +pending_uri_compare (gconstpointer a, + gconstpointer b, + gpointer unused) +{ + const OstreeFetcherPendingURI *pending_a = a; + const OstreeFetcherPendingURI *pending_b = b; + + return (pending_a->priority == pending_b->priority) ? 0 : + (pending_a->priority < pending_b->priority) ? -1 : 1; +} + static void pending_uri_free (OstreeFetcherPendingURI *pending) { @@ -507,6 +520,7 @@ ostree_fetcher_request_uri_internal (OstreeFetcher *self, SoupURI *uri, gboolean is_stream, guint64 max_size, + int priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data, @@ -521,6 +535,7 @@ ostree_fetcher_request_uri_internal (OstreeFetcher *self, pending->self = g_object_ref (self); pending->uri = soup_uri_copy (uri); + pending->priority = priority; pending->max_size = max_size; pending->is_stream = is_stream; pending->cancellable = cancellable ? g_object_ref (cancellable) : NULL; @@ -566,7 +581,7 @@ ostree_fetcher_request_uri_internal (OstreeFetcher *self, } pending->out_tmpfile = out_tmpfile; - g_queue_push_tail (&self->pending_queue, pending); + g_queue_insert_sorted (&self->pending_queue, pending, pending_uri_compare, NULL); ostree_fetcher_process_pending_queue (self); } @@ -587,11 +602,12 @@ void _ostree_fetcher_request_uri_with_partial_async (OstreeFetcher *self, SoupURI *uri, guint64 max_size, + int priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { - ostree_fetcher_request_uri_internal (self, uri, FALSE, max_size, cancellable, + ostree_fetcher_request_uri_internal (self, uri, FALSE, max_size, priority, cancellable, callback, user_data, _ostree_fetcher_request_uri_with_partial_async); } @@ -618,11 +634,12 @@ static void ostree_fetcher_stream_uri_async (OstreeFetcher *self, SoupURI *uri, guint64 max_size, + int priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { - ostree_fetcher_request_uri_internal (self, uri, TRUE, max_size, cancellable, + ostree_fetcher_request_uri_internal (self, uri, TRUE, max_size, priority, cancellable, callback, user_data, ostree_fetcher_stream_uri_async); } @@ -716,6 +733,7 @@ _ostree_fetcher_request_uri_to_membuf (OstreeFetcher *fetcher, ostree_fetcher_stream_uri_async (fetcher, uri, max_size, + OSTREE_FETCHER_DEFAULT_PRIORITY, cancellable, fetch_uri_sync_on_complete, &data); diff --git a/src/libostree/ostree-fetcher.h b/src/libostree/ostree-fetcher.h index 1a6c95b7..c81e51aa 100644 --- a/src/libostree/ostree-fetcher.h +++ b/src/libostree/ostree-fetcher.h @@ -36,6 +36,9 @@ G_BEGIN_DECLS #define OSTREE_IS_FETCHER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), OSTREE_TYPE_FETCHER)) #define OSTREE_FETCHER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), OSTREE_TYPE_FETCHER, OstreeFetcherClass)) +/* Lower values have higher priority */ +#define OSTREE_FETCHER_DEFAULT_PRIORITY 0 + typedef struct OstreeFetcherClass OstreeFetcherClass; typedef struct OstreeFetcher OstreeFetcher; @@ -68,6 +71,7 @@ guint64 _ostree_fetcher_bytes_transferred (OstreeFetcher *self); void _ostree_fetcher_request_uri_with_partial_async (OstreeFetcher *self, SoupURI *uri, guint64 max_size, + int priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); diff --git a/src/libostree/ostree-metalink.c b/src/libostree/ostree-metalink.c index 5244e917..82091eee 100644 --- a/src/libostree/ostree-metalink.c +++ b/src/libostree/ostree-metalink.c @@ -518,6 +518,7 @@ try_next_url (OstreeMetalinkRequest *self) _ostree_fetcher_request_uri_with_partial_async (self->metalink->fetcher, next, self->metalink->max_size, + OSTREE_FETCHER_DEFAULT_PRIORITY, g_task_get_cancellable (self->task), on_fetched_url, self->task); } diff --git a/src/libostree/ostree-repo-pull.c b/src/libostree/ostree-repo-pull.c index a6160d33..296d23eb 100644 --- a/src/libostree/ostree-repo-pull.c +++ b/src/libostree/ostree-repo-pull.c @@ -1123,6 +1123,7 @@ enqueue_one_object_request (OtPullData *pull_data, _ostree_fetcher_request_uri_with_partial_async (pull_data->fetcher, obj_uri, expected_max_size, + OSTREE_FETCHER_DEFAULT_PRIORITY, pull_data->cancellable, is_meta ? meta_fetch_on_complete : content_fetch_on_complete, fetch_data); soup_uri_free (obj_uri); @@ -1451,6 +1452,7 @@ process_one_static_delta (OtPullData *pull_data, target_uri = suburi_new (pull_data->base_uri, deltapart_path, NULL); _ostree_fetcher_request_uri_with_partial_async (pull_data->fetcher, target_uri, size, + OSTREE_FETCHER_DEFAULT_PRIORITY, pull_data->cancellable, static_deltapart_fetch_on_complete, fetch_data);