[tracker] Make the IndexFile DBus method handle directories.



commit 8799e7387b914313ebf2ca69f28a8e9c65a90979
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Aug 19 18:12:22 2010 +0200

    Make the IndexFile DBus method handle directories.

 src/miners/fs/tracker-miner-files-index.c |   81 +++++++++++++++++++---------
 1 files changed, 55 insertions(+), 26 deletions(-)
---
diff --git a/src/miners/fs/tracker-miner-files-index.c b/src/miners/fs/tracker-miner-files-index.c
index b7ab154..1a463f2 100644
--- a/src/miners/fs/tracker-miner-files-index.c
+++ b/src/miners/fs/tracker-miner-files-index.c
@@ -287,7 +287,9 @@ tracker_miner_files_index_index_file (TrackerMinerFilesIndex    *object,
 	TrackerMinerFilesIndexPrivate *priv;
 	TrackerConfig *config;
 	guint request_id;
-	GFile *file, *parent;
+	GFile *file, *dir;
+	GFileInfo *file_info;
+	gboolean is_dir;
 	GError *err;
 
 	tracker_dbus_async_return_if_fail (file_uri != NULL, context);
@@ -297,17 +299,52 @@ tracker_miner_files_index_index_file (TrackerMinerFilesIndex    *object,
 
 	priv = TRACKER_MINER_FILES_INDEX_GET_PRIVATE (object);
 	file = g_file_new_for_uri (file_uri);
-	parent = g_file_get_parent (file);
 
 	g_object_get (priv->files_miner,
 	              "config", &config,
 	              NULL);
 
-	if (parent) {
+	file_info = g_file_query_info (file,
+				       G_FILE_ATTRIBUTE_STANDARD_TYPE,
+	                               G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+	                               NULL, NULL);
+
+	if (!file_info) {
+			err = g_error_new_literal (1, 0, "File does not exist");
+			dbus_g_method_return_error (context, err);
+			tracker_dbus_request_success (request_id, context);
+
+			g_error_free (err);
+
+			return;
+	}
+
+	is_dir = (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY);
+	g_object_unref (file_info);
+
+	if (is_dir) {
+		dir = g_object_ref (file);
+	} else {
+		if (!tracker_miner_files_check_file (file,
+		                                     tracker_config_get_ignored_file_paths (config),
+		                                     tracker_config_get_ignored_file_patterns (config))) {
+			err = g_error_new_literal (1, 0, "File is not eligible to be indexed");
+			dbus_g_method_return_error (context, err);
+			tracker_dbus_request_success (request_id, context);
+
+			g_error_free (err);
+
+			return;
+		}
+
+		dir = g_file_get_parent (file);
+	}
+
+	if (dir) {
 		gboolean found = FALSE;
 		GSList *l;
 
-		if (!tracker_miner_files_check_directory (parent,
+		if (!tracker_miner_files_check_directory (dir,
 		                                          tracker_config_get_index_recursive_directories (config),
 		                                          tracker_config_get_index_single_directories (config),
 		                                          tracker_config_get_ignored_directory_paths (config),
@@ -324,31 +361,31 @@ tracker_miner_files_index_index_file (TrackerMinerFilesIndex    *object,
 		l = tracker_config_get_index_recursive_directories (config);
 
 		while (l && !found) {
-			GFile *dir;
+			GFile *config_dir;
 
-			dir = g_file_new_for_path ((gchar *) l->data);
+			config_dir = g_file_new_for_path ((gchar *) l->data);
 
-			if (g_file_equal (parent, dir) ||
-			    g_file_has_prefix (parent, dir)) {
+			if (g_file_equal (dir, config_dir) ||
+			    g_file_has_prefix (dir, config_dir)) {
 				found = TRUE;
 			}
 
-			g_object_unref (dir);
+			g_object_unref (config_dir);
 			l = l->next;
 		}
 
 		l = tracker_config_get_index_single_directories (config);
 
 		while (l && !found) {
-			GFile *dir;
+			GFile *config_dir;
 
-			dir = g_file_new_for_path ((gchar *) l->data);
+			config_dir = g_file_new_for_path ((gchar *) l->data);
 
-			if (g_file_equal (parent, dir)) {
+			if (g_file_equal (dir, config_dir)) {
 				found = TRUE;
 			}
 
-			g_object_unref (dir);
+			g_object_unref (config_dir);
 			l = l->next;
 		}
 
@@ -362,23 +399,15 @@ tracker_miner_files_index_index_file (TrackerMinerFilesIndex    *object,
 			return;
 		}
 
-		g_object_unref (parent);
+		g_object_unref (dir);
 	}
 
-	if (!tracker_miner_files_check_file (file,
-	                                     tracker_config_get_ignored_file_paths (config),
-	                                     tracker_config_get_ignored_file_patterns (config))) {
-		err = g_error_new_literal (1, 0, "File is not eligible to be indexed");
-		dbus_g_method_return_error (context, err);
-		tracker_dbus_request_success (request_id, context);
-
-		g_error_free (err);
-
-		return;
+	if (is_dir) {
+		tracker_miner_fs_check_directory (TRACKER_MINER_FS (priv->files_miner), file, TRUE);
+	} 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, TRUE);
-
 	tracker_dbus_request_success (request_id, context);
 	dbus_g_method_return (context);
 



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