[nautilus/wip/antoniof/search-engine-fixes-42-backport: 3/7] search-engine-recent: Use file attributes instead of metadata




commit 66c22f8b55d0a4b1bf986ab0203f5e69cde5241b
Author: Ondrej Holy <oholy redhat com>
Date:   Mon Feb 14 16:08:33 2022 +0100

    search-engine-recent: Use file attributes instead of metadata
    
    The recent search engine uses metadata of the resources to set modification
    and access times for the files. This is clearly wrong. Let's use the
    times from `GFileInfo` instead.
    
    (Backported by António Fernandes)

 src/nautilus-search-engine-recent.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)
---
diff --git a/src/nautilus-search-engine-recent.c b/src/nautilus-search-engine-recent.c
index 48d09880f..f41c883c1 100644
--- a/src/nautilus-search-engine-recent.c
+++ b/src/nautilus-search-engine-recent.c
@@ -33,7 +33,9 @@
 
 #define FILE_ATTRIBS G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN "," \
     G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP "," \
-    G_FILE_ATTRIBUTE_ACCESS_CAN_READ ","
+    G_FILE_ATTRIBUTE_ACCESS_CAN_READ "," \
+    G_FILE_ATTRIBUTE_TIME_MODIFIED "," \
+    G_FILE_ATTRIBUTE_TIME_ACCESS
 
 struct _NautilusSearchEngineRecent
 {
@@ -138,6 +140,8 @@ search_add_hits_idle (NautilusSearchEngineRecent *self,
 static gboolean
 is_file_valid_recursive (NautilusSearchEngineRecent  *self,
                          GFile                       *file,
+                         GDateTime                  **mtime,
+                         GDateTime                  **atime,
                          GError                     **error)
 {
     g_autoptr (GFileInfo) file_info = NULL;
@@ -156,6 +160,11 @@ is_file_valid_recursive (NautilusSearchEngineRecent  *self,
         return FALSE;
     }
 
+    if (mtime && atime)
+    {
+        *mtime = g_file_info_get_modification_date_time (file_info);
+        *atime = g_file_info_get_access_date_time (file_info);
+    }
 
     if (!nautilus_query_get_show_hidden_files (self->query))
     {
@@ -166,7 +175,7 @@ is_file_valid_recursive (NautilusSearchEngineRecent  *self,
 
             if (parent)
             {
-                return is_file_valid_recursive (self, parent, error);
+                return is_file_valid_recursive (self, parent, NULL, NULL, error);
             }
         }
         else
@@ -230,9 +239,8 @@ recent_thread_func (gpointer user_data)
         if (rank > 0)
         {
             NautilusSearchHit *hit;
-            time_t modified, visited;
-            g_autoptr (GDateTime) gmodified = NULL;
-            g_autoptr (GDateTime) gvisited = NULL;
+            g_autoptr (GDateTime) mtime = NULL;
+            g_autoptr (GDateTime) atime = NULL;
             g_autoptr (GError) error = NULL;
 
             if (!gtk_recent_info_is_local (info))
@@ -240,7 +248,7 @@ recent_thread_func (gpointer user_data)
                 continue;
             }
 
-            if (!is_file_valid_recursive (self, file, &error))
+            if (!is_file_valid_recursive (self, file, &mtime, &atime, &error))
             {
                 if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
                 {
@@ -277,12 +285,6 @@ recent_thread_func (gpointer user_data)
                 }
             }
 
-            modified = gtk_recent_info_get_modified (info);
-            visited = gtk_recent_info_get_visited (info);
-
-            gmodified = g_date_time_new_from_unix_local (modified);
-            gvisited = g_date_time_new_from_unix_local (visited);
-
             if (date_range != NULL)
             {
                 NautilusQuerySearchType type;
@@ -296,11 +298,11 @@ recent_thread_func (gpointer user_data)
 
                 if (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_ACCESS)
                 {
-                    target_time = visited;
+                    target_time = g_date_time_to_unix (atime);
                 }
                 else if (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_MODIFIED)
                 {
-                    target_time = modified;
+                    target_time = g_date_time_to_unix (mtime);
                 }
 
                 if (!nautilus_file_date_in_between (target_time,
@@ -312,8 +314,8 @@ recent_thread_func (gpointer user_data)
 
             hit = nautilus_search_hit_new (uri);
             nautilus_search_hit_set_fts_rank (hit, rank);
-            nautilus_search_hit_set_modification_time (hit, gmodified);
-            nautilus_search_hit_set_access_time (hit, gvisited);
+            nautilus_search_hit_set_modification_time (hit, mtime);
+            nautilus_search_hit_set_access_time (hit, atime);
 
             hits = g_list_prepend (hits, hit);
         }


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