[glib/glib-2-20] only query file info in g_file_copy() when we need it
- From: Matthias Clasen <matthiasc src gnome org>
- To: svn-commits-list gnome org
- Subject: [glib/glib-2-20] only query file info in g_file_copy() when we need it
- Date: Tue, 23 Jun 2009 13:05:06 -0400 (EDT)
commit 1feacdd38b347711e9f9459790ded6f987f375cb
Author: Benjamin Otte <otte gnome org>
Date: Mon Jun 8 15:27:12 2009 +0200
only query file info in g_file_copy() when we need it
The default implementation of g_file_copy() checked the size of the file
to copy to give useful progress updates unconditionally. This can cause
long delays on 1-connection FTP servers while it tries to open a second
connection before it returns EBUSY. This patch makes this query only
happen when we actually send progress updates.
gio/gfile.c | 34 +++++++++++++++++++---------------
1 files changed, 19 insertions(+), 15 deletions(-)
---
diff --git a/gio/gfile.c b/gio/gfile.c
index 36c66ec..df86364 100644
--- a/gio/gfile.c
+++ b/gio/gfile.c
@@ -2210,28 +2210,32 @@ copy_stream_with_progress (GInputStream *in,
GFileInfo *info;
total_size = -1;
- info = g_file_input_stream_query_info (G_FILE_INPUT_STREAM (in),
- G_FILE_ATTRIBUTE_STANDARD_SIZE,
- cancellable, NULL);
- if (info)
- {
- if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE))
- total_size = g_file_info_get_size (info);
- g_object_unref (info);
- }
-
- if (total_size == -1)
+ /* avoid performance impact of querying total size when it's not needed */
+ if (progress_callback)
{
- info = g_file_query_info (source,
- G_FILE_ATTRIBUTE_STANDARD_SIZE,
- G_FILE_QUERY_INFO_NONE,
- cancellable, NULL);
+ info = g_file_input_stream_query_info (G_FILE_INPUT_STREAM (in),
+ G_FILE_ATTRIBUTE_STANDARD_SIZE,
+ cancellable, NULL);
if (info)
{
if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE))
total_size = g_file_info_get_size (info);
g_object_unref (info);
}
+
+ if (total_size == -1)
+ {
+ info = g_file_query_info (source,
+ G_FILE_ATTRIBUTE_STANDARD_SIZE,
+ G_FILE_QUERY_INFO_NONE,
+ cancellable, NULL);
+ if (info)
+ {
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE))
+ total_size = g_file_info_get_size (info);
+ g_object_unref (info);
+ }
+ }
}
if (total_size == -1)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]