tracker r1358 - in branches/indexer-split: . src/libtracker-common src/trackerd



Author: mr
Date: Tue May  6 14:48:57 2008
New Revision: 1358
URL: http://svn.gnome.org/viewvc/tracker?rev=1358&view=rev

Log:
	* src/trackerd/tracker-apps.c:
	* src/trackerd/tracker-email-utils.c:
	* src/trackerd/tracker-process-files.c:
	* src/trackerd/tracker-service-manager.[ch]:
	* src/trackerd/tracker-utils.[ch]:
	* src/trackerd/trackerd.c: Moved all tracker_add_service_dir() API
	to tracker-service-manager and renamed it accordingly. This was
	moved out of tracker-utils.[ch].


Modified:
   branches/indexer-split/ChangeLog
   branches/indexer-split/src/libtracker-common/tracker-file-utils.c
   branches/indexer-split/src/libtracker-common/tracker-file-utils.h
   branches/indexer-split/src/trackerd/tracker-apps.c
   branches/indexer-split/src/trackerd/tracker-email-utils.c
   branches/indexer-split/src/trackerd/tracker-process-files.c
   branches/indexer-split/src/trackerd/tracker-service-manager.c
   branches/indexer-split/src/trackerd/tracker-service-manager.h
   branches/indexer-split/src/trackerd/tracker-service.c
   branches/indexer-split/src/trackerd/tracker-utils.c
   branches/indexer-split/src/trackerd/tracker-utils.h
   branches/indexer-split/src/trackerd/trackerd.c

Modified: branches/indexer-split/src/libtracker-common/tracker-file-utils.c
==============================================================================
--- branches/indexer-split/src/libtracker-common/tracker-file-utils.c	(original)
+++ branches/indexer-split/src/libtracker-common/tracker-file-utils.c	Tue May  6 14:48:57 2008
@@ -418,3 +418,50 @@
 
 	return g_strdup (" ");
 }
+
+void
+tracker_dir_remove (const gchar *uri)
+{
+	GQueue *dirs;
+	GSList *dirs_to_remove = NULL;
+
+	g_return_if_fail (uri != NULL);
+
+	dirs = g_queue_new ();
+
+	g_queue_push_tail (dirs, g_strdup (uri));
+
+	while (!g_queue_is_empty (dirs)) {
+		GDir  *p;
+		gchar *dir;
+
+		dir = g_queue_pop_head (dirs);
+		dirs_to_remove = g_slist_prepend (dirs_to_remove, dir);
+
+		if ((p = g_dir_open (dir, 0, NULL))) {
+			const gchar *file;
+
+			while ((file = g_dir_read_name (p))) {
+				gchar *full_filename;
+
+				full_filename = g_build_filename (dir, file, NULL);
+
+				if (g_file_test (full_filename, G_FILE_TEST_IS_DIR)) {
+					g_queue_push_tail (dirs, full_filename);
+				} else {
+					g_unlink (full_filename);
+					g_free (full_filename);
+				}
+			}
+
+			g_dir_close (p);
+		}
+	}
+
+	g_queue_free (dirs);
+
+	/* Remove directories (now they are empty) */
+	g_slist_foreach (dirs_to_remove, (GFunc) g_rmdir, NULL);
+	g_slist_foreach (dirs_to_remove, (GFunc) g_free, NULL);
+	g_slist_free (dirs_to_remove);
+}

Modified: branches/indexer-split/src/libtracker-common/tracker-file-utils.h
==============================================================================
--- branches/indexer-split/src/libtracker-common/tracker-file-utils.h	(original)
+++ branches/indexer-split/src/libtracker-common/tracker-file-utils.h	Tue May  6 14:48:57 2008
@@ -36,4 +36,6 @@
 gchar *  tracker_file_get_vfs_path  (const gchar *uri);
 gchar *  tracker_file_get_vfs_name  (const gchar *uri);
 
+void     tracker_dir_remove         (const gchar *uri);
+
 #endif /* __TRACKER_FILE_UTILS_H__ */

Modified: branches/indexer-split/src/trackerd/tracker-apps.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-apps.c	(original)
+++ branches/indexer-split/src/trackerd/tracker-apps.c	Tue May  6 14:48:57 2008
@@ -45,7 +45,7 @@
 		/* Add user defined applications path to service directory list */
 		if (dir) {
 			tracker_log ("Registering path %s as belonging to service Applications", dir);
-			tracker_add_service_path ("Applications", dir);
+			tracker_service_directories_add ("Applications", dir);
 			g_free (dir);
 		}
 		
@@ -59,7 +59,7 @@
 			for (i = 0; dir_array[i] != NULL; ++i) {
 				dir = g_strdup_printf ("%s/applications", dir_array[i]);
 				tracker_info ("Registering path %s as belonging to service Applications", dir);
-				tracker_add_service_path ("Applications", dir);
+				tracker_service_directories_add ("Applications", dir);
 				g_free (dir);	
 			}
 			g_strfreev (dir_array);
@@ -67,8 +67,8 @@
 		} else {
 			tracker_log ("Registering path %s as belonging to service Applications", "/usr/local/share/applications");
 			tracker_log ("Registering path %s as belonging to service Applications", "/usr/share/applications");
-			tracker_add_service_path ("Applications", "/usr/local/share/applications");
-			tracker_add_service_path ("Applications", "/usr/share/applications");
+			tracker_service_directories_add ("Applications", "/usr/local/share/applications");
+			tracker_service_directories_add ("Applications", "/usr/share/applications");
 		}
 	}
 }

Modified: branches/indexer-split/src/trackerd/tracker-email-utils.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-email-utils.c	(original)
+++ branches/indexer-split/src/trackerd/tracker-email-utils.c	Tue May  6 14:48:57 2008
@@ -63,14 +63,14 @@
 email_unwatch_directory (const gchar *dir, const gchar *service)
 {
 	tracker_log ("Registering path %s as belonging to service %s", dir, service);
-	tracker_del_service_path (service, dir);
+	tracker_service_directories_remove (service, dir);
 }
 
 void
 email_watch_directory (const gchar *dir, const gchar *service)
 {
 	tracker_log ("Registering path %s as belonging to service %s", dir, service);
-	tracker_add_service_path (service, dir);
+	tracker_service_directories_add (service, dir);
 }
 
 

Modified: branches/indexer-split/src/trackerd/tracker-process-files.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-process-files.c	(original)
+++ branches/indexer-split/src/trackerd/tracker-process-files.c	Tue May  6 14:48:57 2008
@@ -471,7 +471,7 @@
 		tracker_throttle (100);
 	}
 
-	service_info = tracker_get_service_for_uri (info->uri);
+	service_info = tracker_service_directories_get_service (info->uri);
 
 	if (!service_info) {
 		tracker_error ("ERROR: cannot find service for path %s", info->uri);
@@ -665,7 +665,7 @@
         
         tracker_applications_add_service_directories ();
         
-        list = tracker_get_service_dirs ("Applications");
+        list = tracker_service_directories_get ("Applications");
         process_directory_list (tracker, list, FALSE);
 
         tracker_db_interface_end_transaction (db_con->cache->db);
@@ -963,13 +963,13 @@
         
         if (tracker_file_is_valid (gaim)) {
                 has_logs = TRUE;
-                tracker_add_service_path ("GaimConversations", gaim);
+                tracker_service_directories_add ("GaimConversations", gaim);
                 list = g_slist_prepend (NULL, gaim);
         }
 
         if (tracker_file_is_valid (purple)) {
                 has_logs = TRUE;
-                tracker_add_service_path ("GaimConversations", purple);
+                tracker_service_directories_add ("GaimConversations", purple);
                 list = g_slist_prepend (NULL, purple);
         }
         
@@ -1005,7 +1005,7 @@
                 list = g_slist_prepend( NULL, firefox_dir);
                 
                 tracker_log ("Starting Firefox web history indexing...");
-                tracker_add_service_path ("WebHistory", firefox_dir);
+                tracker_service_directories_add ("WebHistory", firefox_dir);
                 
                 tracker_db_interface_start_transaction (db_con->cache->db);
                 process_directory_list (tracker, list, TRUE);
@@ -1065,7 +1065,7 @@
                 if (name) {
                         GSList *list;
 
-                        list = tracker_get_service_dirs (name);
+                        list = tracker_service_directories_get (name);
                         process_directory_list (tracker, list, TRUE);
                         g_slist_free (list);
                 }

Modified: branches/indexer-split/src/trackerd/tracker-service-manager.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-service-manager.c	(original)
+++ branches/indexer-split/src/trackerd/tracker-service-manager.c	Tue May  6 14:48:57 2008
@@ -24,6 +24,9 @@
 
 #include <glib.h>
 
+#include <libtracker-common/tracker-log.h>
+#include <libtracker-common/tracker-file-utils.h>
+
 #include "tracker-service-manager.h"
 
 typedef struct {
@@ -41,7 +44,14 @@
 static GHashTable *mime_service;       
 
 /* List of ServiceMimePrefixes */
-static GSList *mime_prefix_service; 
+static GSList     *mime_prefix_service; 
+
+/* The service directory table is used to store a ServiceInfo struct
+ * for a directory path - used for determining which service a uri
+ * belongs to for things like files, emails, conversations etc 
+ */ 
+static GHashTable *service_directory_table;
+static GSList	  *service_directory_list;
 
 static void
 service_manager_mime_prefix_foreach (gpointer data, 
@@ -105,11 +115,17 @@
 					      g_str_equal, 
 					      NULL, 
 					      NULL);
+
+	service_directory_table = g_hash_table_new_full (g_str_hash, 
+							 g_str_equal, 
+							 g_free, 
+							 g_free);
 }
 
 void
 tracker_service_manager_term (void)
 {
+	g_hash_table_remove_all (service_directory_table);
 	g_hash_table_remove_all (service_id_table);
 	g_hash_table_remove_all (service_table);
 	g_hash_table_remove_all (mime_service);
@@ -431,3 +447,95 @@
 
 	return tracker_service_get_show_service_directories (service);
 }
+
+/*
+ * Service directories
+ */
+GSList *
+tracker_service_directories_get (const gchar *service)
+{
+	GSList *list = NULL;
+	GSList *l;
+
+	g_return_val_if_fail (service != NULL, NULL);
+
+	for (l = service_directory_list; l; l = l->next) {
+		gchar *str;
+		
+		str = g_hash_table_lookup (service_directory_table, l->data);
+
+		if (strcasecmp (service, str) == 0) {
+			list = g_slist_prepend (list, l->data);
+		}
+	}
+
+	return list;
+}
+
+void
+tracker_service_directories_add (const gchar *service,  
+				 const gchar *path)
+{
+	g_return_if_fail (service != NULL);
+	g_return_if_fail (path != NULL);
+	
+	if (!tracker_file_is_valid (path)) {
+		tracker_debug ("Path:'%s' not valid, not adding it for service:'%s'", path, service);
+		return;
+	}
+
+	tracker_debug ("Adding path:'%s' for service:'%s'", path, service);
+
+	service_directory_list = g_slist_prepend (service_directory_list, 
+						  g_strdup (path));
+
+	g_hash_table_insert (service_directory_table, 
+			     g_strdup (path), 
+			     g_strdup (service));
+}
+
+void
+tracker_service_directories_remove (const gchar *service,  
+				    const gchar *path)
+{
+	GSList *found;
+
+	g_return_if_fail (service != NULL);
+	g_return_if_fail (path != NULL);
+
+	tracker_debug ("Removing path:'%s' for service:'%s'", path, service);
+
+	found = g_slist_find_custom (service_directory_list, 
+				     path, 
+				     (GCompareFunc) strcmp);
+	if (found) {
+		service_directory_list = g_slist_remove_link (service_directory_list, found);
+		g_free (found->data);
+		g_slist_free (found);
+	}
+
+	g_hash_table_remove (service_directory_table, path);
+}
+
+gchar *
+tracker_service_directories_get_service (const gchar *path)
+{
+	GSList *l;
+
+	g_return_val_if_fail (path != NULL, g_strdup ("Files"));
+
+	/* Check service dir list to see if a prefix */
+	for (l = service_directory_list; l; l = l->next) {
+		const gchar *str;
+
+		if (!l->data || !g_str_has_prefix (path, l->data)) {
+                        continue;
+                }
+		
+		str = g_hash_table_lookup (service_directory_table, l->data);
+
+		return g_strdup (str);
+	}
+
+	return g_strdup ("Files");
+}

Modified: branches/indexer-split/src/trackerd/tracker-service-manager.h
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-service-manager.h	(original)
+++ branches/indexer-split/src/trackerd/tracker-service-manager.h	Tue May  6 14:48:57 2008
@@ -52,6 +52,14 @@
 gboolean        tracker_service_manager_show_service_directories     (const gchar    *service_str);
 gboolean        tracker_service_manager_show_service_files           (const gchar    *service_str);
 
+/* Service directories */
+GSList *        tracker_service_directories_get                      (const gchar    *service);
+void            tracker_service_directories_add                      (const gchar    *service,
+								      const gchar    *path);
+void            tracker_service_directories_remove                   (const gchar    *service,
+								      const gchar    *path);
+gchar *         tracker_service_directories_get_service              (const gchar    *path);
+
 G_END_DECLS
 
 #endif /* __TRACKER_SERVICE_MANAGER_H__ */

Modified: branches/indexer-split/src/trackerd/tracker-service.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-service.c	(original)
+++ branches/indexer-split/src/trackerd/tracker-service.c	Tue May  6 14:48:57 2008
@@ -785,3 +785,4 @@
 	priv->show_service_directories = value;
 	g_object_notify (G_OBJECT (service), "show-service-directories");
 }
+

Modified: branches/indexer-split/src/trackerd/tracker-utils.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-utils.c	(original)
+++ branches/indexer-split/src/trackerd/tracker-utils.c	Tue May  6 14:48:57 2008
@@ -121,60 +121,6 @@
 	return g_string_free (gs, FALSE);
 }
 
-
-
-void
-tracker_remove_dirs (const char *root_dir)
-{
-	GQueue *dirs;
-	GSList *dirs_to_remove;
-
-	dirs = g_queue_new ();
-
-	g_queue_push_tail (dirs, g_strdup (root_dir));
-
-	dirs_to_remove = NULL;
-
-	while (!g_queue_is_empty (dirs)) {
-		char *dir;
-		GDir *dirp;
-
-		dir = g_queue_pop_head (dirs);
-
-		dirs_to_remove = g_slist_prepend (dirs_to_remove, dir);
-
-		if ((dirp = g_dir_open (dir, 0, NULL))) {
-			const char *file;
-
-			while ((file = g_dir_read_name (dirp))) {
-				char *full_filename;
-
-				full_filename = g_build_filename (dir, file, NULL);
-
-				if (g_file_test (full_filename, G_FILE_TEST_IS_DIR)) {
-					g_queue_push_tail (dirs, full_filename);
-				} else {
-					g_unlink (full_filename);
-					g_free (full_filename);
-				}
-			}
-
-			g_dir_close (dirp);
-		}
-	}
-
-	g_queue_free (dirs);
-
-	/* remove directories (now they are empty) */
-	g_slist_foreach (dirs_to_remove, (GFunc) g_rmdir, NULL);
-
-	g_slist_foreach (dirs_to_remove, (GFunc) g_free, NULL);
-
-	g_slist_free (dirs_to_remove);
-}
-
-
-
 char *
 tracker_format_search_terms (const char *str, gboolean *do_bool_search)
 {
@@ -247,98 +193,6 @@
 	tracker_log ("Total allocations = %d, total deallocations = %d", info_allocated, info_deallocated);
 }
 
-
-
-
-GSList *
-tracker_get_service_dirs (const char *service)
-{
-	GSList *list = NULL, *tmp;
-
-	if (!service) {
-		return NULL;
-	}
-
-	for (tmp = tracker->service_directory_list; tmp; tmp = tmp->next) {
-
-		char *path = (char *) tmp->data;
-		char *path_service = g_hash_table_lookup (tracker->service_directory_table, path);
-
-		if (strcasecmp (service, path_service) ==0) {
-			list = g_slist_prepend (list, path);
-		}
-	}
-
-	return list;
-}
-
-
-void
-tracker_add_service_path (const char *service,  const char *path)
-{
-	if (!service || 
-            !path || 
-            !tracker_file_is_valid (path)) {
-		return;
-	}
-
-	char *dir_path = g_strdup (path);
-	char *service_type = g_strdup (service);
-
-	tracker->service_directory_list = g_slist_prepend (tracker->service_directory_list, g_strdup (path));
-	g_hash_table_insert (tracker->service_directory_table, dir_path, service_type);
-}
-
-
-void
-tracker_del_service_path (const char *service,  const char *path)
-{
-	if (!service || !path) {
-		return;
-	}
-	GSList *found = g_slist_find_custom (tracker->service_directory_list, path, (GCompareFunc) strcmp);
-	if (found) {
-		g_free (found->data);
-		tracker->service_directory_list = g_slist_remove_link (tracker->service_directory_list, found);
-		g_slist_free (found);
-	}
-	g_hash_table_remove (tracker->service_directory_table, path);
-}
-
-char *
-tracker_get_service_for_uri (const char *uri)
-{
-	GSList *tmp;
-
-	/* check service dir list to see if a prefix */
-	for (tmp = tracker->service_directory_list; tmp; tmp = tmp->next) {
-		char *prefix;
-
-		prefix = (char *) tmp->data;
-		if (prefix && g_str_has_prefix (uri, prefix)) {
-			return g_strdup (g_hash_table_lookup (tracker->service_directory_table, prefix));
-		}
-	}
-
-	return g_strdup ("Files");
-}
-
-
-gboolean
-tracker_is_service_file (const char *uri)
-{
-	char *service;
-	gboolean result;
-
-	service = tracker_get_service_for_uri (uri);
-
-	result =  (service && strcmp (service, "Files") != 0);
-
-	g_free (service);
-
-	return result;
-}
-
 void
 tracker_throttle (int multiplier)
 {

Modified: branches/indexer-split/src/trackerd/tracker-utils.h
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-utils.h	(original)
+++ branches/indexer-split/src/trackerd/tracker-utils.h	Tue May  6 14:48:57 2008
@@ -231,10 +231,6 @@
 
 	char *		xesam_dir;
 
-	/* service directory table - this is used to store a ServiceInfo struct for a directory path - used for determining which service a uri belongs to for things like files, emails, conversations etc*/
-	GHashTable	*service_directory_table;
-	GSList		*service_directory_list;
-
 	/* lookup tables for service and metadata IDs */
 	GHashTable	*metadata_table;
 
@@ -311,16 +307,8 @@
 char *		tracker_escape_metadata 	(const char *in);
 char *		tracker_unescape_metadata 	(const char *in);
 
-void		tracker_remove_dirs 		(const char *root_dir);
 char *		tracker_format_search_terms 	(const char *str, gboolean *do_bool_search);
 
-GSList *	tracker_get_service_dirs 	(const char *service);
-void		tracker_add_service_path 	(const char *service, const char *path);
-void		tracker_del_service_path 	(const char *service,  const char *path);
-
-char *		tracker_get_service_for_uri 	(const char *uri);
-gboolean	tracker_is_service_file 	(const char *uri);
-
 GSList * 	tracker_get_watch_root_dirs 	(void);
 
 void		tracker_print_object_allocations (void);

Modified: branches/indexer-split/src/trackerd/trackerd.c
==============================================================================
--- branches/indexer-split/src/trackerd/trackerd.c	(original)
+++ branches/indexer-split/src/trackerd/trackerd.c	Tue May  6 14:48:57 2008
@@ -290,7 +290,7 @@
 
 
 	if (tracker->reindex) {
-		tracker_remove_dirs (tracker->data_dir);
+		tracker_dir_remove (tracker->data_dir);
 		g_mkdir_with_parents (tracker->data_dir, 00755);
 	}
 
@@ -305,7 +305,7 @@
 
 	/* remove sys tmp directory */
 	if (tracker->sys_tmp_root_dir) {
-		tracker_remove_dirs (tracker->sys_tmp_root_dir);
+		tracker_dir_remove (tracker->sys_tmp_root_dir);
 	}
 
 	/* remove file change queue */
@@ -533,10 +533,6 @@
                                                          g_str_equal, 
                                                          NULL, 
                                                          NULL);
-	tracker->service_directory_table = g_hash_table_new_full (g_str_hash, 
-                                                                  g_str_equal, 
-                                                                  g_free, 
-                                                                  g_free);
 }
 
 static void
@@ -696,14 +692,14 @@
 
 	/* Remove an existing one */
 	if (g_file_test (tracker->sys_tmp_root_dir, G_FILE_TEST_EXISTS)) {
-		tracker_remove_dirs (tracker->sys_tmp_root_dir);
+		tracker_dir_remove (tracker->sys_tmp_root_dir);
 	}
 
 	/* Remove old tracker dirs */
         old_tracker_dir = g_build_filename (g_get_home_dir (), ".Tracker", NULL);
 
 	if (g_file_test (old_tracker_dir ,G_FILE_TEST_EXISTS)) {
-		tracker_remove_dirs (old_tracker_dir);
+		tracker_dir_remove (old_tracker_dir);
 	}
 
 	g_free (old_tracker_dir);
@@ -726,7 +722,7 @@
 	tracker->xesam_dir = g_build_filename (g_get_home_dir (), ".xesam", NULL);
 
 	if (reindex || tracker_db_needs_setup ()) {
-		tracker_remove_dirs (tracker->data_dir);
+		tracker_dir_remove (tracker->data_dir);
 		g_mkdir_with_parents (tracker->data_dir, 00755);
 		need_index = TRUE;
 	}
@@ -880,7 +876,7 @@
 			tracker_error ("db or index corruption detected - prepare for reindex...");
 			tracker_db_close (db_con);	
 
-			tracker_remove_dirs (tracker->data_dir);
+			tracker_dir_remove (tracker->data_dir);
 			g_mkdir_with_parents (tracker->data_dir, 00755);
 			create_index (need_data);
 			db_con = tracker_db_connect ();



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