[gnome-commander] Correct async_xfer_callback-results for mooving, fixes bgo#367949
- From: Uwe Scholz <uwescholz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander] Correct async_xfer_callback-results for mooving, fixes bgo#367949
- Date: Tue, 8 Apr 2014 15:21:55 +0000 (UTC)
commit 5bb05c7b4c1d742ad4d9725c9886e58dcc653d1b
Author: Uwe Scholz <uwescholz src gnome org>
Date: Tue Apr 8 17:17:20 2014 +0200
Correct async_xfer_callback-results for mooving, fixes bgo#367949
src/gnome-cmd-file.cc | 2 +-
src/gnome-cmd-xfer.cc | 18 ++++++++++++++++--
src/utils.cc | 26 +++++++++++++++++++++++---
src/utils.h | 2 +-
4 files changed, 41 insertions(+), 7 deletions(-)
---
diff --git a/src/gnome-cmd-file.cc b/src/gnome-cmd-file.cc
index 034595d..4960d31 100644
--- a/src/gnome-cmd-file.cc
+++ b/src/gnome-cmd-file.cc
@@ -542,7 +542,7 @@ GnomeVFSFileSize GnomeCmdFile::get_tree_size()
return priv->tree_size;
GnomeVFSURI *uri = get_uri();
- priv->tree_size = calc_tree_size (uri);
+ priv->tree_size = calc_tree_size (uri,NULL);
gnome_vfs_uri_unref (uri);
return priv->tree_size;
diff --git a/src/gnome-cmd-xfer.cc b/src/gnome-cmd-xfer.cc
index da399a8..e6ce571 100644
--- a/src/gnome-cmd-xfer.cc
+++ b/src/gnome-cmd-xfer.cc
@@ -124,6 +124,19 @@ create_xfer_data (GnomeVFSXferOptions xferOptions, GList *src_uri_list, GList *d
data->done = FALSE;
data->aborted = FALSE;
+ // If this is a move-operation, determine totals
+ // The async_xfer_callback-results for file and byte totals are not reliable
+ if (xferOptions == GNOME_VFS_XFER_REMOVESOURCE) {
+ GList *uris;
+ GnomeVFSURI *uri;
+ data->bytes_total = 0;
+ data->files_total = 0;
+ for (uris = data->src_uri_list; uris != NULL; uris = uris->next) {
+ uri = (GnomeVFSURI*)uris->data;
+ data->bytes_total += calc_tree_size(uri,&(data->files_total));
+ }
+ }
+
return data;
}
@@ -145,8 +158,9 @@ static gint async_xfer_callback (GnomeVFSAsyncHandle *handle, GnomeVFSXferProgre
{
data->cur_phase = info->phase;
data->cur_file = info->file_index;
- data->files_total = info->files_total;
- data->bytes_total = info->bytes_total;
+ // only update totals if larger than current value
+ if (data->files_total < info->files_total) data->files_total = info->files_total;
+ if (data->bytes_total < info->bytes_total) data->bytes_total = info->bytes_total;
data->file_size = info->file_size;
data->bytes_copied = info->bytes_copied;
data->total_bytes_copied = info->total_bytes_copied;
diff --git a/src/utils.cc b/src/utils.cc
index b7fb816..e4307a5 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -739,7 +739,7 @@ GList *strings_to_uris (gchar *data)
}
-GnomeVFSFileSize calc_tree_size (const GnomeVFSURI *dir_uri)
+GnomeVFSFileSize calc_tree_size (const GnomeVFSURI *dir_uri, gulong *count)
{
if (!dir_uri)
return -1;
@@ -755,6 +755,9 @@ GnomeVFSFileSize calc_tree_size (const GnomeVFSURI *dir_uri)
if (result==GNOME_VFS_OK && list)
{
+ if (count!=NULL) {
+ (*count)++; // Count the directory too
+ }
for (GList *i = list; i; i = i->next)
{
GnomeVFSFileInfo *info = (GnomeVFSFileInfo *) i->data;
@@ -763,11 +766,16 @@ GnomeVFSFileSize calc_tree_size (const GnomeVFSURI *dir_uri)
if (info->type == GNOME_VFS_FILE_TYPE_DIRECTORY)
{
GnomeVFSURI *new_dir_uri = gnome_vfs_uri_append_file_name (dir_uri, info->name);
- size += calc_tree_size (new_dir_uri);
+ size += calc_tree_size (new_dir_uri,count);
gnome_vfs_uri_unref (new_dir_uri);
}
else
+ {
size += info->size;
+ if (count!=NULL) {
+ (*count)++;
+ }
+ }
}
}
@@ -775,7 +783,19 @@ GnomeVFSFileSize calc_tree_size (const GnomeVFSURI *dir_uri)
gnome_vfs_file_info_unref ((GnomeVFSFileInfo *) i->data);
g_list_free (list);
- }
+
+ } else if (result==GNOME_VFS_ERROR_NOT_A_DIRECTORY)
+ {
+ // A file
+ GnomeVFSFileInfo *info = gnome_vfs_file_info_new ();
+ result = gnome_vfs_get_file_info (dir_uri_str, info, GNOME_VFS_FILE_INFO_DEFAULT);
+ size += info->size;
+ if (count!=NULL) {
+ (*count)++;
+ }
+ gnome_vfs_file_info_unref (info);
+
+ }
g_free (dir_uri_str);
diff --git a/src/utils.h b/src/utils.h
index 7ef9c49..4f7bf10 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -178,7 +178,7 @@ inline gboolean state_is_ctrl_alt_shift (gint state)
GList *strings_to_uris (gchar *data);
-GnomeVFSFileSize calc_tree_size (const GnomeVFSURI *dir_uri);
+GnomeVFSFileSize calc_tree_size (const GnomeVFSURI *dir_uri, gulong *count);
gchar *create_nice_size_str (GnomeVFSFileSize size);
inline gchar *quote_if_needed (const gchar *in)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]