[gnome-commander] Get the size of a file through GIO in the search section



commit 645ffad93d32459e81be9eb75567b0c29c38a0c2
Author: Uwe Scholz <u scholz83 gmx de>
Date:   Sat Jul 10 23:45:35 2021 +0200

    Get the size of a file through GIO in the search section

 src/dialogs/gnome-cmd-search-dialog.cc | 21 +++++++++++----------
 src/gnome-cmd-file.cc                  | 22 +---------------------
 src/utils.cc                           | 26 ++++++++++++++++++++++++++
 src/utils.h                            |  2 ++
 4 files changed, 40 insertions(+), 31 deletions(-)
---
diff --git a/src/dialogs/gnome-cmd-search-dialog.cc b/src/dialogs/gnome-cmd-search-dialog.cc
index 82325d98..a21f8245 100644
--- a/src/dialogs/gnome-cmd-search-dialog.cc
+++ b/src/dialogs/gnome-cmd-search-dialog.cc
@@ -289,23 +289,25 @@ gboolean SearchData::read_search_file(SearchFileData *searchfile_data, GnomeCmdF
         return FALSE;
     }
 
+    auto size = get_gfile_attribute_uint64(f->gFile, G_FILE_ATTRIBUTE_STANDARD_SIZE);
+
     if (searchfile_data->len)
     {
-      if ((searchfile_data->offset + searchfile_data->len) >= f->info->size)   // end, all has been read
-      {
-          free_search_file_data (searchfile_data);
-          return FALSE;
-      }
+        if ((searchfile_data->offset + searchfile_data->len) >= size)   // end, all has been read
+        {
+            free_search_file_data (searchfile_data);
+            return FALSE;
+        }
 
       // jump a big step backward to give the regex a chance
       searchfile_data->offset += searchfile_data->len - SEARCH_JUMP_SIZE;
-      if (f->info->size < (searchfile_data->offset + (SEARCH_BUFFER_SIZE - 1)))
-          searchfile_data->len = f->info->size - searchfile_data->offset;
+      if (size < (searchfile_data->offset + (SEARCH_BUFFER_SIZE - 1)))
+          searchfile_data->len = size - searchfile_data->offset;
       else
           searchfile_data->len = SEARCH_BUFFER_SIZE - 1;
     }
     else   // first time call of this function
-        searchfile_data->len = MIN (f->info->size, SEARCH_BUFFER_SIZE - 1);
+        searchfile_data->len = MIN (size, SEARCH_BUFFER_SIZE - 1);
 
     searchfile_data->result = gnome_vfs_seek (searchfile_data->handle, GNOME_VFS_SEEK_START, 
searchfile_data->offset);
     if (searchfile_data->result != GNOME_VFS_OK)
@@ -333,9 +335,8 @@ gboolean SearchData::read_search_file(SearchFileData *searchfile_data, GnomeCmdF
 inline gboolean SearchData::content_matches(GnomeCmdFile *f)
 {
     g_return_val_if_fail (f != NULL, FALSE);
-    g_return_val_if_fail (f->info != NULL, FALSE);
 
-    if (f->info->size==0)
+    if (get_gfile_attribute_uint64(f->gFile, G_FILE_ATTRIBUTE_STANDARD_SIZE) == 0)
         return FALSE;
 
     SearchFileData *search_file = g_new0 (SearchFileData, 1);
diff --git a/src/gnome-cmd-file.cc b/src/gnome-cmd-file.cc
index 4755b643..42d6b158 100644
--- a/src/gnome-cmd-file.cc
+++ b/src/gnome-cmd-file.cc
@@ -542,27 +542,7 @@ 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_NONE,
-                                   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;
+    return get_gfile_attribute_uint64(this->gFile, attribute);
 }
 
 
diff --git a/src/utils.cc b/src/utils.cc
index d32cca54..51f0e8f5 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -1174,6 +1174,32 @@ guint32 get_gfile_attribute_uint32(GFile *gFile, const char *attribute)
 }
 
 
+guint64 get_gfile_attribute_uint64(GFile *gFile, const char *attribute)
+{
+    GError *error;
+    error = nullptr;
+    guint64 gFileAttributeUInt64 = 0;
+
+    auto gcmdFileInfo = g_file_query_info(gFile,
+                                   attribute,
+                                   G_FILE_QUERY_INFO_NONE,
+                                   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;
+}
+
+
 gboolean get_gfile_attribute_boolean(GFile *gFile, const char *attribute)
 {
     GError *error;
diff --git a/src/utils.h b/src/utils.h
index 035ed336..c5ee6d82 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -417,4 +417,6 @@ gboolean get_gfile_attribute_boolean(GFile *gFile, const char *attribute);
 
 guint32 get_gfile_attribute_uint32(GFile *gFile, const char *attribute);
 
+guint64 get_gfile_attribute_uint64(GFile *gFile, const char *attribute);
+
 gchar *get_gfile_attribute_string(GFile *gFile, const char *attribute);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]