[tracker/miner-directory-flags: 1/8] libtracker-miner: Introduce TrackerDirectoryFlags.



commit 440b0baa7a9a8da2689d10c421cdfc2cbb2bc7d9
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Apr 25 15:13:07 2011 +0200

    libtracker-miner: Introduce TrackerDirectoryFlags.
    
    The recurse boolean parameter in tracker_miner_fs_directory_add()
    has been replaced by these flags, so miner implementations can gain
    further control on how things are performed.

 src/libtracker-miner/tracker-miner-fs.c |   61 +++++++++++++++++++++++--------
 src/libtracker-miner/tracker-miner-fs.h |    8 ++++
 src/miners/fs/tracker-miner-files.c     |   12 ++----
 3 files changed, 57 insertions(+), 24 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index e0dff01..b910fa5 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -119,8 +119,8 @@ typedef struct {
 
 typedef struct {
 	GFile    *file;
-	guint     recurse : 1;
-	guint     ref_count : 7;
+	guint16   ref_count;
+	guint16   flags;
 } DirectoryData;
 
 typedef struct {
@@ -288,8 +288,8 @@ static void           miner_paused                        (TrackerMiner
 static void           miner_resumed                       (TrackerMiner         *miner);
 static void           miner_ignore_next_update            (TrackerMiner         *miner,
                                                            const GStrv           subjects);
-static DirectoryData *directory_data_new                  (GFile                *file,
-                                                           gboolean              recurse);
+static DirectoryData *directory_data_new                  (GFile                 *file,
+                                                           TrackerDirectoryFlags  flags);
 static DirectoryData *directory_data_ref                  (DirectoryData        *dd);
 static void           directory_data_unref                (DirectoryData        *dd);
 static ItemMovedData *item_moved_data_new                 (GFile                *file,
@@ -996,15 +996,15 @@ miner_ignore_next_update (TrackerMiner *miner, const GStrv urls)
 
 
 static DirectoryData *
-directory_data_new (GFile    *file,
-                    gboolean  recurse)
+directory_data_new (GFile                 *file,
+                    TrackerDirectoryFlags  flags)
 {
 	DirectoryData *dd;
 
 	dd = g_slice_new (DirectoryData);
 
 	dd->file = g_object_ref (file);
-	dd->recurse = recurse;
+	dd->flags = flags;
 	dd->ref_count = 1;
 
 	return dd;
@@ -1349,7 +1349,8 @@ find_config_directory (TrackerMinerFS *fs,
 		dirs = dirs->next;
 
 		if (g_file_equal (data->file, file) ||
-		    (data->recurse && (g_file_has_prefix (file, data->file)))) {
+		    ((data->flags & TRACKER_DIRECTORY_RECURSE) != 0 &&
+		     g_file_has_prefix (file, data->file))) {
 			return data;
 		}
 	}
@@ -3742,6 +3743,7 @@ crawl_directories_cb (gpointer user_data)
 {
 	TrackerMinerFS *fs = user_data;
 	gchar *path, *path_utf8;
+	gboolean recurse;
 	gchar *str;
 
 	if (fs->private->current_directory) {
@@ -3783,7 +3785,9 @@ crawl_directories_cb (gpointer user_data)
 	path_utf8 = g_filename_to_utf8 (path, -1, NULL, NULL, NULL);
 	g_free (path);
 
-	if (fs->private->current_directory->recurse) {
+	recurse = (fs->private->current_directory->flags & TRACKER_DIRECTORY_RECURSE) != 0;
+
+	if (recurse) {
 		str = g_strdup_printf ("Crawling recursively directory '%s'", path_utf8);
 	} else {
 		str = g_strdup_printf ("Crawling single directory '%s'", path_utf8);
@@ -3804,7 +3808,7 @@ crawl_directories_cb (gpointer user_data)
 
 	if (tracker_crawler_start (fs->private->crawler,
 	                           fs->private->current_directory->file,
-	                           fs->private->current_directory->recurse)) {
+	                           recurse)) {
 		/* Crawler when restart the idle function when done */
 		fs->private->is_crawling = TRUE;
 		fs->private->crawl_directories_id = 0;
@@ -3885,7 +3889,7 @@ should_recurse_for_directory (TrackerMinerFS *fs,
 
 		data = dirs->data;
 
-		if (data->recurse &&
+		if ((data->flags & TRACKER_DIRECTORY_RECURSE) != 0 &&
 		    (g_file_equal (file, data->file) ||
 		     g_file_has_prefix (file, data->file))) {
 			/* File is inside a recursive dir */
@@ -3909,7 +3913,7 @@ directory_compare_cb (gconstpointer a,
 	DirectoryData *ddb = (DirectoryData *) b;
 
 	return (g_file_equal (dda->file, ddb->file) ||
-	        (dda->recurse &&
+	        ((dda->flags & TRACKER_DIRECTORY_RECURSE) != 0 &&
 	         g_file_has_prefix (ddb->file, dda->file))) ? 0 : -1;
 }
 
@@ -3922,11 +3926,14 @@ static void
 tracker_miner_fs_directory_add_internal (TrackerMinerFS *fs,
                                          GFile          *file)
 {
+	TrackerDirectoryFlags flags = 0;
 	DirectoryData *data;
-	gboolean recurse;
 
-	recurse = should_recurse_for_directory (fs, file);
-	data = directory_data_new (file, recurse);
+	if (should_recurse_for_directory (fs, file)) {
+		flags |= TRACKER_DIRECTORY_RECURSE;
+	}
+
+	data = directory_data_new (file, flags);
 
 	/* Only add if not already there */
 	if (!g_list_find_custom (fs->private->directories,
@@ -3957,12 +3964,34 @@ tracker_miner_fs_directory_add (TrackerMinerFS *fs,
                                 GFile          *file,
                                 gboolean        recurse)
 {
+	g_return_if_fail (TRACKER_IS_MINER_FS (fs));
+	g_return_if_fail (G_IS_FILE (file));
+
+	tracker_miner_fs_directory_add_full (fs, file, TRACKER_DIRECTORY_RECURSE);
+}
+
+/**
+ * tracker_miner_fs_directory_add_full:
+ * @fs: a #TrackerMinerFS
+ * @file: #GFile for the directory to inspect
+ * @flags: flags affecting inspection
+ *
+ * Tells the filesystem miner to inspect a directory, performing the
+ * actions specified in @flags.
+ *
+ * Since: 0.10
+ **/
+void
+tracker_miner_fs_directory_add_full (TrackerMinerFS        *fs,
+                                     GFile                 *file,
+                                     TrackerDirectoryFlags  flags)
+{
 	DirectoryData *dir_data;
 
 	g_return_if_fail (TRACKER_IS_MINER_FS (fs));
 	g_return_if_fail (G_IS_FILE (file));
 
-	dir_data = directory_data_new (file, recurse);
+	dir_data = directory_data_new (file, flags);
 
 	/* New directory to add in config_directories? */
 	if (!g_list_find_custom (fs->private->config_directories,
diff --git a/src/libtracker-miner/tracker-miner-fs.h b/src/libtracker-miner/tracker-miner-fs.h
index e26c71f..91165e9 100644
--- a/src/libtracker-miner/tracker-miner-fs.h
+++ b/src/libtracker-miner/tracker-miner-fs.h
@@ -45,6 +45,11 @@ G_BEGIN_DECLS
 typedef struct _TrackerMinerFS        TrackerMinerFS;
 typedef struct _TrackerMinerFSPrivate TrackerMinerFSPrivate;
 
+typedef enum {
+	TRACKER_DIRECTORY_NONE              = 0,
+	TRACKER_DIRECTORY_RECURSE           = 1 << 0,
+} TrackerDirectoryFlags;
+
 /**
  * TrackerMinerFS:
  *
@@ -110,6 +115,9 @@ GType                 tracker_miner_fs_get_type             (void) G_GNUC_CONST;
 void                  tracker_miner_fs_directory_add        (TrackerMinerFS *fs,
                                                              GFile          *file,
                                                              gboolean        recurse);
+void                  tracker_miner_fs_directory_add_full   (TrackerMinerFS        *fs,
+                                                             GFile                 *file,
+                                                             TrackerDirectoryFlags  flags);
 gboolean              tracker_miner_fs_directory_remove     (TrackerMinerFS *fs,
                                                              GFile          *file);
 gboolean              tracker_miner_fs_directory_remove_full (TrackerMinerFS *fs,
diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c
index 3dd67c5..b6246f4 100644
--- a/src/miners/fs/tracker-miner-files.c
+++ b/src/miners/fs/tracker-miner-files.c
@@ -1207,8 +1207,7 @@ mount_point_added_cb (TrackerStorage *storage,
 				g_message ("  Re-check of configured path '%s' needed (recursively)",
 				           (gchar *) l->data);
 				tracker_miner_fs_directory_add (TRACKER_MINER_FS (user_data),
-				                                config_file,
-				                                TRUE);
+				                                config_file, TRUE);
 			} else if (g_file_has_prefix (mount_point_file, config_file)) {
 				/* If the mount path is contained inside the config path,
 				 *  then add the mount path to re-check */
@@ -1216,8 +1215,7 @@ mount_point_added_cb (TrackerStorage *storage,
 				           mount_point,
 				           (gchar *) l->data);
 				tracker_miner_fs_directory_add (TRACKER_MINER_FS (user_data),
-				                                mount_point_file,
-				                                TRUE);
+				                                mount_point_file, TRUE);
 			}
 			g_object_unref (config_file);
 		}
@@ -1235,8 +1233,7 @@ mount_point_added_cb (TrackerStorage *storage,
 				g_message ("  Re-check of configured path '%s' needed (non-recursively)",
 				           (gchar *) l->data);
 				tracker_miner_fs_directory_add (TRACKER_MINER_FS (user_data),
-				                                config_file,
-				                                FALSE);
+				                                config_file, FALSE);
 			}
 			g_object_unref (config_file);
 		}
@@ -3050,7 +3047,6 @@ miner_files_add_removable_or_optical_directory (TrackerMinerFiles *mf,
 
 	g_message ("  Adding removable/optical: '%s'", mount_path);
 	tracker_miner_fs_directory_add (TRACKER_MINER_FS (mf),
-	                                mount_point_file,
-	                                TRUE);
+	                                mount_point_file, TRUE);
 	g_object_unref (mount_point_file);
 }



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