[tracker/miner-fs-dbus-api: 22/22] libtracker-miner: Allow API to bypass checks for users



commit c6be3b0aeb67c1a50fa8c52e4a4dfd9bf894dc6b
Author: Martyn Russell <martyn lanedo com>
Date:   Tue Aug 24 16:50:10 2010 +0100

    libtracker-miner: Allow API to bypass checks for users
    
    This allows the user to say, index /foo/bar and it doesn't need to be
    related to the config. This means that if it is outside the configured
    directories then it must be maintained by the application calling the
    API.

 src/libtracker-miner/tracker-miner-fs.c   |   22 ++++++++++++----------
 src/miners/fs/tracker-miner-files-index.c |   20 ++++++++++++++++++--
 2 files changed, 30 insertions(+), 12 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index d612f1a..da5cadc 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -3631,7 +3631,7 @@ check_file_parents (TrackerMinerFS *fs,
  * tracker_miner_fs_check_file:
  * @fs: a #TrackerMinerFS
  * @file: #GFile for the file to check
- * @check_parents: whether to check parents as well or not
+ * @do_checks: whether to check parents and eligibility or not
  *
  * Tells the filesystem miner to check and index a file,
  * this file must be part of the usual crawling directories
@@ -3640,7 +3640,7 @@ check_file_parents (TrackerMinerFS *fs,
 void
 tracker_miner_fs_check_file (TrackerMinerFS *fs,
                              GFile          *file,
-                             gboolean        check_parents)
+                             gboolean        do_checks)
 {
 	gboolean should_process;
 	gchar *path;
@@ -3648,7 +3648,9 @@ tracker_miner_fs_check_file (TrackerMinerFS *fs,
 	g_return_if_fail (TRACKER_IS_MINER_FS (fs));
 	g_return_if_fail (G_IS_FILE (file));
 
-	should_process = should_check_file (fs, file, FALSE);
+	if (do_checks) {
+		should_process = should_check_file (fs, file, FALSE);
+	}
 
 	path = g_file_get_path (file);
 
@@ -3657,8 +3659,7 @@ tracker_miner_fs_check_file (TrackerMinerFS *fs,
 	         path);
 
 	if (should_process) {
-		if (check_parents &&
-		    !check_file_parents (fs, file)) {
+		if (do_checks && !check_file_parents (fs, file)) {
 			return;
 		}
 
@@ -3675,7 +3676,7 @@ tracker_miner_fs_check_file (TrackerMinerFS *fs,
  * tracker_miner_fs_check_directory:
  * @fs: a #TrackerMinerFS
  * @file: #GFile for the directory to check
- * @check_parents: whether to check parents as well or not
+ * @do_checks: whether to check parents and eligibility or not
  *
  * Tells the filesystem miner to check and index a directory,
  * this file must be part of the usual crawling directories
@@ -3684,7 +3685,7 @@ tracker_miner_fs_check_file (TrackerMinerFS *fs,
 void
 tracker_miner_fs_check_directory (TrackerMinerFS *fs,
                                   GFile          *file,
-                                  gboolean        check_parents)
+                                  gboolean        do_checks)
 {
 	gboolean should_process;
 	gchar *path;
@@ -3692,7 +3693,9 @@ tracker_miner_fs_check_directory (TrackerMinerFS *fs,
 	g_return_if_fail (TRACKER_IS_MINER_FS (fs));
 	g_return_if_fail (G_IS_FILE (file));
 
-	should_process = should_check_file (fs, file, TRUE);
+	if (do_checks) {
+		should_process = should_check_file (fs, file, TRUE);
+	}
 
 	path = g_file_get_path (file);
 
@@ -3701,8 +3704,7 @@ tracker_miner_fs_check_directory (TrackerMinerFS *fs,
 	         path);
 
 	if (should_process) {
-		if (check_parents &&
-		    !check_file_parents (fs, file)) {
+		if (do_checks && !check_file_parents (fs, file)) {
 			return;
 		}
 
diff --git a/src/miners/fs/tracker-miner-files-index.c b/src/miners/fs/tracker-miner-files-index.c
index 01e4394..27d79cd 100644
--- a/src/miners/fs/tracker-miner-files-index.c
+++ b/src/miners/fs/tracker-miner-files-index.c
@@ -27,6 +27,13 @@
 #include "tracker-dbus.h"
 #include "tracker-marshal.h"
 
+/* If defined, then a file provided to be indexed MUST be a child in
+ * an configured path. if undefined, any file can be indexed, however
+ * it is up to applications to maintain files outside the configured
+ * locations.
+ */
+#undef REQUIRE_LOCATION_IN_CONFIG
+
 typedef struct {
 	guint request_id;
 	DBusGMethodInvocation *context;
@@ -296,6 +303,7 @@ tracker_miner_files_index_index_file (TrackerMinerFilesIndex  *object,
 	GFile *file, *dir;
 	GFileInfo *file_info;
 	gboolean is_dir;
+	gboolean do_checks = FALSE;
 	GError *internal_error;
 
 	tracker_dbus_async_return_if_fail (file_uri != NULL, context);
@@ -328,9 +336,14 @@ tracker_miner_files_index_index_file (TrackerMinerFilesIndex  *object,
 	is_dir = (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY);
 	g_object_unref (file_info);
 
+#ifdef REQUIRE_LOCATION_IN_CONFIG
+	do_checks = TRUE;
+#endif /* REQUIRE_LOCATION_IN_CONFIG */
+
 	if (is_dir) {
 		dir = g_object_ref (file);
 	} else {
+#ifdef REQUIRE_LOCATION_IN_CONFIG
 		if (!tracker_miner_files_check_file (file,
 		                                     tracker_config_get_ignored_file_paths (config),
 		                                     tracker_config_get_ignored_file_patterns (config))) {
@@ -342,11 +355,13 @@ tracker_miner_files_index_index_file (TrackerMinerFilesIndex  *object,
 
 			return;
 		}
+#endif /* REQUIRE_LOCATION_IN_CONFIG */
 
 		dir = g_file_get_parent (file);
 	}
 
 	if (dir) {
+#ifdef REQUIRE_LOCATION_IN_CONFIG
 		gboolean found = FALSE;
 		GSList *l;
 
@@ -404,14 +419,15 @@ tracker_miner_files_index_index_file (TrackerMinerFilesIndex  *object,
 
 			return;
 		}
+#endif /* REQUIRE_LOCATION_IN_CONFIG */
 
 		g_object_unref (dir);
 	}
 
 	if (is_dir) {
-		tracker_miner_fs_check_directory (TRACKER_MINER_FS (priv->files_miner), file, TRUE);
+		tracker_miner_fs_check_directory (TRACKER_MINER_FS (priv->files_miner), file, do_checks);
 	} else {
-		tracker_miner_fs_check_file (TRACKER_MINER_FS (priv->files_miner), file, TRUE);
+		tracker_miner_fs_check_file (TRACKER_MINER_FS (priv->files_miner), file, do_checks);
 	}
 
 	tracker_dbus_request_success (request_id, context);



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