[tracker/wip/removable-device-completed: 7/11] Add TrackerRemovableDevice



commit f069f3041665ed4792f652c7d0639d8c6b046e93
Author: Sam Thursfield <sam thursfield codethink co uk>
Date:   Mon Jun 18 16:19:52 2012 +0100

    Add TrackerRemovableDevice

 src/libtracker-miner/Makefile.am                |   14 +-
 src/libtracker-miner/tracker-marshal.list       |    1 +
 src/libtracker-miner/tracker-removable-device.c |  159 +++++++++++++++++++
 src/libtracker-miner/tracker-removable-device.h |   73 +++++++++
 src/libtracker-miner/tracker-storage.c          |  102 +++++++++++-
 src/libtracker-miner/tracker-storage.h          |    5 +
 src/miners/fs/tracker-miner-files.c             |  188 ++++++++++++-----------
 7 files changed, 442 insertions(+), 100 deletions(-)
---
diff --git a/src/libtracker-miner/Makefile.am b/src/libtracker-miner/Makefile.am
index f272a5e..6412ad9 100644
--- a/src/libtracker-miner/Makefile.am
+++ b/src/libtracker-miner/Makefile.am
@@ -52,9 +52,8 @@ private_sources = 				       \
 	tracker-task-pool.h                            \
 	tracker-task-pool.c                            \
 	tracker-sparql-buffer.h                        \
-	tracker-sparql-buffer.c                        \
-	tracker-storage.c                              \
-	tracker-storage.h                              
+	tracker-sparql-buffer.c
+
 
 miner_sources = 				       \
 	$(libtracker_miner_monitor_sources)            \
@@ -69,7 +68,11 @@ miner_sources = 				       \
 	tracker-miner-manager.c                        \
 	tracker-miner-manager.h                        \
 	tracker-miner-web.c                            \
-	tracker-miner-web.h                            
+	tracker-miner-web.h                            \
+	tracker-removable-device.c                     \
+	tracker-removable-device.h                     \
+	tracker-storage.c                              \
+	tracker-storage.h
 
 
 libtracker_miner_private_la_SOURCES =                  \
@@ -103,6 +106,7 @@ libtracker_minerinclude_HEADERS =                      \
 	tracker-miner-web.h                            \
 	tracker-network-provider.h                     \
 	tracker-password-provider.h                    \
+	tracker-removable-device.h                     \
 	tracker-storage.h                              \
 	tracker-thumbnailer.h
 
@@ -112,7 +116,7 @@ if !ENABLE_GCOV
 # Using enable_gcov instead of have_unit_test because when doing a release
 #  we disable gcov but NOT the unit tests
 libtracker_miner_ TRACKER_API_VERSION@_la_LDFLAGS +=    \
-	-export-symbols-regex '^tracker_(miner|thumbnailer|crawler|storage|password_provider|network_provider|indexing_tree|file_system|file_notifier|directory_flags|filter_type|filter_policy)_.*'
+	-export-symbols-regex '^tracker_(miner|thumbnailer|crawler|removable_device|storage|password_provider|network_provider|indexing_tree|file_system|file_notifier|directory_flags|filter_type|filter_policy)_.*'
 endif
 
 libtracker_miner_ TRACKER_API_VERSION@_la_LIBADD =     \
diff --git a/src/libtracker-miner/tracker-marshal.list b/src/libtracker-miner/tracker-marshal.list
index 5c311fb..9ce07f1 100644
--- a/src/libtracker-miner/tracker-marshal.list
+++ b/src/libtracker-miner/tracker-marshal.list
@@ -2,6 +2,7 @@ VOID:OBJECT,BOOLEAN
 VOID:OBJECT,OBJECT
 VOID:OBJECT,OBJECT,BOOLEAN,BOOLEAN
 VOID:OBJECT,POINTER,UINT,UINT,UINT,UINT
+VOID:OBJECT,STRING,STRING,STRING,BOOLEAN,BOOLEAN
 VOID:OBJECT,UINT,UINT,UINT,UINT
 VOID:DOUBLE,UINT,UINT,UINT,UINT
 VOID:STRING,DOUBLE,INT
diff --git a/src/libtracker-miner/tracker-removable-device.c b/src/libtracker-miner/tracker-removable-device.c
new file mode 100644
index 0000000..aad568a
--- /dev/null
+++ b/src/libtracker-miner/tracker-removable-device.c
@@ -0,0 +1,159 @@
+/*
+ * Copyright (C) 2012, Nokia <ivan frade nokia com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+#include "config.h"
+
+#include <string.h>
+
+#include <gio/gio.h>
+#include <gio/gunixmounts.h>
+
+#include <libtracker-common/tracker-log.h>
+
+#include "tracker-removable-device.h"
+#include "tracker-marshal.h"
+#include "tracker-storage.h"
+#include "tracker-utils.h"
+
+/**
+ * SECTION:tracker-removable-device
+ * @short_description: Removable storage and mount point convenience API
+ * @include: libtracker-miner/tracker-miner.h
+ *
+ * A #TrackerRemovableDevice represents a mounted removable volume or optical
+ * disc.
+ **/
+
+#define TRACKER_REMOVABLE_DEVICE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_REMOVABLE_DEVICE, TrackerRemovableDevicePrivate))
+
+struct _TrackerRemovableDevicePrivate {
+	GMount *mount;
+	gchar *mount_point;
+	gchar *uuid;
+	guint unmount_timer_id;
+	guint removable : 1;
+	guint optical : 1;
+};
+
+enum {
+	MINING_COMPLETE,
+	LAST_SIGNAL
+};
+
+static void tracker_removable_device_finalize (GObject *object);
+
+static guint signals[LAST_SIGNAL] = { 0, };
+
+G_DEFINE_TYPE (TrackerRemovableDevice, tracker_removable_device, G_TYPE_OBJECT);
+
+static void
+tracker_removable_device_class_init (TrackerRemovableDeviceClass *klass)
+{
+	GObjectClass *object_class;
+
+	object_class = G_OBJECT_CLASS (klass);
+
+	object_class->finalize = tracker_removable_device_finalize;
+
+	/**
+	 * TrackerRemovableDevice::crawling-complete:
+	 * @device: the #TrackerRemovableDevice
+	 *
+	 * The ::crawling-complete signal is emitted when each file on the
+	 * removable device has been processed by the FS miner.
+	 *
+	 * Since: 0.14.2
+	 **/
+	signals[MINING_COMPLETE] =
+		g_signal_new ("mining-complete",
+		              G_OBJECT_CLASS_TYPE (object_class),
+		              G_SIGNAL_RUN_LAST,
+		              0,
+		              NULL, NULL,
+		              g_cclosure_marshal_VOID__VOID,
+		              G_TYPE_NONE,
+		              0);
+
+	g_type_class_add_private (object_class, sizeof (TrackerRemovableDevicePrivate));
+}
+
+static void
+tracker_removable_device_init (TrackerRemovableDevice *device)
+{
+	device->priv = TRACKER_REMOVABLE_DEVICE_GET_PRIVATE (device);
+}
+
+static void
+tracker_removable_device_finalize (GObject *object)
+{
+	TrackerRemovableDevicePrivate *priv;
+
+	priv = TRACKER_REMOVABLE_DEVICE_GET_PRIVATE (object);
+
+	g_object_unref (priv->mount);
+
+	(G_OBJECT_CLASS (tracker_removable_device_parent_class)->finalize) (object);
+}
+
+TrackerRemovableDevice *
+tracker_removable_device_new (GMount *mount)
+{
+	TrackerRemovableDevice *device;
+
+	device = g_object_new (TRACKER_TYPE_REMOVABLE_DEVICE, NULL);
+
+	device->priv->mount = g_object_ref (mount);
+
+	return device;
+}
+
+/**
+ * tracker_removable_device_get_mount:
+ * @device: a #TrackerRemovableDevice
+ *
+ * Returns the #GMount object representing @device. The caller does not need
+ * to unreference the return value.
+ *
+ * Returns: (transfer none): the #GMount object representing the device.
+ **/
+GMount *
+tracker_removable_device_get_mount (TrackerRemovableDevice *device)
+{
+	g_return_val_if_fail (TRACKER_IS_REMOVABLE_DEVICE (device), NULL);
+
+	return device->priv->mount;
+}
+
+/**
+ * tracker_removable_device_get_mount_point:
+ * @device: a #TrackerRemovableDevice
+ *
+ * Returns a #GFile object representing the mount point of @device. The
+ * caller should unreference this object when no longer needed.
+ *
+ * Returns: (transfer full): a #GFile object presenting the mount point of
+ *          @device.
+ **/
+GFile *
+tracker_removable_device_get_mount_point (TrackerRemovableDevice *device)
+{
+	g_return_val_if_fail (TRACKER_IS_REMOVABLE_DEVICE( device), NULL);
+
+	return g_mount_get_root (device->priv->mount);
+}
diff --git a/src/libtracker-miner/tracker-removable-device.h b/src/libtracker-miner/tracker-removable-device.h
new file mode 100644
index 0000000..b3a727b
--- /dev/null
+++ b/src/libtracker-miner/tracker-removable-device.h
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2012, Nokia <ivan frade nokia com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+#ifndef __TRACKER_REMOVABLE_DEVICE_H__
+#define __TRACKER_REMOVABLE_DEVICE_H__
+
+#if !defined (__LIBTRACKER_MINER_H_INSIDE__) && !defined (TRACKER_COMPILATION)
+#error "Only <libtracker-miner/tracker-miner.h> can be included directly."
+#endif
+
+#include <glib-object.h>
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+#define TRACKER_TYPE_REMOVABLE_DEVICE         (tracker_removable_device_get_type ())
+#define TRACKER_REMOVABLE_DEVICE(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_REMOVABLE_DEVICE, TrackerRemovableDevice))
+#define TRACKER_REMOVABLE_DEVICE_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST ((k), TRACKER_TYPE_REMOVABLE_DEVICE, TrackerRemovableDeviceClass))
+#define TRACKER_IS_REMOVABLE_DEVICE(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_REMOVABLE_DEVICE))
+#define TRACKER_IS_REMOVABLE_DEVICE_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), TRACKER_TYPE_REMOVABLE_DEVICE))
+#define TRACKER_REMOVABLE_DEVICE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_REMOVABLE_DEVICE, TrackerRemovableDeviceClass))
+
+typedef struct _TrackerRemovableDevice TrackerRemovableDevice;
+typedef struct _TrackerRemovableDeviceClass TrackerRemovableDeviceClass;
+typedef struct _TrackerRemovableDevicePrivate TrackerRemovableDevicePrivate;
+
+/**
+ * TrackerRemovableDevice:
+ * @parent: parent object
+ *
+ * Represents a mounted removable or optical volume.
+ **/
+struct _TrackerRemovableDevice {
+	GObject parent;
+	TrackerRemovableDevicePrivate *priv;
+};
+
+/**
+ * TrackerRemovableDeviceClass:
+ * @parent_class: parent object class
+ *
+ * A storage class for #TrackerRemovableDevice.
+ **/
+struct _TrackerRemovableDeviceClass {
+	GObjectClass parent_class;
+};
+
+GType                   tracker_removable_device_get_type                 (void) G_GNUC_CONST;
+
+TrackerRemovableDevice *tracker_removable_device_new                      (GMount *mount);
+
+GMount                 *tracker_removable_device_get_mount                (TrackerRemovableDevice *device);
+GFile                  *tracker_removable_device_get_mount_point          (TrackerRemovableDevice *device);
+
+G_END_DECLS
+
+#endif /* __TRACKER_REMOVABLE_DEVICE_H__ */
diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c
index 277fb38..4d0145f 100644
--- a/src/libtracker-miner/tracker-storage.c
+++ b/src/libtracker-miner/tracker-storage.c
@@ -51,6 +51,7 @@ typedef struct {
 } TrackerStoragePrivate;
 
 typedef struct {
+	TrackerRemovableDevice *device;
 	gchar *mount_point;
 	gchar *uuid;
 	guint unmount_timer_id;
@@ -90,6 +91,7 @@ static void     mount_pre_removed_cb     (GVolumeMonitor *monitor,
                                           gpointer        user_data);
 
 enum {
+	DEVICE_ADDED,
 	MOUNT_POINT_ADDED,
 	MOUNT_POINT_REMOVED,
 	LAST_SIGNAL
@@ -110,6 +112,22 @@ tracker_storage_class_init (TrackerStorageClass *klass)
 
 	object_class->finalize     = tracker_storage_finalize;
 
+	signals[DEVICE_ADDED] =
+		g_signal_new ("device-added",
+		              G_TYPE_FROM_CLASS (klass),
+		              G_SIGNAL_RUN_LAST,
+		              0,
+		              NULL, NULL,
+		              tracker_marshal_VOID__OBJECT_STRING_STRING_STRING_BOOLEAN_BOOLEAN,
+		              G_TYPE_NONE,
+		              6,
+		              TRACKER_TYPE_REMOVABLE_DEVICE,
+		              G_TYPE_STRING,
+		              G_TYPE_STRING,
+		              G_TYPE_STRING,
+		              G_TYPE_BOOLEAN,
+		              G_TYPE_BOOLEAN);
+
 	signals[MOUNT_POINT_ADDED] =
 		g_signal_new ("mount-point-added",
 		              G_TYPE_FROM_CLASS (klass),
@@ -261,6 +279,8 @@ mount_info_free (GNode    *node,
 	info = node->data;
 
 	if (info) {
+		g_object_unref (info->device);
+
 		g_free (info->mount_point);
 		g_free (info->uuid);
 
@@ -312,11 +332,12 @@ mount_point_normalize (const gchar *mount_point)
 }
 
 static GNode *
-mount_add_hierarchy (GNode       *root,
-                     const gchar *uuid,
-                     const gchar *mount_point,
-                     gboolean     removable,
-                     gboolean     optical)
+mount_add_hierarchy (GNode                  *root,
+                     TrackerRemovableDevice *device,
+                     const gchar            *uuid,
+                     const gchar            *mount_point,
+                     gboolean                removable,
+                     gboolean                optical)
 {
 	MountInfo *info;
 	GNode *node;
@@ -330,6 +351,7 @@ mount_add_hierarchy (GNode       *root,
 	}
 
 	info = g_slice_new (MountInfo);
+	info->device = device;
 	info->mount_point = mp;
 	info->uuid = g_strdup (uuid);
 	info->removable = removable;
@@ -340,6 +362,7 @@ mount_add_hierarchy (GNode       *root,
 
 static void
 mount_add_new (TrackerStorage *storage,
+               GMount         *mount,
                const gchar    *uuid,
                const gchar    *mount_point,
                const gchar    *mount_name,
@@ -347,19 +370,35 @@ mount_add_new (TrackerStorage *storage,
                gboolean        optical_disc)
 {
 	TrackerStoragePrivate *priv;
+	TrackerRemovableDevice *device;
 	GNode *node;
 
+	g_return_if_fail (G_IS_MOUNT (mount));
+
 	priv = TRACKER_STORAGE_GET_PRIVATE (storage);
 
-	node = mount_add_hierarchy (priv->mounts, uuid, mount_point, removable_device, optical_disc);
+	device = tracker_removable_device_new (mount);
+
+	node = mount_add_hierarchy (priv->mounts, device, uuid, mount_point, removable_device, optical_disc);
 	g_hash_table_insert (priv->mounts_by_uuid, g_strdup (uuid), node);
 
 	g_signal_emit (storage,
+	               signals[DEVICE_ADDED],
+	               0,
+	               device,
+	               uuid,
+	               mount_point,
+	               mount_name,
+	               removable_device,
+	               optical_disc,
+	               NULL);
+
+	g_signal_emit (storage,
 	               signals[MOUNT_POINT_ADDED],
 	               0,
 	               uuid,
 	               mount_point,
-                       mount_name,
+	               mount_name,
 	               removable_device,
 	               optical_disc,
 	               NULL);
@@ -682,7 +721,7 @@ mount_add (TrackerStorage *storage,
 		         is_removable ? "yes" : "no",
 		         is_optical ? "yes" : "no",
 		         mount_path);
-		mount_add_new (storage, uuid, mount_path, mount_name, is_removable, is_optical);
+		mount_add_new (storage, mount, uuid, mount_path, mount_name, is_removable, is_optical);
 	} else {
 		g_debug ("  Skipping mount point with UUID: '%s', path: '%s', already managed: '%s'",
 		         uuid ? uuid : "none",
@@ -914,6 +953,53 @@ get_mount_point_by_uuid_foreach (gpointer key,
 }
 
 /**
+ * tracker_storage_get_devices:
+ * @storage: A #TrackerStorage
+ * @type: A #TrackerStorageType
+ * @exact_match: if all devices should exactly match the types
+ *
+ * Returns: (transfer full) (element-type TrackerRemovableDevice): a #GSList of
+ * #TrackerRemovableDevice objects representing connected removable / optical
+ * devices, according
+ * to @type and @exact_match.
+ *
+ * Since: 0.14.2
+ **/
+GSList *
+tracker_storage_get_devices (TrackerStorage     *storage,
+                             TrackerStorageType  type,
+                             gboolean            exact_match)
+{
+	TrackerStoragePrivate *priv;
+	GList *mount_node_list;
+	GList *l;
+	GSList *devices_list;
+
+	priv = TRACKER_STORAGE_GET_PRIVATE (storage);
+
+	mount_node_list = g_hash_table_get_values (priv->mounts_by_uuid);
+
+	devices_list = NULL;
+
+	for (l = mount_node_list; l != NULL; l = l->next) {
+		GNode *node = l->data;
+		MountInfo *mount_info = node->data;
+		TrackerStorageType mount_type;
+
+		mount_type = mount_info_get_type (mount_info);
+
+		if ((exact_match && mount_type == type) ||
+		    (!exact_match && (mount_type & type))) {
+			devices_list = g_slist_prepend (devices_list, mount_info->device);
+		}
+	}
+
+	g_list_free (mount_node_list);
+
+	return devices_list;
+}
+
+/**
  * tracker_storage_get_device_roots:
  * @storage: A #TrackerStorage
  * @type: A #TrackerStorageType
diff --git a/src/libtracker-miner/tracker-storage.h b/src/libtracker-miner/tracker-storage.h
index 17f6596..add4a35 100644
--- a/src/libtracker-miner/tracker-storage.h
+++ b/src/libtracker-miner/tracker-storage.h
@@ -27,6 +27,8 @@
 #include <glib-object.h>
 #include <gio/gio.h>
 
+#include "tracker-removable-device.h"
+
 G_BEGIN_DECLS
 
 /**
@@ -102,6 +104,9 @@ GType              tracker_storage_get_type                 (void) G_GNUC_CONST;
 TrackerStorage *   tracker_storage_get                      (void);
 G_GNUC_DEPRECATED_FOR(tracker_storage_get)
 TrackerStorage *   tracker_storage_new                      (void);
+GSList *           tracker_storage_get_devices              (TrackerStorage     *storage,
+                                                             TrackerStorageType  type,
+                                                             gboolean            exact_match);
 GSList *           tracker_storage_get_device_roots         (TrackerStorage     *storage,
                                                              TrackerStorageType  type,
                                                              gboolean            exact_match);
diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c
index b4a1b07..b5322b6 100644
--- a/src/miners/fs/tracker-miner-files.c
+++ b/src/miners/fs/tracker-miner-files.c
@@ -132,14 +132,14 @@ static gboolean    miner_files_initable_init            (GInitable            *i
 static void        mount_pre_unmount_cb                 (GVolumeMonitor       *volume_monitor,
                                                          GMount               *mount,
                                                          TrackerMinerFiles    *mf);
-
-static void        mount_point_added_cb                 (TrackerStorage       *storage,
-                                                         const gchar          *uuid,
-                                                         const gchar          *mount_point,
-                                                         const gchar          *mount_name,
-                                                         gboolean              removable,
-                                                         gboolean              optical,
-                                                         gpointer              user_data);
+static void        device_added_cb                      (TrackerStorage         *storage,
+                                                         TrackerRemovableDevice *mount,
+                                                         const gchar            *uuid,
+                                                         const gchar            *mount_point,
+                                                         const gchar            *mount_name,
+                                                         gboolean                removable,
+                                                         gboolean                optical,
+                                                         gpointer                user_data);
 static void        mount_point_removed_cb               (TrackerStorage       *storage,
                                                          const gchar          *uuid,
                                                          const gchar          *mount_point,
@@ -200,15 +200,13 @@ static gboolean    miner_files_in_removable_media_remove_by_type  (TrackerMinerF
 static void        miner_files_in_removable_media_remove_by_date  (TrackerMinerFiles  *miner,
                                                                    const gchar        *date);
 
-static void        miner_files_add_removable_or_optical_directory (TrackerMinerFiles *mf,
-                                                                   const gchar       *mount_path,
-                                                                   const gchar       *uuid);
+static void        miner_files_add_removable_or_optical_device    (TrackerMinerFiles      *mf,
+                                                                   TrackerRemovableDevice *device);
 
 static void        extractor_process_failsafe                     (TrackerMinerFiles *miner);
 
 static void        miner_files_update_filters                     (TrackerMinerFiles *files);
 
-
 static GInitableIface* miner_files_initable_parent_iface;
 
 G_DEFINE_TYPE_WITH_CODE (TrackerMinerFiles, tracker_miner_files, TRACKER_TYPE_MINER_FS,
@@ -253,8 +251,8 @@ tracker_miner_files_init (TrackerMinerFiles *mf)
 
 	storage = tracker_storage_get ();
 
-	g_signal_connect (storage, "mount-point-added",
-	                  G_CALLBACK (mount_point_added_cb),
+	g_signal_connect (storage, "device-added",
+	                  G_CALLBACK (device_added_cb),
 	                  mf);
 
 	g_signal_connect (storage, "mount-point-removed",
@@ -302,7 +300,7 @@ miner_files_initable_init (GInitable     *initable,
 	TrackerStorage *storage;
 	TrackerDirectoryFlags flags;
 	GError *inner_error = NULL;
-	GSList *mounts = NULL;
+	GSList *devices = NULL;
 	GSList *dirs;
 	GSList *m;
 
@@ -353,9 +351,9 @@ miner_files_initable_init (GInitable     *initable,
 	mf->private->index_removable_devices = tracker_config_get_index_removable_devices (mf->private->config);
 	if (mf->private->index_removable_devices) {
 		/* Get list of roots for removable devices (excluding optical) */
-		mounts = tracker_storage_get_device_roots (storage,
-		                                           TRACKER_STORAGE_REMOVABLE,
-		                                           TRUE);
+		devices = tracker_storage_get_devices (storage,
+		                                       TRACKER_STORAGE_REMOVABLE,
+		                                       TRUE);
 	}
 
 	/* Setup initial flag for optical discs. Note that if removable devices not indexed,
@@ -364,11 +362,11 @@ miner_files_initable_init (GInitable     *initable,
 	                                    tracker_config_get_index_optical_discs (mf->private->config) :
 	                                    FALSE);
 	if (mf->private->index_optical_discs) {
-		/* Get list of roots for removable+optical devices */
-		m = tracker_storage_get_device_roots (storage,
-		                                      TRACKER_STORAGE_OPTICAL | TRACKER_STORAGE_REMOVABLE,
-		                                      TRUE);
-		mounts = g_slist_concat (mounts, m);
+		/* Get list of mounts for removable+optical devices */
+		m = tracker_storage_get_devices (storage,
+		                                 TRACKER_STORAGE_OPTICAL | TRACKER_STORAGE_REMOVABLE,
+		                                 TRUE);
+		devices = g_slist_concat (devices, m);
 	}
 
 #if defined(HAVE_UPOWER) || defined(HAVE_HAL)
@@ -399,11 +397,16 @@ miner_files_initable_init (GInitable     *initable,
 		}
 
 		/* Make sure we don't crawl volumes. */
-		if (mounts) {
+		if (devices) {
+			TrackerRemovableDevice *device;
+			GFile *mount_point;
 			gboolean found = FALSE;
 
-			for (m = mounts; m && !found; m = m->next) {
-				found = strcmp (m->data, dirs->data) == 0;
+			for (m = devices; m && !found; m = m->next) {
+				device = TRACKER_REMOVABLE_DEVICE (m->data);
+				mount_point = tracker_removable_device_get_mount_point (device);
+				found = strcmp (g_file_get_path (mount_point), dirs->data) == 0;
+				g_object_unref (mount_point);
 			}
 
 			if (found) {
@@ -454,11 +457,16 @@ miner_files_initable_init (GInitable     *initable,
 		}
 
 		/* Make sure we don't crawl volumes. */
-		if (mounts) {
+		if (devices) {
+			TrackerRemovableDevice *device;
+			GFile *mount_point;
 			gboolean found = FALSE;
 
-			for (m = mounts; m && !found; m = m->next) {
-				found = strcmp (m->data, dirs->data) == 0;
+			for (m = devices; m && !found; m = m->next) {
+				device = TRACKER_REMOVABLE_DEVICE (m->data);
+				mount_point = tracker_removable_device_get_mount_point (device);
+				found = strcmp (g_file_get_path (mount_point), dirs->data) == 0;
+				g_object_unref (mount_point);
 			}
 
 			if (found) {
@@ -503,10 +511,8 @@ miner_files_initable_init (GInitable     *initable,
 		miner_files_in_removable_media_remove_by_type (mf, TRACKER_STORAGE_REMOVABLE | TRACKER_STORAGE_OPTICAL);
 	}
 
-	for (m = mounts; m; m = m->next) {
-		miner_files_add_removable_or_optical_directory (mf,
-		                                                (gchar *) m->data,
-		                                                NULL);
+	for (m = devices; m; m = m->next) {
+		miner_files_add_removable_or_optical_device (mf, TRACKER_REMOVABLE_DEVICE (m->data));
 	}
 
 	/* We want to get notified when config changes */
@@ -550,8 +556,7 @@ miner_files_initable_init (GInitable     *initable,
 
 #endif /* defined(HAVE_UPOWER) || defined(HAVE_HAL) */
 
-	g_slist_foreach (mounts, (GFunc) g_free, NULL);
-	g_slist_free (mounts);
+	g_slist_free (devices);
 
 	disk_space_check_start (mf);
 
@@ -1142,7 +1147,6 @@ init_stale_volume_removal (TrackerMinerFiles *miner)
 		                       miner);
 }
 
-
 static void
 mount_point_removed_cb (TrackerStorage *storage,
                         const gchar    *uuid,
@@ -1175,13 +1179,14 @@ mount_point_removed_cb (TrackerStorage *storage,
 }
 
 static void
-mount_point_added_cb (TrackerStorage *storage,
-                      const gchar    *uuid,
-                      const gchar    *mount_point,
-                      const gchar    *mount_name,
-                      gboolean        removable,
-                      gboolean        optical,
-                      gpointer        user_data)
+device_added_cb (TrackerStorage         *storage,
+                 TrackerRemovableDevice *device,
+                 const gchar            *uuid,
+                 const gchar            *mount_point,
+                 const gchar            *mount_name,
+                 gboolean                removable,
+                 gboolean                optical,
+                 gpointer                user_data)
 {
 	TrackerMinerFiles *miner = user_data;
 	TrackerMinerFilesPrivate *priv;
@@ -1203,7 +1208,18 @@ mount_point_added_cb (TrackerStorage *storage,
 		GFile *mount_point_file;
 		GSList *l;
 
-		mount_point_file = g_file_new_for_path (mount_point);
+		/* If the removable device is not actually a removable device (this
+		 * is getting a bit ugly already) but it's located under a directory
+		 * that gets indexed, we index it .... is that actually what you'd ever
+		 * want?
+		 *  - eg, sftp mounts under /home/, ... but there's no way to disable
+		 *    these, and , hm... do you want it? and, if they're under a
+		 *    recursive path THEY WILL BE INDEXED ANYWAY due to the dir-created
+		 *    notification, so WHY IS THIS !!!!
+		 * I guess what we're doing is RE-CHECKING, ...
+		 */
+
+		mount_point_file = tracker_removable_device_get_mount_point (device);
 		indexing_tree = tracker_miner_fs_get_indexing_tree (TRACKER_MINER_FS (miner));
 
 		/* Check if one of the recursively indexed locations is in
@@ -1273,9 +1289,7 @@ mount_point_added_cb (TrackerStorage *storage,
 		g_object_unref (mount_point_file);
 	} else {
 		g_message ("  Adding directories in removable/optical media to crawler's queue");
-		miner_files_add_removable_or_optical_directory (miner,
-		                                                mount_point,
-		                                                uuid);
+		miner_files_add_removable_or_optical_device (miner, device);
 	}
 
 	queries = g_string_new ("");
@@ -1770,8 +1784,8 @@ index_volumes_changed_idle (gpointer user_data)
 {
 	TrackerMinerFiles *mf = user_data;
 	TrackerStorage *storage;
-	GSList *mounts_removed = NULL;
-	GSList *mounts_added = NULL;
+	GSList *devices_removed = NULL;
+	GSList *devices_added = NULL;
 	gboolean new_index_removable_devices;
 	gboolean new_index_optical_discs;
 
@@ -1792,9 +1806,9 @@ index_volumes_changed_idle (gpointer user_data)
 
 		/* Get list of roots for currently mounted removable devices
 		 * (excluding optical) */
-		m = tracker_storage_get_device_roots (storage,
-		                                      TRACKER_STORAGE_REMOVABLE,
-		                                      TRUE);
+		m = tracker_storage_get_devices (storage,
+		                                 TRACKER_STORAGE_REMOVABLE,
+		                                 TRUE);
 		/* Set new config value */
 		mf->private->index_removable_devices = new_index_removable_devices;
 
@@ -1802,13 +1816,13 @@ index_volumes_changed_idle (gpointer user_data)
 			/* If previously not indexing and now indexing, need to re-check
 			 * current mounted volumes, add new monitors and index new files
 			 */
-			mounts_added = m;
+			devices_added = m;
 		} else {
 			/* If previously indexing and now not indexing, need to re-check
 			 * current mounted volumes, remove monitors and remove all resources
 			 * from the store belonging to a removable device
 			 */
-			mounts_removed = m;
+			devices_removed = m;
 
 			/* And now, single sparql update to remove all resources
 			 * corresponding to removable devices (includes those
@@ -1822,9 +1836,9 @@ index_volumes_changed_idle (gpointer user_data)
 		GSList *m;
 
 		/* Get list of roots for removable devices (excluding optical) */
-		m = tracker_storage_get_device_roots (storage,
-		                                      TRACKER_STORAGE_REMOVABLE | TRACKER_STORAGE_OPTICAL,
-		                                      TRUE);
+		m = tracker_storage_get_devices (storage,
+		                                 TRACKER_STORAGE_REMOVABLE | TRACKER_STORAGE_OPTICAL,
+		                                 TRUE);
 
 		/* Set new config value */
 		mf->private->index_optical_discs = new_index_optical_discs;
@@ -1833,13 +1847,13 @@ index_volumes_changed_idle (gpointer user_data)
 			/* If previously not indexing and now indexing, need to re-check
 			 * current mounted volumes, add new monitors and index new files
 			 */
-			mounts_added = g_slist_concat (mounts_added, m);
+			devices_added = g_slist_concat (devices_added, m);
 		} else {
 			/* If previously indexing and now not indexing, need to re-check
 			 * current mounted volumes, remove monitors and remove all resources
 			 * from the store belonging to a optical disc
 			 */
-			mounts_removed = g_slist_concat (mounts_removed, m);
+			devices_removed = g_slist_concat (devices_removed, m);
 
 			/* And now, single sparql update to remove all resources
 			 * corresponding to removable+optical devices (includes those
@@ -1849,37 +1863,38 @@ index_volumes_changed_idle (gpointer user_data)
 	}
 
 	/* Tell TrackerMinerFS to stop monitoring the given removed mount paths, if any */
-	if (mounts_removed) {
+	if (devices_removed) {
 		TrackerIndexingTree *indexing_tree;
 		GSList *sl;
 
 		indexing_tree = tracker_miner_fs_get_indexing_tree (TRACKER_MINER_FS (mf));
 
-		for (sl = mounts_removed; sl; sl = g_slist_next (sl)) {
+		for (sl = devices_removed; sl; sl = g_slist_next (sl)) {
+			TrackerRemovableDevice *device;
 			GFile *mount_point_file;
 
-			mount_point_file = g_file_new_for_path (sl->data);
-			tracker_indexing_tree_remove (indexing_tree,
-						      mount_point_file);
+			device = TRACKER_REMOVABLE_DEVICE (sl->data);
+			mount_point_file = tracker_removable_device_get_mount_point (device);
+
+			tracker_indexing_tree_remove (indexing_tree, mount_point_file);
+
 			g_object_unref (mount_point_file);
 		}
 
-		g_slist_foreach (mounts_removed, (GFunc) g_free, NULL);
-		g_slist_free (mounts_removed);
+		//g_slist_foreach (mounts_removed, (GFunc) g_free, NULL);
+		g_slist_free (devices_removed);
 	}
 
 	/* Tell TrackerMinerFS to start monitoring the given added mount paths, if any */
-	if (mounts_added) {
+	if (devices_added) {
 		GSList *sl;
 
-		for (sl = mounts_added; sl; sl = g_slist_next (sl)) {
-			miner_files_add_removable_or_optical_directory (mf,
-			                                                (gchar *) sl->data,
-			                                                NULL);
+		for (sl = devices_added; sl; sl = g_slist_next (sl)) {
+			miner_files_add_removable_or_optical_device (mf, TRACKER_REMOVABLE_DEVICE (sl->data));
 		}
 
-		g_slist_foreach (mounts_added, (GFunc) g_free, NULL);
-		g_slist_free (mounts_added);
+		//g_slist_foreach (mounts_added, (GFunc) g_free, NULL);
+		g_slist_free (devices_added);
 	}
 
 	mf->private->volumes_changed_id = 0;
@@ -2941,26 +2956,25 @@ miner_files_in_removable_media_remove_by_date (TrackerMinerFiles  *miner,
 }
 
 static void
-miner_files_add_removable_or_optical_directory (TrackerMinerFiles *mf,
-                                                const gchar       *mount_path,
-                                                const gchar       *uuid)
+miner_files_add_removable_or_optical_device (TrackerMinerFiles      *mf,
+                                             TrackerRemovableDevice *device)
 {
 	TrackerIndexingTree *indexing_tree;
 	TrackerDirectoryFlags flags;
 	GFile *mount_point_file;
+	const gchar *uuid;
 
-	mount_point_file = g_file_new_for_path (mount_path);
+	mount_point_file = tracker_removable_device_get_mount_point (device);
 
-	/* UUID may be NULL, and if so, get it */
+	/* FIXME: can't get from the mount, but can get more easily than this,
+	 * right? TrackerStorage should handle! */
+	uuid = tracker_storage_get_uuid_for_file (tracker_storage_get (),
+	                                          mount_point_file);
 	if (!uuid) {
-		uuid = tracker_storage_get_uuid_for_file (tracker_storage_get (),
-		                                          mount_point_file);
-		if (!uuid) {
-			g_critical ("Couldn't get UUID for mount point '%s'",
-			            mount_path);
-			g_object_unref (mount_point_file);
-			return;
-		}
+		g_critical ("Couldn't get UUID for mount point '%s'",
+		            g_file_get_path (mount_point_file));
+		g_object_unref (mount_point_file);
+		return;
 	}
 
 	indexing_tree = tracker_miner_fs_get_indexing_tree (TRACKER_MINER_FS (mf));
@@ -2977,7 +2991,7 @@ miner_files_add_removable_or_optical_directory (TrackerMinerFiles *mf,
 	                         g_strdup (uuid),
 	                         (GDestroyNotify) g_free);
 
-	g_message ("  Adding removable/optical: '%s'", mount_path);
+	g_message ("  Adding removable/optical: '%s'", g_file_get_path (mount_point_file));
 	tracker_indexing_tree_add (indexing_tree,
 				   mount_point_file,
 				   flags);



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