Hi,

The file size reported to gnome-vfs transfer callbacks is currently
based on values returned by gnome_vfs_get_file_info() before starting
the transfer.  For HTTP transfers, this means it's based on the
Content-Length header returned from a HEAD request.  

In bugs 330498 and 378155, there are a few examples of HTTP servers that
do not return Content-Length headers for HEAD requests, or return
'Content-Length: 0'.  The HTTP server is not required to return exactly
the same headers as it would for a GET request (RFC 2616 only says it
SHOULD).

The patch adds a gnome_vfs_get_file_info_from_handle() call after
opening the source file to set the file size if the initial
gnome_vfs_get_file_info() didn't provide a value.  For HTTP transfers,
this will use the Content-Length header from the GET response, which is
at least a bit more likely to provide the right value.

thanks,
jonathan
Index: libgnomevfs/gnome-vfs-xfer.c
===================================================================
--- libgnomevfs/gnome-vfs-xfer.c        (revision 5266)
+++ libgnomevfs/gnome-vfs-xfer.c        (working copy)
@@ -1341,6 +1341,23 @@
                }
        } while (retry);
 
+       /* if we didn't get a file size earlier,
+        * try to get one from the handle (#330498)
+        */
+       if (progress->progress_info->file_size == 0) {
+               GnomeVFSFileInfo *info;
+
+               info = gnome_vfs_file_info_new ();
+               result = gnome_vfs_get_file_info_from_handle (*source_handle,
+                                                             info,
+                                                             
GNOME_VFS_FILE_INFO_DEFAULT);
+               if (result == GNOME_VFS_OK &&
+                   info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SIZE) {
+                       progress->progress_info->file_size = info->size;
+               }
+               gnome_vfs_file_info_unref (info);
+       }
+
        return result;
 }
 
_______________________________________________
gnome-vfs-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gnome-vfs-list

Reply via email to