[tracker-miners/wip/carlosg/time_t: 10/10] tracker-miner-fs: Interpret GFileInfo uint64 times as time_t




commit ebec93102c88db8378a5d23ab7e5441762a6bb26
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Dec 16 11:42:16 2020 +0100

    tracker-miner-fs: Interpret GFileInfo uint64 times as time_t
    
    This is a time_t underneath, and forcibly interpreting it as unsigned
    will break with negative times on platforms that internally define that
    type as signed (Linux and the GNU C library between them).
    
    Deal with it as a time_t on our side, and let up to the underlying
    implementation the interpretation of negative timestamps. This relies
    on undocumented implementation details and is thus a hack.
    
    Fixes: https://gitlab.gnome.org/GNOME/tracker-miners/-/issues/155

 src/miners/fs/tracker-miner-files.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
---
diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c
index 794b85a3d..93e5d912b 100644
--- a/src/miners/fs/tracker-miner-files.c
+++ b/src/miners/fs/tracker-miner-files.c
@@ -2064,7 +2064,7 @@ miner_files_process_file (TrackerMinerFS      *fs,
        const gchar *mime_type, *graph;
        gchar *parent_urn;
        gchar *delete_properties_sparql = NULL;
-       guint64 time_;
+       time_t time_;
        GFile *parent;
        gchar *uri, *time_str;
        gboolean is_directory;
@@ -2125,7 +2125,7 @@ miner_files_process_file (TrackerMinerFS      *fs,
        tracker_resource_set_string (resource, "nfo:fileLastModified", time_str);
        g_free (time_str);
 
-       time_ = g_file_info_get_attribute_uint64 (file_info, G_FILE_ATTRIBUTE_TIME_ACCESS);
+       time_ = (time_t) g_file_info_get_attribute_uint64 (file_info, G_FILE_ATTRIBUTE_TIME_ACCESS);
        time_str = tracker_date_to_string (time_);
        tracker_resource_set_string (resource, "nfo:fileLastAccessed", time_str);
        g_free (time_str);
@@ -2181,7 +2181,7 @@ miner_files_process_file_attributes (TrackerMinerFS      *fs,
                                      TrackerSparqlBuffer *buffer)
 {
        TrackerResource *resource;
-       guint64 time_;
+       time_t time_;
        gchar *uri, *time_str;
        GDateTime *modified;
 
@@ -2204,7 +2204,7 @@ miner_files_process_file_attributes (TrackerMinerFS      *fs,
        g_free (time_str);
 
        /* Update nfo:fileLastAccessed */
-       time_ = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_ACCESS);
+       time_ = (time_t) g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_ACCESS);
        time_str = tracker_date_to_string (time_);
        tracker_resource_set_string (resource, "nfo:fileLastAccessed", time_str);
        g_free (time_str);


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