[tracker-miners/tracker-miners-3.0] tracker-miner-fs: Use g_file_info_get_modification_date_time()



commit 7389f900caf9f8296e06f21488360fbb9e5e0f70
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Dec 28 14:21:03 2020 +0100

    tracker-miner-fs: Use g_file_info_get_modification_date_time()
    
    The interpretation of the uint64 G_FILE_ATTRIBUTE_TIME_MODIFIED value
    with mtime < 0 is fairly undefined. We interpret it literally as an
    uint64_t, but (signed) time_t is practically simply casted to it
    internally in gio. This makes negative dates seem far far in the
    future.
    
    Use the GDateTime helper instead, this will a) leave the mtime
    interpretation (bugs included) up to GLib. And b) will implicitly
    make mtimes within the expected range, given Tracker and GDateTime
    limits match.
    
    Fixes: https://gitlab.gnome.org/GNOME/tracker-miners/-/issues/155
    
    (cherry-picked from commit e04b360ed676d25434601952bee3e3bdfdd551fa)

 src/miners/fs/tracker-miner-files.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
---
diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c
index bb6289912..9ed6a8f05 100644
--- a/src/miners/fs/tracker-miner-files.c
+++ b/src/miners/fs/tracker-miner-files.c
@@ -2104,6 +2104,7 @@ process_file_cb (GObject      *object,
        GError *error = NULL;
        gboolean is_special;
        gboolean is_directory;
+       GDateTime *modified;
 
        data = user_data;
        file = G_FILE (object);
@@ -2136,6 +2137,7 @@ process_file_cb (GObject      *object,
        data->mime_type = g_strdup (mime_type);
        is_directory = (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY ?
                        TRUE : FALSE);
+       modified = g_file_info_get_modification_date_time (file_info);
 
        if (!is_directory) {
                /* In case of update: delete all information elements for the given data object
@@ -2178,8 +2180,7 @@ process_file_cb (GObject      *object,
        tracker_resource_set_int64 (resource, "nfo:fileSize",
                                    g_file_info_get_size (file_info));
 
-       time_ = g_file_info_get_attribute_uint64 (file_info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
-       time_str = tracker_date_to_string (time_);
+       time_str = g_date_time_format_iso8601 (modified);
        tracker_resource_set_string (resource, "nfo:fileLastModified", time_str);
        g_free (time_str);
 
@@ -2221,8 +2222,7 @@ process_file_cb (GObject      *object,
                graph_file = tracker_resource_new (uri);
                tracker_resource_add_uri (graph_file, "rdf:type", "nfo:FileDataObject");
 
-               time_ = g_file_info_get_attribute_uint64 (file_info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
-               time_str = tracker_date_to_string (time_);
+               time_str = g_date_time_format_iso8601 (modified);
                tracker_resource_set_string (graph_file, "nfo:fileLastModified", time_str);
                g_free (time_str);
 
@@ -2247,6 +2247,7 @@ process_file_cb (GObject      *object,
        process_file_data_free (data);
 
        g_object_run_dispose (G_OBJECT (resource));
+       g_date_time_unref (modified);
        g_object_unref (resource);
        g_object_unref (file_info);
        g_free (sparql_str);
@@ -2303,6 +2304,7 @@ process_file_attributes_cb (GObject      *object,
        GFile *file;
        gchar *uri, *time_str, *sparql_str;
        GError *error = NULL;
+       GDateTime *modified;
 
        data = user_data;
        file = G_FILE (object);
@@ -2319,9 +2321,10 @@ process_file_attributes_cb (GObject      *object,
        resource = tracker_resource_new (uri);
 
        /* Update nfo:fileLastModified */
-       time_ = g_file_info_get_attribute_uint64 (file_info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
-       time_str = tracker_date_to_string (time_);
+       modified = g_file_info_get_modification_date_time (file_info);
+       time_str = g_date_time_format_iso8601 (modified);
        tracker_resource_set_string (resource, "nfo:fileLastModified", time_str);
+       g_date_time_unref (modified);
        g_free (time_str);
 
        /* Update nfo:fileLastAccessed */


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