[tracker/tracker-0.10] libtracker-miner: Ignore mtime difference of less than 2 seconds



commit 8bbbe8654fba3c8052d4e8bfcfd430d2e2ef49d2
Author: JÃrg Billeter <j bitron ch>
Date:   Thu Oct 20 13:12:53 2011 +0200

    libtracker-miner: Ignore mtime difference of less than 2 seconds
    
    FAT stores timestamps with 2 second granularity.
    
    Fixes NB#287278.

 src/libtracker-miner/tracker-miner-fs.c |   35 +++++++++++++++----------------
 1 files changed, 17 insertions(+), 18 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index b8fe5f0..4eb1d63 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -19,6 +19,7 @@
 
 #include "config.h"
 
+#include <libtracker-common/tracker-date-time.h>
 #include <libtracker-common/tracker-dbus.h>
 #include <libtracker-common/tracker-file-utils.h>
 #include <libtracker-common/tracker-log.h>
@@ -3456,9 +3457,9 @@ should_change_index_for_file (TrackerMinerFS *fs,
 {
 	GFileInfo          *file_info;
 	guint64             time;
-	time_t              mtime;
-	struct tm           t;
-	gchar              *time_str, *lookup_time;
+	time_t              mtime, lookup_mtime;
+	gchar              *lookup_time;
+	GError             *error = NULL;
 
 	/* Make sure mtime cache contains the mtimes of all files in the
 	 * same directory as the given file
@@ -3477,6 +3478,14 @@ should_change_index_for_file (TrackerMinerFS *fs,
 		return TRUE;
 	}
 
+	lookup_mtime = tracker_string_to_date (lookup_time, NULL, &error);
+	if (error) {
+		/* This should never happen. Assume that file was modified. */
+		g_critical ("should_change_index_for_file: %s", error->message);
+		g_clear_error (&error);
+		return TRUE;
+	}
+
 	file_info = g_file_query_info (file,
 	                               G_FILE_ATTRIBUTE_TIME_MODIFIED,
 	                               G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
@@ -3493,24 +3502,14 @@ should_change_index_for_file (TrackerMinerFS *fs,
 	mtime = (time_t) time;
 	g_object_unref (file_info);
 
-	gmtime_r (&mtime, &t);
-
-	time_str = g_strdup_printf ("%04d-%02d-%02dT%02d:%02d:%02dZ",
-	                            t.tm_year + 1900,
-	                            t.tm_mon + 1,
-	                            t.tm_mday,
-	                            t.tm_hour,
-	                            t.tm_min,
-	                            t.tm_sec);
-
-	if (strcmp (time_str, lookup_time) == 0) {
-		/* File already up-to-date in the database */
-		g_free (time_str);
+	if (abs (mtime - lookup_mtime) < 2) {
+		/* File already up-to-date in the database
+		 * accept 1 second difference as FAT stores timestamps
+		 * with 2 second granularity
+		 */
 		return FALSE;
 	}
 
-	g_free (time_str);
-
 	/* File either not yet in the database or mtime is different
 	 * Update in database required
 	 */



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