[tracker/crawling-interval] Add CrawlingInterval configuration option.



commit d8ec726edc57750c5d71e10ab5abadef2432bf28
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Apr 28 15:23:37 2010 +0200

    Add CrawlingInterval configuration option.
    
    This either forever enables mtime queries for initial crawling, disables it,
    or specified an interval in days until the next crawling.
    
    The other use of crawling (setting up monitors) is unavoidable.

 src/libtracker-miner/tracker-miner-fs.c |   46 ++++++++++++++++++--
 src/libtracker-miner/tracker-miner-fs.h |    5 ++
 src/miners/fs/tracker-config.c          |   13 ++++++
 src/miners/fs/tracker-main.c            |   69 +++++++++++++++++++++++++++++++
 4 files changed, 128 insertions(+), 5 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 3e22a10..eacd208 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -140,6 +140,7 @@ struct TrackerMinerFSPrivate {
 	guint           is_paused : 1;
 	guint           is_crawling : 1;
 	guint		mtime_checking : 1;
+	guint		initial_crawling : 1;
 
 	/* Statistics */
 	guint           total_directories_found;
@@ -182,7 +183,8 @@ enum {
 	PROP_0,
 	PROP_THROTTLE,
 	PROP_POOL_LIMIT,
-	PROP_MTIME_CHECKING
+	PROP_MTIME_CHECKING,
+	PROP_INITIAL_CRAWLING
 };
 
 static void           fs_finalize                         (GObject              *object);
@@ -307,12 +309,20 @@ tracker_miner_fs_class_init (TrackerMinerFSClass *klass)
 	                                                    1, G_MAXUINT, 1,
 	                                                    G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 	g_object_class_install_property (object_class,
-	                                 PROP_MTIME_CHECKING,
+ 	                                 PROP_MTIME_CHECKING,
 	                                 g_param_spec_boolean ("mtime-checking",
 	                                                       "Mtime checking",
 	                                                       "Whether to perform mtime checks during initial crawling or not",
 	                                                       TRUE,
 	                                                       G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+	g_object_class_install_property (object_class,
+	                                 PROP_INITIAL_CRAWLING,
+	                                 g_param_spec_boolean ("initial-crawling",
+	                                                       "Initial crawling",
+	                                                       "Whether to perform initial crawling or not",
+	                                                       TRUE,
+	                                                       G_PARAM_READWRITE));
+
 	/**
 	 * TrackerMinerFS::check-file:
 	 * @miner_fs: the #TrackerMinerFS
@@ -546,6 +556,7 @@ tracker_miner_fs_init (TrackerMinerFS *object)
 	                                         (GDestroyNotify) g_free);
 
 	priv->mtime_checking = TRUE;
+	priv->initial_crawling = TRUE;
 }
 
 static ProcessData *
@@ -696,6 +707,9 @@ fs_set_property (GObject      *object,
 		break;
 	case PROP_MTIME_CHECKING:
 		fs->private->mtime_checking = g_value_get_boolean (value);
+                break;
+	case PROP_INITIAL_CRAWLING:
+		fs->private->initial_crawling = g_value_get_boolean (value);
 		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -722,6 +736,9 @@ fs_get_property (GObject    *object,
 		break;
 	case PROP_MTIME_CHECKING:
 		g_value_set_boolean (value, fs->private->mtime_checking);
+                break;
+	case PROP_INITIAL_CRAWLING:
+		g_value_set_boolean (value, fs->private->initial_crawling);
 		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -2513,8 +2530,9 @@ crawler_check_file_cb (TrackerCrawler *crawler,
 	TrackerMinerFS *fs = user_data;
 
 	if (!fs->private->been_crawled &&
-	    !fs->private->mtime_checking) {
-                return FALSE;
+	    (!fs->private->mtime_checking ||
+             !fs->private->initial_crawling)) {
+		return FALSE;
 	}
 
 	return should_process_file (fs, file, FALSE);
@@ -2537,7 +2555,8 @@ crawler_check_directory_cb (TrackerCrawler *crawler,
                 gboolean should_change_index;
 
 		if (!fs->private->been_crawled &&
-		    !fs->private->mtime_checking) {
+		    (!fs->private->mtime_checking ||
+                     !fs->private->initial_crawling)) {
 			should_change_index = FALSE;
 		} else {
 			should_change_index = should_change_index_for_file (fs, file);
@@ -3251,3 +3270,20 @@ tracker_miner_fs_force_recheck (TrackerMinerFS *fs)
 
 	crawl_directories_start (fs);
 }
+
+void
+tracker_miner_fs_set_initial_crawling (TrackerMinerFS *fs,
+                                       gboolean        do_initial_crawling)
+{
+        g_return_if_fail (TRACKER_IS_MINER_FS (fs));
+
+        fs->private->initial_crawling = do_initial_crawling;
+}
+
+gboolean
+tracker_miner_fs_get_initial_crawling (TrackerMinerFS *fs)
+{
+        g_return_val_if_fail (TRACKER_IS_MINER_FS (fs), FALSE);
+
+        return fs->private->initial_crawling;
+}
diff --git a/src/libtracker-miner/tracker-miner-fs.h b/src/libtracker-miner/tracker-miner-fs.h
index 61b628d..5105e1e 100644
--- a/src/libtracker-miner/tracker-miner-fs.h
+++ b/src/libtracker-miner/tracker-miner-fs.h
@@ -112,6 +112,11 @@ G_CONST_RETURN gchar *tracker_miner_fs_get_parent_urn   (TrackerMinerFS *fs,
                                                          GFile          *file);
 void                  tracker_miner_fs_force_recheck    (TrackerMinerFS *fs);
 
+void                  tracker_miner_fs_set_initial_crawling (TrackerMinerFS *fs,
+                                                             gboolean        do_initial_crawling);
+gboolean              tracker_miner_fs_get_initial_crawling (TrackerMinerFS *fs);
+
+
 G_END_DECLS
 
 #endif /* __LIBTRACKER_MINER_MINER_FS_H__ */
diff --git a/src/miners/fs/tracker-config.c b/src/miners/fs/tracker-config.c
index 92a6c91..954b84c 100644
--- a/src/miners/fs/tracker-config.c
+++ b/src/miners/fs/tracker-config.c
@@ -37,6 +37,7 @@
 #define GROUP_GENERAL                            "General"
 #define GROUP_MONITORS                           "Monitors"
 #define GROUP_INDEXING                           "Indexing"
+#define GROUP_CRAWLING                           "Crawling"
 
 /* Default values */
 #define DEFAULT_VERBOSITY                        0
@@ -335,6 +336,18 @@ tracker_config_class_init (TrackerConfigClass *klass)
 	                                                   DEFAULT_CRAWLING_INTERVAL,
 	                                                   G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
+        /* Crawling */
+	g_object_class_install_property (object_class,
+	                         PROP_CRAWLING_INTERVAL,
+	                                 g_param_spec_int ("crawling-interval",
+	                                                   "Crawling interval",
+	                                                   " Interval at which startup crawling may happen. 0 is always, -1 is never,"
+	                                                   " and any number > 0 is the crawling interval in number of days.",
+	                                                   -1,
+	                                                   G_MAXINT,
+	                                                   DEFAULT_CRAWLING_INTERVAL,
+	                                                   G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
 	g_type_class_add_private (object_class, sizeof (TrackerConfigPrivate));
 }
 
diff --git a/src/miners/fs/tracker-main.c b/src/miners/fs/tracker-main.c
index 0e3e50c..9016b0c 100644
--- a/src/miners/fs/tracker-main.c
+++ b/src/miners/fs/tracker-main.c
@@ -194,6 +194,68 @@ initialize_priority (void)
 	}
 }
 
+static gboolean
+should_crawl (TrackerConfig *config)
+{
+	gint crawling_interval;
+
+	if (G_UNLIKELY (!crawl_timestamp_file)) {
+		crawl_timestamp_file = g_build_filename (g_get_user_cache_dir (),
+		                                         "tracker",
+		                                         "crawling-timestamp.txt",
+		                                         NULL);
+	}
+
+	crawling_interval = tracker_config_get_crawling_interval (config);
+
+	g_message ("Checking whether to perform mtime checks during crawling:");
+
+	if (crawling_interval == -1) {
+		g_message ("  Disabled");
+		return FALSE;
+	} else if (crawling_interval == 0) {
+		g_message ("  Enabled");
+		return TRUE;
+	} else {
+		guint64 then, now;
+		gchar *content;
+
+		if (!g_file_get_contents (crawl_timestamp_file, &content, NULL, NULL)) {
+			g_message ("  No previous timestamp, crawling forced");
+			return TRUE;
+		}
+
+		now = (guint64) time (NULL);
+
+		then = g_ascii_strtoull (content, NULL, 10);
+		g_free (content);
+
+		if (now < then + (crawling_interval * SECONDS_PER_DAY)) {
+			g_message ("  Postponed");
+			return FALSE;
+		} else {
+			g_message ("  (More than) %d days after last crawling, enabled", crawling_interval);
+			return FALSE;
+		}
+	}
+}
+
+static void
+save_crawling_time (void)
+{
+	GError *error = NULL;
+	gchar *content;
+
+	content = g_strdup_printf ("%" G_GUINT64_FORMAT, (guint64) time (NULL));
+
+	g_file_set_contents (crawl_timestamp_file, content, -1, &error);
+
+	if (error) {
+		g_critical ("Could not save crawling timestamp: %s", error->message);
+		g_error_free (error);
+	}
+}
+
 static void
 miner_handle_next (void)
 {
@@ -244,6 +306,11 @@ miner_finished_cb (TrackerMinerFS *fs,
 		return;
 	}
 
+	if (TRACKER_IS_MINER_FILES (fs) &&
+	    tracker_miner_fs_get_initial_crawling (fs)) {
+		save_crawling_time ();
+	}
+
 	miner_handle_next ();
 }
 
@@ -588,6 +655,8 @@ main (gint argc, gchar *argv[])
 
 	if (!add_file) {
 		miner_files = tracker_miner_files_new (config);
+		tracker_miner_fs_set_initial_crawling (TRACKER_MINER_FS (miner_files),
+		                                       should_crawl (config));
 	} else {
 		GFile *file;
 



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