fetcher: Display incremental download progress

Previously the progress meter would bump in large chunks after we
completed a download.  Instead, poll in progress files via fstat() for
their size, and add those to the running total.
This commit is contained in:
Colin Walters 2013-11-21 14:34:47 -05:00
parent e9b35deba8
commit 2b8c717c33
1 changed files with 28 additions and 1 deletions

View File

@ -83,6 +83,7 @@ struct OstreeFetcher
GHashTable *sending_messages; /* SoupMessage */ GHashTable *sending_messages; /* SoupMessage */
GHashTable *message_to_request; /* SoupMessage -> SoupRequest */ GHashTable *message_to_request; /* SoupMessage -> SoupRequest */
GHashTable *output_stream_set; /* set<GOutputStream> */
guint64 total_downloaded; guint64 total_downloaded;
guint total_requests; guint total_requests;
@ -107,6 +108,7 @@ ostree_fetcher_finalize (GObject *object)
g_hash_table_destroy (self->sending_messages); g_hash_table_destroy (self->sending_messages);
g_hash_table_destroy (self->message_to_request); g_hash_table_destroy (self->message_to_request);
g_hash_table_destroy (self->output_stream_set);
g_queue_clear (&self->pending_queue); g_queue_clear (&self->pending_queue);
@ -165,6 +167,7 @@ ostree_fetcher_init (OstreeFetcher *self)
(GDestroyNotify)g_object_unref); (GDestroyNotify)g_object_unref);
self->message_to_request = g_hash_table_new_full (NULL, NULL, (GDestroyNotify)g_object_unref, self->message_to_request = g_hash_table_new_full (NULL, NULL, (GDestroyNotify)g_object_unref,
(GDestroyNotify)pending_uri_free); (GDestroyNotify)pending_uri_free);
self->output_stream_set = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify)g_object_unref);
} }
OstreeFetcher * OstreeFetcher *
@ -218,6 +221,9 @@ on_splice_complete (GObject *object,
goffset filesize; goffset filesize;
GError *local_error = NULL; GError *local_error = NULL;
if (pending->out_stream)
g_hash_table_remove (pending->self->output_stream_set, pending->out_stream);
pending->state = OSTREE_FETCHER_STATE_COMPLETE; pending->state = OSTREE_FETCHER_STATE_COMPLETE;
file_info = g_file_query_info (pending->out_tmpfile, OSTREE_GIO_FAST_QUERYINFO, file_info = g_file_query_info (pending->out_tmpfile, OSTREE_GIO_FAST_QUERYINFO,
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
@ -308,8 +314,10 @@ on_request_sent (GObject *object,
pending->cancellable, &local_error)); pending->cancellable, &local_error));
if (!pending->out_stream) if (!pending->out_stream)
goto out; goto out;
g_hash_table_add (pending->self->output_stream_set, g_object_ref (pending->out_stream));
g_output_stream_splice_async (pending->out_stream, pending->request_body, flags, G_PRIORITY_DEFAULT, g_output_stream_splice_async (pending->out_stream, pending->request_body, flags, G_PRIORITY_DEFAULT,
pending->cancellable, on_splice_complete, pending); pending->cancellable, on_splice_complete, pending);
} }
else else
{ {
@ -536,7 +544,26 @@ ostree_fetcher_query_state_text (OstreeFetcher *self)
guint64 guint64
ostree_fetcher_bytes_transferred (OstreeFetcher *self) ostree_fetcher_bytes_transferred (OstreeFetcher *self)
{ {
return self->total_downloaded; guint64 ret = self->total_downloaded;
GHashTableIter hiter;
gpointer key, value;
g_hash_table_iter_init (&hiter, self->output_stream_set);
while (g_hash_table_iter_next (&hiter, &key, &value))
{
GFileOutputStream *stream = key;
GFileInfo *finfo;
finfo = g_file_output_stream_query_info (stream, "standard::size",
NULL, NULL);
if (finfo)
{
ret += g_file_info_get_size (finfo);
g_object_unref (finfo);
}
}
return ret;
} }
guint guint