[gnome-commander] Calculate the file size and directory size with gio instead of gnome-vfs
- From: Uwe Scholz <uwescholz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander] Calculate the file size and directory size with gio instead of gnome-vfs
- Date: Thu, 18 Feb 2021 22:25:20 +0000 (UTC)
commit c29a47a72f66b126ec1001f979cdea73f5a8d064
Author: Uwe Scholz <u scholz83 gmx de>
Date: Thu Feb 18 23:21:55 2021 +0100
Calculate the file size and directory size with gio instead of gnome-vfs
src/gnome-cmd-file-selector.cc | 4 +-
src/gnome-cmd-file.cc | 75 +++++++++++++++++++++++++++++++++++---
src/gnome-cmd-file.h | 4 +-
src/gnome-cmd-xfer-progress-win.cc | 4 +-
src/gnome-cmd-xfer.cc | 22 ++++++-----
src/utils.cc | 69 +----------------------------------
src/utils.h | 5 +--
7 files changed, 92 insertions(+), 91 deletions(-)
---
diff --git a/src/gnome-cmd-file-selector.cc b/src/gnome-cmd-file-selector.cc
index ed83a631..2ac6ff15 100644
--- a/src/gnome-cmd-file-selector.cc
+++ b/src/gnome-cmd-file-selector.cc
@@ -98,8 +98,8 @@ inline void GnomeCmdFileSelector::update_selected_files_label()
if (!all_files)
return;
- GnomeVFSFileSize sel_bytes = 0;
- GnomeVFSFileSize total_bytes = 0;
+ guint64 sel_bytes = 0;
+ guint64 total_bytes = 0;
gint num_files = 0;
gint num_dirs = 0;
gint num_sel_files = 0;
diff --git a/src/gnome-cmd-file.cc b/src/gnome-cmd-file.cc
index d5a87e20..59c2202d 100644
--- a/src/gnome-cmd-file.cc
+++ b/src/gnome-cmd-file.cc
@@ -518,6 +518,32 @@ guint32 GnomeCmdFile::GetGfileAttributeUInt32(const char *attribute)
}
+guint64 GnomeCmdFile::GetGfileAttributeUInt64(const char *attribute)
+{
+ GError *error;
+ error = nullptr;
+ guint64 gFileAttributeUInt64 = 0;
+
+ auto gcmdFileInfo = g_file_query_info(this->gFile,
+ attribute,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ nullptr,
+ &error);
+ if (error)
+ {
+ g_message ("retrieving file info failed: %s", error->message);
+ g_error_free (error);
+ }
+ else
+ {
+ gFileAttributeUInt64 = g_file_info_get_attribute_uint64 (gcmdFileInfo, attribute);
+ g_object_unref(gcmdFileInfo);
+ }
+
+ return gFileAttributeUInt64;
+}
+
+
gchar *GnomeCmdFile::get_default_application_name_string()
{
auto contentType = GetGfileAttributeString (G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
@@ -667,11 +693,12 @@ const gchar *GnomeCmdFile::get_size()
if (GetGfileAttributeUInt32(G_FILE_ATTRIBUTE_STANDARD_TYPE) == G_FILE_TYPE_DIRECTORY)
return dir_indicator;
- return size2string (info->size, gnome_cmd_data.options.size_disp_mode);
+ auto size = GetGfileAttributeUInt64(G_FILE_ATTRIBUTE_STANDARD_SIZE);
+ return size2string (size, gnome_cmd_data.options.size_disp_mode);
}
-GnomeVFSFileSize GnomeCmdFile::get_tree_size()
+guint64 GnomeCmdFile::get_tree_size()
{
if (GetGfileAttributeUInt32(G_FILE_ATTRIBUTE_STANDARD_TYPE) != G_FILE_TYPE_DIRECTORY)
return info->size;
@@ -679,17 +706,53 @@ GnomeVFSFileSize GnomeCmdFile::get_tree_size()
if (is_dotdot)
return 0;
- if (priv->tree_size != (GnomeVFSFileSize)-1)
+ if (priv->tree_size != (guint64)-1)
return priv->tree_size;
- GnomeVFSURI *uri = get_uri();
- priv->tree_size = calc_tree_size (uri,nullptr);
- gnome_vfs_uri_unref (uri);
+ priv->tree_size = calc_tree_size (nullptr);
return priv->tree_size;
}
+guint64 GnomeCmdFile::calc_tree_size (gulong *count)
+{
+ g_return_val_if_fail (this->gFile != NULL, -1);
+
+ GnomeVFSFileSize size = 0;
+
+ if (GetGfileAttributeUInt32(G_FILE_ATTRIBUTE_STANDARD_TYPE) == G_FILE_TYPE_DIRECTORY)
+ {
+ GError *error;
+ error = nullptr;
+
+ g_file_measure_disk_usage (this->gFile,
+ G_FILE_MEASURE_NONE,
+ nullptr,
+ nullptr,
+ nullptr,
+ &size,
+ nullptr,
+ nullptr,
+ &error);
+
+ if (error)
+ {
+ g_message ("calc_tree_size: closing gFileEnumerator failed: %s", error->message);
+ g_error_free (error);
+ }
+ }
+ else
+ {
+ size += GetGfileAttributeUInt32(G_FILE_ATTRIBUTE_STANDARD_SIZE);
+ if (count!=NULL) {
+ (*count)++;
+ }
+ }
+ return size;
+}
+
+
const gchar *GnomeCmdFile::get_tree_size_as_str()
{
g_return_val_if_fail (info != nullptr, nullptr);
diff --git a/src/gnome-cmd-file.h b/src/gnome-cmd-file.h
index dbb7941c..c255ce90 100644
--- a/src/gnome-cmd-file.h
+++ b/src/gnome-cmd-file.h
@@ -75,7 +75,8 @@ struct GnomeCmdFile
const gchar *get_adate(gboolean overide_disp_setting);
const gchar *get_mdate(gboolean overide_disp_setting);
const gchar *get_size();
- GnomeVFSFileSize get_tree_size();
+ guint64 get_tree_size();
+ guint64 calc_tree_size (gulong *count);
const gchar *get_tree_size_as_str();
const gchar *get_perm();
gboolean has_mime_type(const gchar *mime_type);
@@ -102,6 +103,7 @@ struct GnomeCmdFile
gboolean has_tree_size();
guint32 GetGfileAttributeUInt32(const char *attribute);
+ guint64 GetGfileAttributeUInt64(const char *attribute);
gchar *GetGfileAttributeString(const char *attribute);
gchar *get_default_application_name_string();
gchar *get_default_application_action_label(GAppInfo *gAppInfo);
diff --git a/src/gnome-cmd-xfer-progress-win.cc b/src/gnome-cmd-xfer-progress-win.cc
index 9dd9344c..75e6d6bb 100644
--- a/src/gnome-cmd-xfer-progress-win.cc
+++ b/src/gnome-cmd-xfer-progress-win.cc
@@ -159,8 +159,8 @@ GtkType gnome_cmd_xfer_progress_win_get_type ()
void gnome_cmd_xfer_progress_win_set_total_progress (GnomeCmdXferProgressWin *win,
GnomeVFSFileSize file_bytes_copied,
GnomeVFSFileSize file_size,
- GnomeVFSFileSize bytes_copied,
- GnomeVFSFileSize bytes_total)
+ guint64 bytes_copied,
+ guint64 bytes_total)
{
gfloat total_prog = bytes_total>0 ? (gdouble) bytes_copied/(gdouble) bytes_total : -1.0f;
gtk_progress_set_percentage (GTK_PROGRESS (win->totalprog), total_prog);
diff --git a/src/gnome-cmd-xfer.cc b/src/gnome-cmd-xfer.cc
index 8c487ca4..f95fc476 100644
--- a/src/gnome-cmd-xfer.cc
+++ b/src/gnome-cmd-xfer.cc
@@ -124,18 +124,20 @@ create_xfer_data (GnomeVFSXferOptions xferOptions, GList *src_uri_list, GList *d
data->done = FALSE;
data->aborted = FALSE;
+ //ToDo: Fix this to complete migration from gnome-vfs to gvfs
// 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;
- data->bytes_total = 0;
- data->files_total = 0;
- for (uris = data->src_uri_list; uris != nullptr; uris = uris->next) {
- GnomeVFSURI *uri;
- uri = (GnomeVFSURI*)uris->data;
- data->bytes_total += calc_tree_size(uri,&(data->files_total));
- }
- }
+ //if (xferOptions == GNOME_VFS_XFER_REMOVESOURCE) {
+ // GList *uris;
+ // data->bytes_total = 0;
+ // data->files_total = 0;
+ // for (uris = data->src_uri_list; uris != nullptr; uris = uris->next) {
+ // GnomeVFSURI *uri;
+ // uri = (GnomeVFSURI*)uris->data;
+ // data->bytes_total += calc_tree_size(uri,&(data->files_total));
+ // g_object_unref(gFile);
+ // }
+ //}
return data;
}
diff --git a/src/utils.cc b/src/utils.cc
index 6323d66a..cb214f35 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -319,7 +319,7 @@ const gchar *perm2numstring (guint32 permissions, gchar *buf, guint max)
}
-const gchar *size2string (GnomeVFSFileSize size, GnomeCmdSizeDispMode size_disp_mode)
+const gchar *size2string (guint64 size, GnomeCmdSizeDispMode size_disp_mode)
{
static gchar buf0[64];
static gchar buf1[128];
@@ -449,71 +449,6 @@ GList *strings_to_uris (gchar *data)
return uri_list;
}
-
-GnomeVFSFileSize calc_tree_size (const GnomeVFSURI *dir_uri, gulong *count)
-{
- if (!dir_uri)
- return -1;
-
- gchar *dir_uri_str = gnome_vfs_uri_to_string (dir_uri, GNOME_VFS_URI_HIDE_PASSWORD);
-
- g_return_val_if_fail (dir_uri_str != NULL, -1);
-
- GList *list = NULL;
- GnomeVFSFileSize size = 0;
-
- GnomeVFSResult result = gnome_vfs_directory_list_load (&list, dir_uri_str, GNOME_VFS_FILE_INFO_DEFAULT);
-
- 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;
- if (strcmp (info->name, ".") != 0 && strcmp (info->name, "..") != 0)
- {
- 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,count);
- gnome_vfs_uri_unref (new_dir_uri);
- }
- else
- {
- size += info->size;
- if (count!=NULL) {
- (*count)++;
- }
- }
- }
- }
-
- for (GList *i = list; i; i = i->next)
- 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 ();
- 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);
-
- return size;
-}
-
-
GList *string_history_add (GList *in, const gchar *value, guint maxsize)
{
GList *tmp = g_list_find_custom (in, (gchar *) value, (GCompareFunc) strcmp);
@@ -544,7 +479,7 @@ GList *string_history_add (GList *in, const gchar *value, guint maxsize)
}
-gchar *create_nice_size_str (GnomeVFSFileSize size)
+gchar *create_nice_size_str (guint64 size)
{
GString *s = g_string_sized_new (64);
diff --git a/src/utils.h b/src/utils.h
index 4666d265..9dab26b3 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -137,7 +137,7 @@ const gchar *type2string (guint32 type, gchar *buf, guint max);
const gchar *perm2string (guint32 permissions, gchar *buf, guint max);
const gchar *perm2textstring (guint32 permissions, gchar *buf, guint max);
const gchar *perm2numstring (guint32 permissions, gchar *buf, guint max);
-const gchar *size2string (GnomeVFSFileSize size, GnomeCmdSizeDispMode size_disp_mode);
+const gchar *size2string (guint64 size, GnomeCmdSizeDispMode size_disp_mode);
const gchar *time2string (time_t t, const gchar *date_format);
void clear_event_key (GdkEventKey *event);
@@ -186,8 +186,7 @@ inline gboolean state_is_ctrl_alt_shift (gint state)
GList *strings_to_uris (gchar *data);
-GnomeVFSFileSize calc_tree_size (const GnomeVFSURI *dir_uri, gulong *count);
-gchar *create_nice_size_str (GnomeVFSFileSize size);
+gchar *create_nice_size_str (guint64 size);
inline gchar *quote_if_needed (const gchar *in)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]