After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 524579 - g_file_copy reports wrong total on progress callback for http
g_file_copy reports wrong total on progress callback for http
Status: RESOLVED DUPLICATE of bug 520244
Product: glib
Classification: Platform
Component: gio
2.16.x
Other All
: Normal normal
: ---
Assigned To: Alexander Larsson
gtkdev
Depends on:
Blocks:
 
 
Reported: 2008-03-27 00:40 UTC by Lincoln de Sousa
Modified: 2008-03-28 12:44 UTC
See Also:
GNOME target: ---
GNOME version: 2.21/2.22


Attachments
Fixes wrong size report in g_file_copy (1.63 KB, patch)
2008-03-27 00:44 UTC, Lincoln de Sousa
none Details | Review

Description Lincoln de Sousa 2008-03-27 00:40:00 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:
Comment 1 Lincoln de Sousa 2008-03-27 00:44:57 UTC
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.
Comment 2 Alexander Larsson 2008-03-27 09:21:13 UTC
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 ***
Comment 3 Alexander Larsson 2008-03-28 12:44:23 UTC
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)