GNOME Bugzilla – Bug 524579
g_file_copy reports wrong total on progress callback for http
Last modified: 2008-03-28 12:44:23 UTC
Please describe the problem: When I tried to copy a file from an http:// source to a file:// destination, the progress callback passed to g_file_copy was receiving total_num_bytes equals to 0 every time. So after a little debugging we saw copy_stream_with_progress calling g_file_input_stream_query_info and it was always returning NULL. We tracked the problem to gvfs/daemon/soup-input-stream.c but it wasn't implementing query_info and we didn't find a way to implement because it extends GInputStream, not GFileInputStream. The way we found to fix it was get the info from GFile with g_file_query_info in copy_stream_with_progress instead of using g_file_input_stream_query_info, since the former implements query_info correctly for the http backend. Steps to reproduce: g_message ("file copy"); { GFile *src; GFile *dst; GError *error = NULL; src = g_file_new_for_uri ("http://lincoln.alfaiati.net/index.html"); dst = g_file_new_for_uri ("file:///home/lincoln/Desktop/lincoln-alfaiati.html"); void progress_callback (goffset current_num_bytes, goffset total_num_bytes, gpointer user_data) { g_message ("%d, %d", (gint) current_num_bytes, (gint) total_num_bytes); } if (!g_file_copy (src, dst, G_FILE_COPY_OVERWRITE, NULL, progress_callback, NULL, &error)) { g_printerr ("Error... Oh caraio! %s\n", error->message); g_error_free (error); return 1; } return 0; } Actual results: ** Message: file copy ** Message: 1120, 0 ** Message: 6912, 0 ** Message: 7468, 0 ** Message: 7468, 0 Expected results: ** Message: file copy ** Message: 1120, 7468 ** Message: 6912, 7468 ** Message: 7468, 7468 ** Message: 7468, 7468 Does this happen every time? yes Other information:
Created attachment 108096 [details] [review] Fixes wrong size report in g_file_copy Thanks to kov@debian.org for helping debug and write this patch.
This is not right. We need to do an "fstat", not a "stat", as the later is racy. However, "fstat" is not yet implemented for gvfs yet (bug 520244) *** This bug has been marked as a duplicate of 520244 ***
Actually, i guess it makes sense to try g_file_query_info if g_file_input_stream_query_info fails. Possibly racy is better than always wrong. 2008-03-28 Alexander Larsson <alexl@redhat.com> * gfile.c: (copy_stream_with_progress): (file_copy_fallback): Fallback to g_file_query_info for source size if g_file_input_stream_query_info fails. (#524579)