diff options
author | Martyn Russell <martyn@lanedo.com> | 2010-02-24 17:19:32 +0000 |
---|---|---|
committer | Martyn Russell <martyn@lanedo.com> | 2010-02-24 17:19:58 +0000 |
commit | 928da615a97cc727de66c2e97f5e2b91dfd2b86f (patch) | |
tree | 1d19734e6ef060dc549931aed10e80b62b6f2b29 | |
parent | 6121aa8e18d846f5aad90383d593513317cda489 (diff) | |
parent | 05b826a58904bb62b24706c33abf07623b781519 (diff) | |
download | tracker-928da615a97cc727de66c2e97f5e2b91dfd2b86f.tar.gz |
Fixes GB#609606, Merge branch 'swap-gio-for-hal'
-rw-r--r-- | docs/reference/libtracker-common/libtracker-common-docs.sgml | 2 | ||||
-rw-r--r-- | docs/reference/libtracker-common/libtracker-common-sections.txt | 23 | ||||
-rw-r--r-- | docs/reference/libtracker-miner/libtracker-miner-docs.sgml | 6 | ||||
-rw-r--r-- | docs/reference/libtracker-miner/libtracker-miner-sections.txt | 20 | ||||
-rw-r--r-- | src/libtracker-common/Makefile.am | 10 | ||||
-rw-r--r-- | src/libtracker-common/tracker-storage-hal.c | 1165 | ||||
-rw-r--r-- | src/libtracker-miner/Makefile.am | 5 | ||||
-rw-r--r-- | src/libtracker-miner/tracker-marshal.list | 1 | ||||
-rw-r--r-- | src/libtracker-miner/tracker-storage.c | 748 | ||||
-rw-r--r-- | src/libtracker-miner/tracker-storage.h (renamed from src/libtracker-common/tracker-storage.h) | 37 | ||||
-rw-r--r-- | src/tracker-extract/Makefile.am | 1 | ||||
-rw-r--r-- | src/tracker-extract/tracker-albumart.c | 40 | ||||
-rw-r--r-- | src/tracker-miner-fs/tracker-miner-files.c | 94 |
13 files changed, 842 insertions, 1310 deletions
diff --git a/docs/reference/libtracker-common/libtracker-common-docs.sgml b/docs/reference/libtracker-common/libtracker-common-docs.sgml index 41e255451..b5595883a 100644 --- a/docs/reference/libtracker-common/libtracker-common-docs.sgml +++ b/docs/reference/libtracker-common/libtracker-common-docs.sgml @@ -15,7 +15,6 @@ <!ENTITY tracker-os-dependant SYSTEM "xml/tracker-os-dependant.xml"> <!ENTITY tracker-power SYSTEM "xml/tracker-power.xml"> <!ENTITY tracker-property SYSTEM "xml/tracker-property.xml"> -<!ENTITY tracker-storage SYSTEM "xml/tracker-storage.xml"> <!ENTITY tracker-type-utils SYSTEM "xml/tracker-type-utils.xml"> <!ENTITY tracker-utils SYSTEM "xml/tracker-utils.xml"> <!ENTITY version SYSTEM "version.xml"> @@ -52,7 +51,6 @@ &tracker-config-file; &tracker-language; &tracker-power; - &tracker-storage; </chapter> <chapter> diff --git a/docs/reference/libtracker-common/libtracker-common-sections.txt b/docs/reference/libtracker-common/libtracker-common-sections.txt index 597bf0430..a7462e865 100644 --- a/docs/reference/libtracker-common/libtracker-common-sections.txt +++ b/docs/reference/libtracker-common/libtracker-common-sections.txt @@ -41,29 +41,6 @@ TRACKER_CLASS_GET_CLASS </SECTION> <SECTION> -<FILE>tracker-storage</FILE> -<TITLE>TrackerStorage</TITLE> -TrackerStorage -TrackerStorageClass -tracker_storage_new -tracker_storage_get_mounted_directory_roots -tracker_storage_get_removable_device_roots -tracker_storage_get_removable_device_udis -tracker_storage_udi_get_mount_point -tracker_storage_udi_get_is_mounted -tracker_storage_uri_is_on_removable_device -tracker_storage_get_volume_udi_for_file -<SUBSECTION Standard> -TRACKER_STORAGE -TRACKER_IS_STORAGE -TRACKER_TYPE_STORAGE -tracker_storage_get_type -TRACKER_STORAGE_CLASS -TRACKER_IS_STORAGE_CLASS -TRACKER_STORAGE_GET_CLASS -</SECTION> - -<SECTION> <FILE>tracker-power</FILE> <TITLE>TrackerPower</TITLE> TrackerPower diff --git a/docs/reference/libtracker-miner/libtracker-miner-docs.sgml b/docs/reference/libtracker-miner/libtracker-miner-docs.sgml index aa533ea73..bfe9175cd 100644 --- a/docs/reference/libtracker-miner/libtracker-miner-docs.sgml +++ b/docs/reference/libtracker-miner/libtracker-miner-docs.sgml @@ -4,6 +4,7 @@ <!ENTITY tracker-miner SYSTEM "xml/tracker-miner.xml"> <!ENTITY tracker-miner-fs SYSTEM "xml/tracker-miner-fs.xml"> <!ENTITY tracker-miner-manager SYSTEM "xml/tracker-miner-manager.xml"> +<!ENTITY tracker-storage SYSTEM "xml/tracker-storage.xml"> <!ENTITY version SYSTEM "version.xml"> ]> <book id="index"> @@ -39,4 +40,9 @@ <title>Managing miners</title> &tracker-miner-manager; </chapter> + + <chapter> + <title>Utilities</title> + &tracker-storage; + </chapter> </book> diff --git a/docs/reference/libtracker-miner/libtracker-miner-sections.txt b/docs/reference/libtracker-miner/libtracker-miner-sections.txt index c764f100f..47ae66ee3 100644 --- a/docs/reference/libtracker-miner/libtracker-miner-sections.txt +++ b/docs/reference/libtracker-miner/libtracker-miner-sections.txt @@ -108,3 +108,23 @@ tracker_thumbnailer_remove_add tracker_thumbnailer_cleanup </SECTION> +<SECTION> +<FILE>tracker-storage</FILE> +<TITLE>TrackerStorage</TITLE> +TrackerStorage +TrackerStorageClass +tracker_storage_new +tracker_storage_get_removable_device_roots +tracker_storage_get_removable_device_uuids +tracker_storage_get_mount_point_for_uuid +tracker_storage_get_uuid_for_file +<SUBSECTION Standard> +TRACKER_STORAGE +TRACKER_IS_STORAGE +TRACKER_TYPE_STORAGE +tracker_storage_get_type +TRACKER_STORAGE_CLASS +TRACKER_IS_STORAGE_CLASS +TRACKER_STORAGE_GET_CLASS +</SECTION> + diff --git a/src/libtracker-common/Makefile.am b/src/libtracker-common/Makefile.am index 479dc1b2b..1cc804e87 100644 --- a/src/libtracker-common/Makefile.am +++ b/src/libtracker-common/Makefile.am @@ -27,14 +27,6 @@ else os_sources = tracker-os-dependant-unix.c endif -# For storage, we need HAL, tracker isn't yet ported to DeviceKit-disks -if HAVE_HAL -storage_headers = \ - tracker-storage.h -storage_sources = \ - tracker-storage-hal.c -endif - # Prefer DeviceKit-power for the power data if it's available, else fall back to HAL if HAVE_DEVKIT_POWER power_headers = \ @@ -57,7 +49,6 @@ libtracker_common_la_SOURCES = \ $(marshal_sources) \ $(os_sources) \ $(power_sources) \ - $(storage_sources) \ tracker-config-file.c \ tracker-class.c \ tracker-date-time.c \ @@ -79,7 +70,6 @@ libtracker_common_la_SOURCES = \ noinst_HEADERS = \ $(power_headers) \ - $(storage_headers) \ tracker-dbus.h \ tracker-ioprio.h \ tracker-log.h \ diff --git a/src/libtracker-common/tracker-storage-hal.c b/src/libtracker-common/tracker-storage-hal.c deleted file mode 100644 index 32822bd2e..000000000 --- a/src/libtracker-common/tracker-storage-hal.c +++ /dev/null @@ -1,1165 +0,0 @@ -/* - * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc@gnome.org) - * Copyright (C) 2008, Nokia (urho.konttori@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" - -#ifdef HAVE_HAL - -#include <string.h> - -#include <gio/gio.h> -#include <libhal.h> -#include <libhal-storage.h> - -#include <dbus/dbus-glib-lowlevel.h> - -#include "tracker-log.h" -#include "tracker-storage.h" -#include "tracker-utils.h" -#include "tracker-marshal.h" - -#define CAPABILITY_VOLUME "volume" - -#define PROP_IS_MOUNTED "volume.is_mounted" - -#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_STORAGE, TrackerStoragePriv)) - -typedef struct { - LibHalContext *context; - DBusConnection *connection; - - GHashTable *all_devices; - - GNode *mounts; - GHashTable *mounts_by_udi; - -} TrackerStoragePriv; - -typedef struct { - gchar *mount_point; - gchar *udi; - guint removable : 1; -} MountInfo; - -typedef struct { - const gchar *path; - GNode *node; -} TraverseData; - -typedef struct { - LibHalContext *context; - GSList *roots; - gboolean only_removable; -} GetRoots; - -static void tracker_storage_finalize (GObject *object); -static void hal_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec); -static gboolean hal_setup_devices (TrackerStorage *hal); - -static gboolean hal_device_add (TrackerStorage *hal, - LibHalVolume *volume); -static void hal_device_added_cb (LibHalContext *context, - const gchar *udi); -static void hal_device_removed_cb (LibHalContext *context, - const gchar *udi); -static void hal_device_property_modified_cb (LibHalContext *context, - const char *udi, - const char *key, - dbus_bool_t is_removed, - dbus_bool_t is_added); - -enum { - PROP_0, -}; - -enum { - MOUNT_POINT_ADDED, - MOUNT_POINT_REMOVED, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = {0}; - -G_DEFINE_TYPE (TrackerStorage, tracker_storage, G_TYPE_OBJECT); - -static void -tracker_storage_class_init (TrackerStorageClass *klass) -{ - GObjectClass *object_class; - - object_class = G_OBJECT_CLASS (klass); - - object_class->finalize = tracker_storage_finalize; - object_class->get_property = hal_get_property; - - signals[MOUNT_POINT_ADDED] = - g_signal_new ("mount-point-added", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - 0, - NULL, NULL, - tracker_marshal_VOID__STRING_STRING, - G_TYPE_NONE, - 2, - G_TYPE_STRING, - G_TYPE_STRING); - - signals[MOUNT_POINT_REMOVED] = - g_signal_new ("mount-point-removed", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - 0, - NULL, NULL, - tracker_marshal_VOID__STRING_STRING, - G_TYPE_NONE, - 2, - G_TYPE_STRING, - G_TYPE_STRING); - - g_type_class_add_private (object_class, sizeof (TrackerStoragePriv)); -} - -static void -tracker_storage_init (TrackerStorage *storage) -{ - TrackerStoragePriv *priv; - DBusError error; - - g_message ("Initializing HAL Storage..."); - - priv = GET_PRIV (storage); - - priv->all_devices = g_hash_table_new_full (g_str_hash, - g_str_equal, - (GDestroyNotify) g_free, - (GDestroyNotify) g_free); - priv->mounts = g_node_new (NULL); - - priv->mounts_by_udi = g_hash_table_new_full (g_str_hash, - g_str_equal, - (GDestroyNotify) g_free, - NULL); - - dbus_error_init (&error); - - priv->connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error); - if (dbus_error_is_set (&error)) { - g_critical ("Could not get the system D-Bus connection, %s", - error.message); - dbus_error_free (&error); - return; - } - - dbus_connection_set_exit_on_disconnect (priv->connection, FALSE); - dbus_connection_setup_with_g_main (priv->connection, NULL); - - priv->context = libhal_ctx_new (); - - if (!priv->context) { - g_critical ("Could not create HAL context"); - return; - } - - libhal_ctx_set_user_data (priv->context, storage); - libhal_ctx_set_dbus_connection (priv->context, priv->connection); - - if (!libhal_ctx_init (priv->context, &error)) { - if (dbus_error_is_set (&error)) { - g_critical ("Could not initialize the HAL context, %s", - error.message); - dbus_error_free (&error); - } else { - g_critical ("Could not initialize the HAL context, " - "no error, is hald running?"); - } - - libhal_ctx_free (priv->context); - priv->context = NULL; - return; - } - - - /* Volume and property notification callbacks */ - g_message ("HAL monitors set for devices added/removed/mounted/umounted..."); - libhal_ctx_set_device_added (priv->context, hal_device_added_cb); - libhal_ctx_set_device_removed (priv->context, hal_device_removed_cb); - libhal_ctx_set_device_property_modified (priv->context, hal_device_property_modified_cb); - - /* Get all devices which are mountable and set them up */ - if (!hal_setup_devices (storage)) { - return; - } -} - -static gboolean -free_mount_info (GNode *node, - gpointer user_data) -{ - MountInfo *info; - - info = node->data; - - if (info) { - g_free (info->mount_point); - g_free (info->udi); - - g_slice_free (MountInfo, info); - } - - return FALSE; -} - -static void -free_mount_node (GNode *node) -{ - g_node_traverse (node, - G_POST_ORDER, - G_TRAVERSE_ALL, - -1, - free_mount_info, - NULL); - - g_node_destroy (node); -} - - -static void -tracker_storage_finalize (GObject *object) -{ - TrackerStoragePriv *priv; - - priv = GET_PRIV (object); - - if (priv->mounts_by_udi) { - g_hash_table_unref (priv->mounts_by_udi); - } - - if (priv->all_devices) { - g_hash_table_unref (priv->all_devices); - } - - if (priv->mounts) { - free_mount_node (priv->mounts); - } - - if (priv->context) { - libhal_ctx_shutdown (priv->context, NULL); - libhal_ctx_set_user_data (priv->context, NULL); - libhal_ctx_free (priv->context); - } - - if (priv->connection) { - dbus_connection_unref (priv->connection); - } - - (G_OBJECT_CLASS (tracker_storage_parent_class)->finalize) (object); -} - -static void -hal_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - TrackerStoragePriv *priv; - - priv = GET_PRIV (object); - - switch (param_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - }; -} - -static gboolean -hal_setup_devices (TrackerStorage *storage) -{ - TrackerStoragePriv *priv; - DBusError error; - gchar **devices, **p; - gint num; - - priv = GET_PRIV (storage); - - dbus_error_init (&error); - - devices = libhal_find_device_by_capability (priv->context, - CAPABILITY_VOLUME, - &num, - &error); - - if (dbus_error_is_set (&error)) { - g_critical ("Could not get devices with 'volume' capability, %s", - error.message); - dbus_error_free (&error); - return FALSE; - } - - if (!devices || !devices[0]) { - g_message ("HAL devices not found with 'volume' capability"); - return TRUE; - } - - for (p = devices; *p; p++) { - LibHalVolume *volume; - - volume = libhal_volume_from_udi (priv->context, *p); - if (!volume) { - continue; - } - - g_debug ("HAL device:'%s' found:", - libhal_volume_get_device_file (volume)); - g_debug (" UDI : %s", - libhal_volume_get_udi (volume)); - g_debug (" Mount point: %s", - libhal_volume_get_mount_point (volume)); - g_debug (" UUID : %s", - libhal_volume_get_uuid (volume)); - g_debug (" Mounted : %s", - libhal_volume_is_mounted (volume) ? "yes" : "no"); - g_debug (" File system: %s", - libhal_volume_get_fstype (volume)); - g_debug (" Label : %s", - libhal_volume_get_label (volume)); - - hal_device_add (storage, volume); - libhal_volume_free (volume); - } - - libhal_free_string_array (devices); - - return TRUE; -} - -static gboolean -mount_point_traverse_func (GNode *node, - gpointer user_data) -{ - TraverseData *data; - MountInfo *info; - - if (!node->data) { - /* Root node */ - return FALSE; - } - - data = user_data; - info = node->data; - - if (g_str_has_prefix (data->path, info->mount_point)) { - data->node = node; - return TRUE; - } - - return FALSE; -} - -static GNode * -find_mount_point (GNode *root, - const gchar *path) -{ - TraverseData data = { path, NULL }; - - g_node_traverse (root, - G_POST_ORDER, - G_TRAVERSE_ALL, - -1, - mount_point_traverse_func, - &data); - - return data.node; -} - -static MountInfo * -find_mount_point_info (GNode *root, - const gchar *path) -{ - GNode *node; - - node = find_mount_point (root, path); - return (node) ? node->data : NULL; -} - -static GNode * -mount_point_hierarchy_add (GNode *root, - const gchar *mount_point, - const gchar *udi, - gboolean removable) -{ - MountInfo *info; - GNode *node; - gchar *mp; - - /* Normalize all mount points to have a / at the end */ - if (g_str_has_suffix (mount_point, G_DIR_SEPARATOR_S)) { - mp = g_strdup (mount_point); - } else { - mp = g_strconcat (mount_point, G_DIR_SEPARATOR_S, NULL); - } - - node = find_mount_point (root, mp); - - if (!node) { - node = root; - } - - info = g_slice_new (MountInfo); - info->mount_point = mp; - info->udi = g_strdup (udi); - info->removable = removable; - - return g_node_append_data (node, info); -} - - -static void -hal_mount_point_add (TrackerStorage *storage, - const gchar *udi, - const gchar *mount_point, - gboolean removable_device) -{ - TrackerStoragePriv *priv; - GNode *node; - - priv = GET_PRIV (storage); - - g_message ("HAL device:'%s' with mount point:'%s', removable:%s now being tracked", - (const gchar*) g_hash_table_lookup (priv->all_devices, udi), - mount_point, - removable_device ? "yes" : "no"); - - node = mount_point_hierarchy_add (priv->mounts, mount_point, udi, removable_device); - g_hash_table_insert (priv->mounts_by_udi, g_strdup (udi), node); - - g_signal_emit (storage, signals[MOUNT_POINT_ADDED], 0, udi, mount_point, NULL); -} - -static void -hal_mount_point_remove (TrackerStorage *storage, - const gchar *udi) -{ - MountInfo *info; - TrackerStoragePriv *priv; - GNode *node; - - priv = GET_PRIV (storage); - - node = g_hash_table_lookup (priv->mounts_by_udi, udi); - - if (!node) { - return; - } - - info = node->data; - - g_message ("HAL device:'%s' with mount point:'%s' (uuid:'%s'), removable:%s NO LONGER being tracked", - (const gchar*) g_hash_table_lookup (priv->all_devices, udi), - info->mount_point, - udi, - info->removable ? "yes" : "no"); - - g_signal_emit (storage, signals[MOUNT_POINT_REMOVED], 0, udi, info->mount_point, NULL); - - g_hash_table_remove (priv->mounts_by_udi, udi); - free_mount_node (node); -} - -static const gchar * -hal_drive_type_to_string (LibHalDriveType type) -{ - switch (type) { - case LIBHAL_DRIVE_TYPE_REMOVABLE_DISK: - return "LIBHAL_DRIVE_TYPE_REMOVABLE_DISK"; - case LIBHAL_DRIVE_TYPE_DISK: - return "LIBHAL_DRIVE_TYPE_DISK"; - case LIBHAL_DRIVE_TYPE_CDROM: - return "LIBHAL_DRIVE_TYPE_CDROM"; - case LIBHAL_DRIVE_TYPE_FLOPPY: - return "LIBHAL_DRIVE_TYPE_FLOPPY"; - case LIBHAL_DRIVE_TYPE_TAPE: - return "LIBHAL_DRIVE_TYPE_TAPE"; - case LIBHAL_DRIVE_TYPE_COMPACT_FLASH: - return "LIBHAL_DRIVE_TYPE_COMPACT_FLASH"; - case LIBHAL_DRIVE_TYPE_MEMORY_STICK: - return "LIBHAL_DRIVE_TYPE_MEMORY_STICK"; - case LIBHAL_DRIVE_TYPE_SMART_MEDIA: - return "LIBHAL_DRIVE_TYPE_SMART_MEDIA"; - case LIBHAL_DRIVE_TYPE_SD_MMC: - return "LIBHAL_DRIVE_TYPE_SD_MMC"; - case LIBHAL_DRIVE_TYPE_CAMERA: - return "LIBHAL_DRIVE_TYPE_CAMERA"; - case LIBHAL_DRIVE_TYPE_PORTABLE_AUDIO_PLAYER: - return "LIBHAL_DRIVE_TYPE_PORTABLE_AUDIO_PLAYER"; - case LIBHAL_DRIVE_TYPE_ZIP: - return "LIBHAL_DRIVE_TYPE_ZIP"; - case LIBHAL_DRIVE_TYPE_JAZ: - return "LIBHAL_DRIVE_TYPE_JAZ"; - case LIBHAL_DRIVE_TYPE_FLASHKEY: - return "LIBHAL_DRIVE_TYPE_FLASHKEY"; - case LIBHAL_DRIVE_TYPE_MO: - return "LIBHAL_DRIVE_TYPE_MO"; - default: - return ""; - } -} - -static gboolean -hal_device_is_user_removable (TrackerStorage *storage, - const gchar *device_file, - const gchar *mount_point) -{ - TrackerStoragePriv *priv; - LibHalDrive *drive; - gboolean removable; - - if (!device_file) { - return FALSE; - } - - priv = GET_PRIV (storage); - - drive = libhal_drive_from_device_file (priv->context, device_file); - if (!drive) { - return FALSE; - } - - removable = libhal_drive_uses_removable_media (drive); - - if (libhal_drive_get_type (drive) == LIBHAL_DRIVE_TYPE_SD_MMC) { - /* mmc block devices are not considered removable according to - linux kernel as they do not contain removable media, they - are simply hotpluggable - consider all SD/MMC volumes mounted in /media as user removable - */ - if (g_str_has_prefix (mount_point, "/media/")) { - removable = TRUE; - } - } - - libhal_drive_free (drive); - - return removable; -} - -static gboolean -hal_device_should_be_tracked (TrackerStorage *storage, - const gchar *device_file) -{ - TrackerStoragePriv *priv; - LibHalDrive *drive; - LibHalDriveType drive_type; - gboolean eligible; - - if (!device_file) { - return FALSE; - } - - priv = GET_PRIV (storage); - - drive = libhal_drive_from_device_file (priv->context, device_file); - if (!drive) { - return FALSE; - } - - /* From the list, the first one below seems to be the ONLY one - * to ignore: - * - * LIBHAL_DRIVE_TYPE_REMOVABLE_DISK = 0x00, - * LIBHAL_DRIVE_TYPE_DISK = 0x01, - * LIBHAL_DRIVE_TYPE_CDROM = 0x02, - * LIBHAL_DRIVE_TYPE_FLOPPY = 0x03, - * LIBHAL_DRIVE_TYPE_TAPE = 0x04, - * LIBHAL_DRIVE_TYPE_COMPACT_FLASH = 0x05, - * LIBHAL_DRIVE_TYPE_MEMORY_STICK = 0x06, - * LIBHAL_DRIVE_TYPE_SMART_MEDIA = 0x07, - * LIBHAL_DRIVE_TYPE_SD_MMC = 0x08, - * LIBHAL_DRIVE_TYPE_CAMERA = 0x09, - * LIBHAL_DRIVE_TYPE_PORTABLE_AUDIO_PLAYER = 0x0a, - * LIBHAL_DRIVE_TYPE_ZIP = 0x0b, - * LIBHAL_DRIVE_TYPE_JAZ = 0x0c, - * LIBHAL_DRIVE_TYPE_FLASHKEY = 0x0d, - * LIBHAL_DRIVE_TYPE_MO = 0x0e - * - */ - - drive_type = libhal_drive_get_type (drive); - - /* So here we don't track CDROM devices or the hard disks in - * the machine, we simply track devices which are added or - * removed in real time which we are interested in and which - * are viable for tracking. CDROMs are too slow. - */ - eligible = TRUE; - eligible &= drive_type != LIBHAL_DRIVE_TYPE_DISK; - eligible &= drive_type != LIBHAL_DRIVE_TYPE_CDROM; - - libhal_drive_free (drive); - - if (!eligible) { - g_message ("HAL device:'%s' is not eligible for tracking, type is '%s'", - device_file, - hal_drive_type_to_string (drive_type)); - } else { - g_message ("HAL device:'%s' is eligible for tracking, type is '%s'", - device_file, - hal_drive_type_to_string (drive_type)); - } - - return eligible; -} - -static gboolean -hal_device_add (TrackerStorage *storage, - LibHalVolume *volume) -{ - TrackerStoragePriv *priv; - DBusError error; - const gchar *udi; - const gchar *mount_point; - const gchar *device_file; - - priv = GET_PRIV (storage); - - dbus_error_init (&error); - - udi = libhal_volume_get_udi (volume); - mount_point = libhal_volume_get_mount_point (volume); - device_file = libhal_volume_get_device_file (volume); - - if (g_hash_table_lookup (priv->all_devices, udi)) { - return TRUE; - } - - /* If there is no mount point, then there is nothing to track */ - if (!hal_device_should_be_tracked (storage, device_file)) { - return TRUE; - } - - /* Make sure we watch changes to the mount/umount state */ - libhal_device_add_property_watch (priv->context, udi, &error); - - if (dbus_error_is_set (&error)) { - g_critical ("Could not add device:'%s' property watch for udi:'%s', %s", - device_file, - udi, - error.message); - dbus_error_free (&error); - return FALSE; - } - - g_hash_table_insert (priv->all_devices, - g_strdup (udi), - g_strdup (device_file)); - - if (mount_point) { - hal_mount_point_add (storage, - udi, - mount_point, - hal_device_is_user_removable (storage, device_file, mount_point)); - } - - return TRUE; -} - -static void -hal_device_added_cb (LibHalContext *context, - const gchar *udi) -{ - TrackerStorage *storage; - LibHalVolume *volume; - - storage = libhal_ctx_get_user_data (context); - - if (libhal_device_query_capability (context, udi, CAPABILITY_VOLUME, NULL)) { - volume = libhal_volume_from_udi (context, udi); - - if (!volume) { - /* Not a device with a volume */ - return; - } - - g_message ("HAL device:'%s' added:", - libhal_volume_get_device_file (volume)); - g_message (" UDI : %s", - udi); - g_message (" Mount point: %s", - libhal_volume_get_mount_point (volume)); - g_message (" UUID : %s", - libhal_volume_get_uuid (volume)); - g_message (" Mounted : %s", - libhal_volume_is_mounted (volume) ? "yes" : "no"); - g_message (" File system: %s", - libhal_volume_get_fstype (volume)); - g_message (" Label : %s", - libhal_volume_get_label (volume)); - - hal_device_add (storage, volume); - libhal_volume_free (volume); - } -} - -static void -hal_device_removed_cb (LibHalContext *context, - const gchar *udi) -{ - TrackerStorage *storage; - TrackerStoragePriv *priv; - const gchar *device_file; - - storage = libhal_ctx_get_user_data (context); - priv = GET_PRIV (storage); - - if (g_hash_table_lookup (priv->all_devices, udi)) { - device_file = g_hash_table_lookup (priv->all_devices, udi); - - if (!device_file) { - /* Don't report about unknown devices */ - return; - } - - g_message ("HAL device:'%s' removed:", - device_file); - g_message (" UDI : %s", - udi); - - g_hash_table_remove (priv->all_devices, udi); - - hal_mount_point_remove (storage, udi); - } -} - -static void -hal_device_property_modified_cb (LibHalContext *context, - const char *udi, - const char *key, - dbus_bool_t is_removed, - dbus_bool_t is_added) -{ - TrackerStorage *storage; - TrackerStoragePriv *priv; - DBusError error; - - storage = libhal_ctx_get_user_data (context); - priv = GET_PRIV (storage); - - dbus_error_init (&error); - - if (g_hash_table_lookup (priv->all_devices, udi)) { - const gchar *device_file; - gboolean is_mounted; - - device_file = g_hash_table_lookup (priv->all_devices, udi); - - g_message ("HAL device:'%s' property change for udi:'%s' and key:'%s'", - device_file, - udi, - key); - - if (strcmp (key, PROP_IS_MOUNTED) != 0) { - return; - } - - is_mounted = libhal_device_get_property_bool (context, - udi, - key, - &error); - - if (dbus_error_is_set (&error)) { - g_message ("Could not get device property:'%s' for udi:'%s', %s", - udi, key, error.message); - dbus_error_free (&error); - - g_message ("HAL device:'%s' with udi:'%s' is now unmounted (due to error)", - device_file, - udi); - hal_mount_point_remove (storage, udi); - return; - } - - if (is_mounted) { - LibHalVolume *volume; - const gchar *mount_point; - - volume = libhal_volume_from_udi (context, udi); - mount_point = libhal_volume_get_mount_point (volume); - - g_message ("HAL device:'%s' with udi:'%s' is now mounted", - device_file, - udi); - - hal_mount_point_add (storage, - udi, - mount_point, - hal_device_is_user_removable (storage, device_file, mount_point)); - - libhal_volume_free (volume); - } else { - g_message ("HAL device:'%s' with udi:'%s' is now unmounted", - device_file, - udi); - - hal_mount_point_remove (storage, udi); - } - } -} - -/** - * tracker_storage_new: - * - * Creates a new instance of #TrackerStorage. - * - * Returns: The newly created #TrackerStorage. - **/ -TrackerStorage * -tracker_storage_new (void) -{ - return g_object_new (TRACKER_TYPE_STORAGE, NULL); -} - -static void -hal_get_mount_point_by_udi_foreach (gpointer key, - gpointer value, - gpointer user_data) -{ - GetRoots *gr; - const gchar *udi; - GNode *node; - MountInfo *info; - - gr = user_data; - udi = key; - node = value; - info = node->data; - - if (!gr->only_removable || info->removable) { - gchar *normalized_mount_point; - gint len; - - normalized_mount_point = g_strdup (info->mount_point); - len = strlen (normalized_mount_point); - - /* Don't include trailing slashes */ - if (len > 2 && normalized_mount_point[len - 1] == G_DIR_SEPARATOR) { - normalized_mount_point[len - 1] = '\0'; - } - - gr->roots = g_slist_prepend (gr->roots, normalized_mount_point); - } -} - -/** - * tracker_storage_get_mounted_directory_roots: - * @storage: A #TrackerStorage - * - * Returns a #GSList of strings containing the root directories for - * mounted devices. - * - * Each element must be freed using g_free() and the list itself using - * g_slist_free(). - * - * Returns: The list of root directories. - **/ -GSList * -tracker_storage_get_mounted_directory_roots (TrackerStorage *storage) -{ - TrackerStoragePriv *priv; - GetRoots gr; - - g_return_val_if_fail (TRACKER_IS_STORAGE (storage), NULL); - - priv = GET_PRIV (storage); - - gr.context = priv->context; - gr.roots = NULL; - gr.only_removable = FALSE; - - g_hash_table_foreach (priv->mounts_by_udi, - hal_get_mount_point_by_udi_foreach, - &gr); - - return g_slist_reverse (gr.roots); -} - -/** - * tracker_storage_get_removable_device_roots: - * @storage: A #TrackerStorage - * - * Returns a #GSList of strings containing the root directories for - * removable devices. - * - * Each element must be freed using g_free() and the list itself - * through g_slist_free(). - * - * Returns: The list of root directories. - **/ -GSList * -tracker_storage_get_removable_device_roots (TrackerStorage *storage) -{ - TrackerStoragePriv *priv; - GetRoots gr; - - g_return_val_if_fail (TRACKER_IS_STORAGE (storage), NULL); - - priv = GET_PRIV (storage); - - gr.context = priv->context; - gr.roots = NULL; - gr.only_removable = TRUE; - - g_hash_table_foreach (priv->mounts_by_udi, - hal_get_mount_point_by_udi_foreach, - &gr); - - return g_slist_reverse (gr.roots); -} - -/** - * tracker_storage_path_is_on_removable_device: - * @storage: A #TrackerStorage - * @uri: a uri - * @mount_mount: if @uri is on a removable device, the mount point will - * be filled in here. You must free the returned result - * @available: if @uri is on a removable device, this will be set to - * TRUE in case the file is available right now - * - * Returns Whether or not @uri is on a known removable device - * - * Returns: TRUE if @uri on a known removable device, FALSE otherwise - **/ -gboolean -tracker_storage_uri_is_on_removable_device (TrackerStorage *storage, - const gchar *uri, - gchar **mount_point, - gboolean *available) -{ - TrackerStoragePriv *priv; - gchar *path; - GFile *file; - MountInfo *info; - - g_return_val_if_fail (TRACKER_IS_STORAGE (storage), FALSE); - - file = g_file_new_for_uri (uri); - path = g_file_get_path (file); - - if (!path) { - g_object_unref (file); - return FALSE; - } - - priv = GET_PRIV (storage); - info = find_mount_point_info (priv->mounts, path); - - if (!info) { - g_free (path); - g_object_unref (file); - return FALSE; - } - - if (!info->removable) { - g_free (path); - g_object_unref (file); - return FALSE; - } - - /* Mount point found and is removable */ - if (mount_point) { - *mount_point = g_strdup (info->mount_point); - } - - if (available) { - *available = TRUE; - } - - g_free (path); - g_object_unref (file); - - return TRUE; -} - -/** - * tracker_storage_get_removable_device_udis: - * @storage: A #TrackerStorage - * - * Returns a #GSList of strings containing the UDI for removable devices. - * Each element is owned by the #GHashTable internally, the list - * itself through should be freed using g_slist_free(). - * - * Returns: The list of UDIs. - **/ -GSList * -tracker_storage_get_removable_device_udis (TrackerStorage *storage) -{ - TrackerStoragePriv *priv; - GHashTableIter iter; - gpointer key, value; - GSList *udis; - - g_return_val_if_fail (TRACKER_IS_STORAGE (storage), NULL); - - priv = GET_PRIV (storage); - - udis = NULL; - - g_hash_table_iter_init (&iter, priv->mounts_by_udi); - - while (g_hash_table_iter_next (&iter, &key, &value)) { - const gchar *udi; - GNode *node; - MountInfo *info; - - udi = key; - node = value; - info = node->data; - - if (info->removable) { - udis = g_slist_prepend (udis, g_strdup (udi)); - } - } - - return g_slist_reverse (udis); -} - -/** - * tracker_storage_udi_get_mount_point: - * @storage: A #TrackerStorage - * @udi: A string pointer to the UDI for the device. - * - * Returns: The mount point for @udi, this should not be freed. - **/ -const gchar * -tracker_storage_udi_get_mount_point (TrackerStorage *storage, - const gchar *udi) -{ - TrackerStoragePriv *priv; - GNode *node; - MountInfo *info; - - g_return_val_if_fail (TRACKER_IS_STORAGE (storage), NULL); - g_return_val_if_fail (udi != NULL, NULL); - - priv = GET_PRIV (storage); - - node = g_hash_table_lookup (priv->mounts_by_udi, udi); - - if (!node) { - return NULL; - } - - info = node->data; - return info->mount_point; -} - -/** - * tracker_storage_udi_get_mount_point: - * @storage: A #TrackerStorage - * @udi: A #gboolean - * - * Returns: The %TRUE if @udi is mounted or %FALSE if it isn't. - **/ -gboolean -tracker_storage_udi_get_is_mounted (TrackerStorage *storage, - const gchar *udi) -{ - TrackerStoragePriv *priv; - LibHalVolume *volume; - const gchar *mount_point; - gboolean is_mounted; - - g_return_val_if_fail (TRACKER_IS_STORAGE (storage), FALSE); - g_return_val_if_fail (udi != NULL, FALSE); - - priv = GET_PRIV (storage); - - volume = libhal_volume_from_udi (priv->context, udi); - if (!volume) { - g_message ("HAL device with udi:'%s' has no volume, " - "should we delete?", - udi); - return FALSE; - } - - mount_point = libhal_volume_get_mount_point (volume); - is_mounted = libhal_volume_is_mounted (volume); - - libhal_volume_free (volume); - - return is_mounted && mount_point; - -} - -/** - * tracker_storage_get_volume_udi_for_file: - * @storage: A #TrackerStorage - * @file: a file - * - * Returns the UDI of the removable device for @file - * - * Returns: Returns the UDI of the removable device for @file - **/ -const gchar * -tracker_storage_get_volume_udi_for_file (TrackerStorage *storage, - GFile *file) -{ - TrackerStoragePriv *priv; - gchar *path; - MountInfo *info; - - g_return_val_if_fail (TRACKER_IS_STORAGE (storage), FALSE); - - path = g_file_get_path (file); - - if (!path) { - return NULL; - } - - /* Normalize all paths to have a / at the end */ - if (!g_str_has_suffix (path, G_DIR_SEPARATOR_S)) { - gchar *norm_path; - - norm_path = g_strconcat (path, G_DIR_SEPARATOR_S, NULL); - g_free (path); - path = norm_path; - } - - - priv = GET_PRIV (storage); - - info = find_mount_point_info (priv->mounts, path); - - if (!info) { - g_free (path); - return NULL; - } - - g_debug ("Mount for path '%s' is '%s' (UDI:'%s')", - path, info->mount_point, info->udi); - - g_free (path); - - return info->udi; -} - -#endif /* HAVE_HAL */ diff --git a/src/libtracker-miner/Makefile.am b/src/libtracker-miner/Makefile.am index 973126a04..75752ef70 100644 --- a/src/libtracker-miner/Makefile.am +++ b/src/libtracker-miner/Makefile.am @@ -40,6 +40,8 @@ libtracker_miner_@TRACKER_API_VERSION@_la_SOURCES = \ tracker-miner-manager.h \ tracker-monitor.c \ tracker-monitor.h \ + tracker-storage.c \ + tracker-storage.h \ tracker-utils.c \ tracker-utils.h \ tracker-thumbnailer.c @@ -50,10 +52,11 @@ libtracker_minerinclude_HEADERS = \ tracker-miner-dbus.h \ tracker-miner-fs.h \ tracker-miner-manager.h \ + tracker-storage.h \ tracker-thumbnailer.h libtracker_miner_@TRACKER_API_VERSION@_la_LDFLAGS = \ - -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \ + -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \m -export-symbols-regex '^tracker_(miner|thumbnailer|crawler)_.*' libtracker_miner_@TRACKER_API_VERSION@_la_LIBADD = \ diff --git a/src/libtracker-miner/tracker-marshal.list b/src/libtracker-miner/tracker-marshal.list index 5b5988c08..05c67289c 100644 --- a/src/libtracker-miner/tracker-marshal.list +++ b/src/libtracker-miner/tracker-marshal.list @@ -4,6 +4,7 @@ VOID:OBJECT,POINTER,UINT,UINT,UINT,UINT VOID:DOUBLE,UINT,UINT,UINT,UINT VOID:STRING,STRING,DOUBLE VOID:STRING,DOUBLE +VOID:STRING,STRING BOOL:OBJECT,OBJECT,OBJECT BOOL:OBJECT,OBJECT BOOL:OBJECT,POINTER diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c new file mode 100644 index 000000000..c086d5953 --- /dev/null +++ b/src/libtracker-miner/tracker-storage.c @@ -0,0 +1,748 @@ +/* + * Copyright (C) 2008, Nokia (urho.konttori@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 <libtracker-common/tracker-log.h> + +#include "tracker-storage.h" +#include "tracker-utils.h" +#include "tracker-marshal.h" + +#define TRACKER_STORAGE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_STORAGE, TrackerStoragePrivate)) + +typedef struct { + GVolumeMonitor *volume_monitor; + + GNode *mounts; + GHashTable *mounts_by_uuid; +} TrackerStoragePrivate; + +typedef struct { + gchar *mount_point; + gchar *uuid; + guint removable : 1; +} MountInfo; + +typedef struct { + const gchar *path; + GNode *node; +} TraverseData; + +typedef struct { + GSList *roots; + gboolean only_removable; +} GetRoots; + +static void tracker_storage_finalize (GObject *object); +static gboolean mount_info_free (GNode *node, + gpointer user_data); +static void mount_node_free (GNode *node); +static gboolean drives_setup (TrackerStorage *storage); +static void mount_added_cb (GVolumeMonitor *monitor, + GMount *mount, + gpointer user_data); +static void mount_removed_cb (GVolumeMonitor *monitor, + GMount *mount, + gpointer user_data); +static void volume_added_cb (GVolumeMonitor *monitor, + GVolume *volume, + gpointer user_data); + +enum { + MOUNT_POINT_ADDED, + MOUNT_POINT_REMOVED, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = {0}; + +G_DEFINE_TYPE (TrackerStorage, tracker_storage, G_TYPE_OBJECT); + +static void +tracker_storage_class_init (TrackerStorageClass *klass) +{ + GObjectClass *object_class; + + object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = tracker_storage_finalize; + + signals[MOUNT_POINT_ADDED] = + g_signal_new ("mount-point-added", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + tracker_marshal_VOID__STRING_STRING, + G_TYPE_NONE, + 2, + G_TYPE_STRING, + G_TYPE_STRING); + + signals[MOUNT_POINT_REMOVED] = + g_signal_new ("mount-point-removed", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + tracker_marshal_VOID__STRING_STRING, + G_TYPE_NONE, + 2, + G_TYPE_STRING, + G_TYPE_STRING); + + g_type_class_add_private (object_class, sizeof (TrackerStoragePrivate)); +} + +static void +tracker_storage_init (TrackerStorage *storage) +{ + TrackerStoragePrivate *priv; + + g_message ("Initializing Storage..."); + + priv = TRACKER_STORAGE_GET_PRIVATE (storage); + + priv->mounts = g_node_new (NULL); + + priv->mounts_by_uuid = g_hash_table_new_full (g_str_hash, + g_str_equal, + (GDestroyNotify) g_free, + NULL); + + priv->volume_monitor = g_volume_monitor_get (); + + /* Volume and property notification callbacks */ + g_signal_connect_object (priv->volume_monitor, "mount-removed", + G_CALLBACK (mount_removed_cb), storage, 0); + g_signal_connect_object (priv->volume_monitor, "mount-pre_unmount", + G_CALLBACK (mount_removed_cb), storage, 0); + g_signal_connect_object (priv->volume_monitor, "mount-added", + G_CALLBACK (mount_added_cb), storage, 0); + g_signal_connect_object (priv->volume_monitor, "volume-added", + G_CALLBACK (volume_added_cb), storage, 0); + + g_message ("Drive/Volume monitors set up for to watch for added, removed and pre-unmounts..."); + + /* Get all devices which are mountable and set them up */ + if (!drives_setup (storage)) { + return; + } +} + +static void +tracker_storage_finalize (GObject *object) +{ + TrackerStoragePrivate *priv; + + priv = TRACKER_STORAGE_GET_PRIVATE (object); + + if (priv->mounts_by_uuid) { + g_hash_table_unref (priv->mounts_by_uuid); + } + + if (priv->mounts) { + mount_node_free (priv->mounts); + } + + if (priv->volume_monitor) { + g_object_unref (priv->volume_monitor); + } + + (G_OBJECT_CLASS (tracker_storage_parent_class)->finalize) (object); +} + +static void +mount_node_free (GNode *node) +{ + g_node_traverse (node, + G_POST_ORDER, + G_TRAVERSE_ALL, + -1, + mount_info_free, + NULL); + + g_node_destroy (node); +} + +static gboolean +mount_node_traverse_func (GNode *node, + gpointer user_data) +{ + TraverseData *data; + MountInfo *info; + + if (!node->data) { + /* Root node */ + return FALSE; + } + + data = user_data; + info = node->data; + + if (g_str_has_prefix (data->path, info->mount_point)) { + data->node = node; + return TRUE; + } + + return FALSE; +} + +static GNode * +mount_node_find (GNode *root, + const gchar *path) +{ + TraverseData data = { path, NULL }; + + g_node_traverse (root, + G_POST_ORDER, + G_TRAVERSE_ALL, + -1, + mount_node_traverse_func, + &data); + + return data.node; +} + +static gboolean +mount_info_free (GNode *node, + gpointer user_data) +{ + MountInfo *info; + + info = node->data; + + if (info) { + g_free (info->mount_point); + g_free (info->uuid); + + g_slice_free (MountInfo, info); + } + + return FALSE; +} + +static MountInfo * +mount_info_find (GNode *root, + const gchar *path) +{ + GNode *node; + + node = mount_node_find (root, path); + return (node) ? node->data : NULL; +} + +static gchar * +mount_point_normalize (const gchar *mount_point) +{ + gchar *mp; + + /* Normalize all mount points to have a / at the end */ + if (g_str_has_suffix (mount_point, G_DIR_SEPARATOR_S)) { + mp = g_strdup (mount_point); + } else { + mp = g_strconcat (mount_point, G_DIR_SEPARATOR_S, NULL); + } + + return mp; +} + +static GNode * +mount_add_hierarchy (GNode *root, + const gchar *uuid, + const gchar *mount_point, + gboolean removable) +{ + MountInfo *info; + GNode *node; + gchar *mp; + + mp = mount_point_normalize (mount_point); + node = mount_node_find (root, mp); + + if (!node) { + node = root; + } + + info = g_slice_new (MountInfo); + info->mount_point = mp; + info->uuid = g_strdup (uuid); + info->removable = removable; + + return g_node_append_data (node, info); +} + +static void +mount_add (TrackerStorage *storage, + const gchar *uuid, + const gchar *mount_point, + gboolean removable_device) +{ + TrackerStoragePrivate *priv; + GNode *node; + + priv = TRACKER_STORAGE_GET_PRIVATE (storage); + + node = mount_add_hierarchy (priv->mounts, uuid, mount_point, removable_device); + g_hash_table_insert (priv->mounts_by_uuid, g_strdup (uuid), node); + + g_signal_emit (storage, signals[MOUNT_POINT_ADDED], 0, uuid, mount_point, NULL); +} + +static void +volume_add (TrackerStorage *storage, + GVolume *volume, + gboolean initialization) +{ + TrackerStoragePrivate *priv; + GMount *mount; + gchar *str; + gboolean is_mounted; + gchar *uuid; + gchar *mount_point; + gchar *device_file; + + if (!initialization) { + GDrive *drive; + + drive = g_volume_get_drive (volume); + + if (drive) { + g_debug ("Drive:'%s' added 1 volume:", + g_drive_get_name (drive)); + } else { + g_debug ("No drive associated with volume being added:"); + } + } + + str = g_volume_get_name (volume); + g_debug (" Volume:'%s' found", str); + g_free (str); + + if (!g_volume_should_automount (volume) || + !g_volume_can_mount (volume)) { + g_debug (" Ignoring, volume can not be automatically mounted or mounted at all"); + return; + } + + device_file = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); + g_debug (" Device file : %s", device_file); + + mount = g_volume_get_mount (volume); + + if (mount) { + GFile *file; + + file = g_mount_get_root (mount); + + mount_point = g_file_get_path (file); + g_debug (" Mount point : %s", mount_point); + + g_object_unref (file); + g_object_unref (mount); + + is_mounted = TRUE; + } else { + mount_point = NULL; + is_mounted = FALSE; + } + + uuid = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UUID); + g_debug (" UUID : %s", uuid); + + g_debug (" Mounted : %s", is_mounted ? "yes" : "no"); + + priv = TRACKER_STORAGE_GET_PRIVATE (storage); + + if (mount_point && !g_hash_table_lookup (priv->mounts_by_uuid, uuid)) { + mount_add (storage, uuid, mount_point, TRUE); + } + + g_free (uuid); + g_free (mount_point); + g_free (device_file); +} + +static gboolean +drives_setup (TrackerStorage *storage) +{ + TrackerStoragePrivate *priv; + GList *drives, *ld; + + priv = TRACKER_STORAGE_GET_PRIVATE (storage); + + drives = g_volume_monitor_get_connected_drives (priv->volume_monitor); + + if (g_list_length (drives) < 1) { + g_message ("No drives found to iterate"); + return TRUE; + } + + for (ld = drives; ld; ld = ld->next) { + GDrive *drive; + GList *volumes, *lv; + + drive = ld->data; + + if (!drive) { + continue; + } + + volumes = g_drive_get_volumes (drive); + + g_debug ("Drive:'%s' found with %d %s:", + g_drive_get_name (drive), + g_list_length (volumes), + (volumes && !volumes->next) ? "volume" : "volumes"); + + for (lv = volumes; lv; lv = lv->next) { + volume_add (storage, lv->data, TRUE); + g_object_unref (lv->data); + } + + g_list_free (volumes); + g_object_unref (ld->data); + } + + g_list_free (drives); + + return TRUE; +} + +static void +mount_added_cb (GVolumeMonitor *monitor, + GMount *mount, + gpointer user_data) +{ + TrackerStorage *storage; + GVolume *volume; + GFile *file; + gchar *mount_point; + gchar *name; + + storage = user_data; + + name = g_mount_get_name (mount); + file = g_mount_get_root (mount); + mount_point = g_file_get_path (file); + + g_message ("Mount:'%s', now mounted on:'%s'", + name, + mount_point); + + volume = g_mount_get_volume (mount); + + if (volume) { + gchar *device_file; + gchar *uuid; + gboolean removable_device = TRUE; + + device_file = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); + uuid = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UUID); + + /* NOTE: We only deal with removable devices */ + removable_device = TRUE; + + g_message (" Device:'%s', UUID:'%s'", + device_file, + uuid); + + /* We don't have a UUID for CDROMs */ + if (uuid) { + g_message (" Being added as a tracker resource to index!"); + mount_add (storage, uuid, mount_point, removable_device); + } else { + g_message (" Being ignored because we have no UUID"); + } + + g_free (uuid); + g_free (device_file); + g_object_unref (volume); + } else { + g_message (" Being ignored because we have no GVolume"); + } + + g_free (mount_point); + g_object_unref (file); + g_free (name); +} + +static void +mount_removed_cb (GVolumeMonitor *monitor, + GMount *mount, + gpointer user_data) +{ + TrackerStorage *storage; + TrackerStoragePrivate *priv; + MountInfo *info; + GNode *node; + GFile *file; + gchar *name; + gchar *mount_point; + gchar *mp; + + storage = user_data; + priv = TRACKER_STORAGE_GET_PRIVATE (storage); + + file = g_mount_get_root (mount); + mount_point = g_file_get_path (file); + name = g_mount_get_name (mount); + + mp = mount_point_normalize (mount_point); + node = mount_node_find (priv->mounts, mp); + g_free (mp); + + if (node) { + info = node->data; + + g_message ("Mount:'%s' with UUID:'%s' now unmounted from:'%s'", + name, + info->uuid, + mount_point); + + g_signal_emit (storage, signals[MOUNT_POINT_REMOVED], 0, info->uuid, mount_point, NULL); + + g_hash_table_remove (priv->mounts_by_uuid, info->uuid); + mount_node_free (node); + } else { + g_message ("Mount:'%s' now unmounted from:'%s' (was not tracked)", + name, + mount_point); + } + + g_free (name); + g_free (mount_point); + g_object_unref (file); +} + +static void +volume_added_cb (GVolumeMonitor *monitor, + GVolume *volume, + gpointer user_data) +{ + volume_add (user_data, volume, FALSE); +} + +/** + * tracker_storage_new: + * + * Creates a new instance of #TrackerStorage. + * + * Returns: The newly created #TrackerStorage. + **/ +TrackerStorage * +tracker_storage_new (void) +{ + return g_object_new (TRACKER_TYPE_STORAGE, NULL); +} + +static void +get_mount_point_by_uuid_foreach (gpointer key, + gpointer value, + gpointer user_data) +{ + GetRoots *gr; + const gchar *uuid; + GNode *node; + MountInfo *info; + + gr = user_data; + uuid = key; + node = value; + info = node->data; + + if (!gr->only_removable || info->removable) { + gchar *normalized_mount_point; + gint len; + + normalized_mount_point = g_strdup (info->mount_point); + len = strlen (normalized_mount_point); + + /* Don't include trailing slashes */ + if (len > 2 && normalized_mount_point[len - 1] == G_DIR_SEPARATOR) { + normalized_mount_point[len - 1] = '\0'; + } + + gr->roots = g_slist_prepend (gr->roots, normalized_mount_point); + } +} + +/** + * tracker_storage_get_removable_device_roots: + * @storage: A #TrackerStorage + * + * Returns a #GSList of strings containing the root directories for + * removable devices. + * + * Each element must be freed using g_free() and the list itself + * through g_slist_free(). + * + * Returns: The list of root directories. + **/ +GSList * +tracker_storage_get_removable_device_roots (TrackerStorage *storage) +{ + TrackerStoragePrivate *priv; + GetRoots gr; + + g_return_val_if_fail (TRACKER_IS_STORAGE (storage), NULL); + + priv = TRACKER_STORAGE_GET_PRIVATE (storage); + + gr.roots = NULL; + gr.only_removable = TRUE; + + g_hash_table_foreach (priv->mounts_by_uuid, + get_mount_point_by_uuid_foreach, + &gr); + + return gr.roots; +} + +/** + * tracker_storage_get_removable_device_uuids: + * @storage: A #TrackerStorage + * + * Returns a #GSList of strings containing the UUID for removable devices. + * Each element is owned by the #GHashTable internally, the list + * itself through should be freed using g_slist_free(). + * + * Returns: The list of UUIDs. + **/ +GSList * +tracker_storage_get_removable_device_uuids (TrackerStorage *storage) +{ + TrackerStoragePrivate *priv; + GHashTableIter iter; + gpointer key, value; + GSList *uuids; + + g_return_val_if_fail (TRACKER_IS_STORAGE (storage), NULL); + + priv = TRACKER_STORAGE_GET_PRIVATE (storage); + + uuids = NULL; + + g_hash_table_iter_init (&iter, priv->mounts_by_uuid); + + while (g_hash_table_iter_next (&iter, &key, &value)) { + const gchar *uuid; + GNode *node; + MountInfo *info; + + uuid = key; + node = value; + info = node->data; + + if (info->removable) { + uuids = g_slist_prepend (uuids, g_strdup (uuid)); + } + } + + return uuids; +} + +/** + * tracker_storage_get_mount_point_for_uuid: + * @storage: A #TrackerStorage + * @uuid: A string pointer to the UUID for the %GVolume. + * + * Returns: The mount point for @uuid, this should not be freed. + **/ +const gchar * +tracker_storage_get_mount_point_for_uuid (TrackerStorage *storage, + const gchar *uuid) +{ + TrackerStoragePrivate *priv; + GNode *node; + MountInfo *info; + + g_return_val_if_fail (TRACKER_IS_STORAGE (storage), NULL); + g_return_val_if_fail (uuid != NULL, NULL); + + priv = TRACKER_STORAGE_GET_PRIVATE (storage); + + node = g_hash_table_lookup (priv->mounts_by_uuid, uuid); + + if (!node) { + return NULL; + } + + info = node->data; + + return info->mount_point; +} + +/** + * tracker_storage_get_uuid_for_file: + * @storage: A #TrackerStorage + * @file: a file + * + * Returns the UUID of the removable device for @file + * + * Returns: Returns the UUID of the removable device for @file, this + * should not be freed. + **/ +const gchar * +tracker_storage_get_uuid_for_file (TrackerStorage *storage, + GFile *file) +{ + TrackerStoragePrivate *priv; + gchar *path; + MountInfo *info; + + g_return_val_if_fail (TRACKER_IS_STORAGE (storage), FALSE); + + path = g_file_get_path (file); + + if (!path) { + return NULL; + } + + /* Normalize all paths to have a / at the end */ + if (!g_str_has_suffix (path, G_DIR_SEPARATOR_S)) { + gchar *norm_path; + + norm_path = g_strconcat (path, G_DIR_SEPARATOR_S, NULL); + g_free (path); + path = norm_path; + } + + priv = TRACKER_STORAGE_GET_PRIVATE (storage); + + info = mount_info_find (priv->mounts, path); + + if (!info) { + g_free (path); + return NULL; + } + + /* g_debug ("Mount for path '%s' is '%s' (UUID:'%s')", */ + /* path, info->mount_point, info->uuid); */ + + g_free (path); + + return info->uuid; +} + diff --git a/src/libtracker-common/tracker-storage.h b/src/libtracker-miner/tracker-storage.h index f7e5b0f26..ee40e91cd 100644 --- a/src/libtracker-common/tracker-storage.h +++ b/src/libtracker-miner/tracker-storage.h @@ -17,18 +17,14 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __LIBTRACKER_COMMON_STORAGE_H__ -#define __LIBTRACKER_COMMON_STORAGE_H__ +#ifndef __LIBTRACKER_MINER_STORAGE_H__ +#define __LIBTRACKER_MINER_STORAGE_H__ #include <glib-object.h> #include <gio/gio.h> G_BEGIN_DECLS -#if !defined (__LIBTRACKER_COMMON_INSIDE__) && !defined (TRACKER_COMPILATION) -#error "only <libtracker-common/tracker-common.h> must be included directly." -#endif - #define TRACKER_TYPE_STORAGE (tracker_storage_get_type ()) #define TRACKER_STORAGE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_STORAGE, TrackerStorage)) #define TRACKER_STORAGE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), TRACKER_TYPE_STORAGE, TrackerStorageClass)) @@ -47,26 +43,15 @@ struct _TrackerStorageClass { GObjectClass parent_class; }; -#ifdef HAVE_HAL - -GType tracker_storage_get_type (void) G_GNUC_CONST; -TrackerStorage *tracker_storage_new (void); -GSList * tracker_storage_get_mounted_directory_roots (TrackerStorage *storage); -GSList * tracker_storage_get_removable_device_roots (TrackerStorage *storage); -GSList * tracker_storage_get_removable_device_udis (TrackerStorage *storage); -const gchar * tracker_storage_udi_get_mount_point (TrackerStorage *storage, - const gchar *udi); -gboolean tracker_storage_udi_get_is_mounted (TrackerStorage *storage, - const gchar *udi); -gboolean tracker_storage_uri_is_on_removable_device (TrackerStorage *storage, - const gchar *uri, - gchar **mount_point, - gboolean *available); -const gchar* tracker_storage_get_volume_udi_for_file (TrackerStorage *storage, - GFile *file); - -#endif /* HAVE_HAL */ +GType tracker_storage_get_type (void) G_GNUC_CONST; +TrackerStorage *tracker_storage_new (void); +GSList * tracker_storage_get_removable_device_roots (TrackerStorage *storage); +GSList * tracker_storage_get_removable_device_uuids (TrackerStorage *storage); +const gchar * tracker_storage_get_mount_point_for_uuid (TrackerStorage *storage, + const gchar *uuid); +const gchar* tracker_storage_get_uuid_for_file (TrackerStorage *storage, + GFile *file); G_END_DECLS -#endif /* __LIBTRACKER_COMMON_STORAGE_H__ */ +#endif /* __LIBTRACKER_MINER_STORAGE_H__ */ diff --git a/src/tracker-extract/Makefile.am b/src/tracker-extract/Makefile.am index 6da01062b..1f6f5d99d 100644 --- a/src/tracker-extract/Makefile.am +++ b/src/tracker-extract/Makefile.am @@ -329,6 +329,7 @@ tracker_extract_SOURCES = \ tracker_extract_LDADD = \ $(top_builddir)/src/libtracker-client/libtracker-client-@TRACKER_API_VERSION@.la \ + $(top_builddir)/src/libtracker-miner/libtracker-miner-@TRACKER_API_VERSION@.la \ $(top_builddir)/src/libtracker-common/libtracker-common.la \ $(DBUS_LIBS) \ $(GMODULE_LIBS) \ diff --git a/src/tracker-extract/tracker-albumart.c b/src/tracker-extract/tracker-albumart.c index ec4fbbcdd..35cd6bde7 100644 --- a/src/tracker-extract/tracker-albumart.c +++ b/src/tracker-extract/tracker-albumart.c @@ -33,7 +33,7 @@ #include <dbus/dbus-glib-bindings.h> -#include <libtracker-common/tracker-storage.h> +#include <libtracker-miner/tracker-storage.h> #include "tracker-albumart.h" #include "tracker-dbus.h" @@ -46,7 +46,7 @@ #define ALBUMARTER_INTERFACE "com.nokia.albumart.Requester" typedef struct { - TrackerStorage *hal; + TrackerStorage *storage; gchar *art_path; gchar *local_uri; } GetFileInfo; @@ -548,7 +548,7 @@ albumart_set (const unsigned char *buffer, } static void -albumart_request_download (TrackerStorage *hal, +albumart_request_download (TrackerStorage *storage, const gchar *album, const gchar *artist, const gchar *local_uri, @@ -562,11 +562,7 @@ albumart_request_download (TrackerStorage *hal, info = g_slice_new (GetFileInfo); -#ifdef HAVE_HAL - info->hal = hal ? g_object_ref (hal) : NULL; -#else - info->hal = NULL; -#endif + info->storage = storage ? g_object_ref (storage) : NULL; info->local_uri = g_strdup (local_uri); info->art_path = g_strdup (art_path); @@ -600,7 +596,7 @@ albumart_request_download (TrackerStorage *hal, } static void -albumart_copy_to_local (TrackerStorage *hal, +albumart_copy_to_local (TrackerStorage *storage, const gchar *filename, const gchar *local_uri) { @@ -609,8 +605,7 @@ albumart_copy_to_local (TrackerStorage *hal, guint flen; /* Determining if we are on a removable device */ -#ifdef HAVE_HAL - if (!hal) { + if (!storage) { /* This is usually because we are running on the * command line, so we don't error here with * g_return_if_fail(). @@ -618,11 +613,7 @@ albumart_copy_to_local (TrackerStorage *hal, return; } - removable_roots = tracker_storage_get_removable_device_roots (hal); -#else - removable_roots = g_slist_append (removable_roots, "/media"); - removable_roots = g_slist_append (removable_roots, "/mnt"); -#endif + removable_roots = tracker_storage_get_removable_device_roots (storage); flen = strlen (filename); @@ -637,10 +628,7 @@ albumart_copy_to_local (TrackerStorage *hal, } } -#ifdef HAVE_HAL g_slist_foreach (removable_roots, (GFunc) g_free, NULL); -#endif - g_slist_free (removable_roots); if (on_removable_device) { @@ -697,10 +685,10 @@ albumart_queue_cb (DBusGProxy *proxy, g_clear_error (&error); } - if (info->hal && info->art_path && + if (info->storage && info->art_path && g_file_test (info->art_path, G_FILE_TEST_EXISTS)) { - albumart_copy_to_local (info->hal, + albumart_copy_to_local (info->storage, info->art_path, info->local_uri); } @@ -708,8 +696,8 @@ albumart_queue_cb (DBusGProxy *proxy, g_free (info->art_path); g_free (info->local_uri); - if (info->hal) { - g_object_unref (info->hal); + if (info->storage) { + g_object_unref (info->storage); } g_slice_free (GetFileInfo, info); @@ -723,11 +711,7 @@ tracker_albumart_init (void) g_return_val_if_fail (initialized == FALSE, FALSE); -#ifdef HAVE_HAL albumart_storage = tracker_storage_new (); -#else /* HAVE_HAL */ - albumart_storage = NULL; -#endif /* HAVE_HAL */ /* Cache to know if we have already handled uris */ albumart_cache = g_hash_table_new_full (g_str_hash, @@ -769,11 +753,9 @@ tracker_albumart_shutdown (void) g_hash_table_unref (albumart_cache); } -#ifdef HAVE_HAL if (albumart_storage) { g_object_unref (albumart_storage); } -#endif /* HAVE_HAL */ initialized = FALSE; } diff --git a/src/tracker-miner-fs/tracker-miner-files.c b/src/tracker-miner-fs/tracker-miner-files.c index d88645835..fd7080daa 100644 --- a/src/tracker-miner-fs/tracker-miner-files.c +++ b/src/tracker-miner-fs/tracker-miner-files.c @@ -31,11 +31,11 @@ #include <libtracker-common/tracker-date-time.h> #include <libtracker-common/tracker-ontologies.h> #include <libtracker-common/tracker-power.h> -#include <libtracker-common/tracker-storage.h> #include <libtracker-common/tracker-type-utils.h> #include <libtracker-common/tracker-utils.h> #include <libtracker-miner/tracker-miner.h> +#include <libtracker-miner/tracker-storage.h> #include "tracker-miner-files.h" #include "tracker-config.h" @@ -75,7 +75,7 @@ struct TrackerMinerFilesPrivate { DBusGProxy *extractor_proxy; - GQuark quark_mount_point_udi; + GQuark quark_mount_point_uuid; GQuark quark_directory_config_root; }; @@ -103,20 +103,18 @@ static void mount_pre_unmount_cb (GVolumeMonitor *v GMount *mount, TrackerMinerFiles *mf); -#ifdef HAVE_HAL static void mount_point_added_cb (TrackerStorage *storage, - const gchar *udi, + const gchar *uuid, const gchar *mount_point, gpointer user_data); static void mount_point_removed_cb (TrackerStorage *storage, - const gchar *udi, + const gchar *uuid, const gchar *mount_point, gpointer user_data); static void check_battery_status (TrackerMinerFiles *fs); static void battery_status_cb (GObject *object, GParamSpec *pspec, gpointer user_data); -#endif static void init_mount_points (TrackerMinerFiles *miner); static void disk_space_check_start (TrackerMinerFiles *mf); @@ -189,7 +187,6 @@ tracker_miner_files_init (TrackerMinerFiles *mf) priv = mf->private = TRACKER_MINER_FILES_GET_PRIVATE (mf); -#ifdef HAVE_HAL priv->storage = tracker_storage_new (); g_signal_connect (priv->storage, "mount-point-added", @@ -200,6 +197,7 @@ tracker_miner_files_init (TrackerMinerFiles *mf) G_CALLBACK (mount_point_removed_cb), mf); +#ifdef HAVE_HAL priv->power = tracker_power_new (); g_signal_connect (priv->power, "notify::on-low-battery", @@ -218,7 +216,7 @@ tracker_miner_files_init (TrackerMinerFiles *mf) /* Set up extractor and signals */ priv->extractor_proxy = extractor_create_proxy (); - priv->quark_mount_point_udi = g_quark_from_static_string ("tracker-mount-point-udi"); + priv->quark_mount_point_uuid = g_quark_from_static_string ("tracker-mount-point-uuid"); priv->quark_directory_config_root = g_quark_from_static_string ("tracker-directory-config-root"); init_mount_points (mf); @@ -295,9 +293,10 @@ miner_files_finalize (GObject *object) #ifdef HAVE_HAL g_object_unref (priv->power); - g_object_unref (priv->storage); #endif /* HAVE_HAL */ + g_object_unref (priv->storage); + g_signal_handlers_disconnect_by_func (priv->volume_monitor, mount_pre_unmount_cb, object); @@ -324,11 +323,11 @@ miner_files_constructed (GObject *object) g_assert_not_reached (); } -#ifdef HAVE_HAL if (tracker_config_get_index_removable_devices (mf->private->config)) { mounts = tracker_storage_get_removable_device_roots (mf->private->storage); } +#ifdef HAVE_HAL check_battery_status (mf); #endif /* HAVE_HAL */ @@ -434,15 +433,12 @@ miner_files_constructed (GObject *object) for (m = mounts; m; m = m->next) { GFile *file = g_file_new_for_path (m->data); -#ifdef HAVE_HAL - const gchar *udi = tracker_storage_get_volume_udi_for_file (mf->private->storage, file); + const gchar *uuid = tracker_storage_get_uuid_for_file (mf->private->storage, file); g_object_set_qdata_full (G_OBJECT (file), - mf->private->quark_mount_point_udi, - g_strdup (udi), + mf->private->quark_mount_point_uuid, + g_strdup (uuid), (GDestroyNotify) g_free); -#endif - g_object_set_qdata (G_OBJECT (file), mf->private->quark_directory_config_root, GINT_TO_POINTER (TRUE)); @@ -610,9 +606,7 @@ query_mount_points_cb (GObject *source, gint i; GError *error = NULL; const GPtrArray *query_results; -#ifdef HAVE_HAL - GSList *udis, *u; -#endif + GSList *uuids, *u; query_results = tracker_miner_execute_sparql_finish (miner, result, @@ -647,17 +641,16 @@ query_mount_points_cb (GObject *source, g_hash_table_replace (volumes, g_strdup (TRACKER_NON_REMOVABLE_MEDIA_DATASOURCE_URN), GINT_TO_POINTER (VOLUME_MOUNTED)); -#ifdef HAVE_HAL - udis = tracker_storage_get_removable_device_udis (priv->storage); + uuids = tracker_storage_get_removable_device_uuids (priv->storage); /* Then, get all currently mounted volumes, according to HAL */ - for (u = udis; u; u = u->next) { - const gchar *udi; + for (u = uuids; u; u = u->next) { + const gchar *uuid; gchar *removable_device_urn; gint state; - udi = u->data; - removable_device_urn = g_strdup_printf (TRACKER_DATASOURCE_URN_PREFIX "%s", udi); + uuid = u->data; + removable_device_urn = g_strdup_printf (TRACKER_DATASOURCE_URN_PREFIX "%s", uuid); state = GPOINTER_TO_INT (g_hash_table_lookup (volumes, removable_device_urn)); state |= VOLUME_MOUNTED; @@ -665,9 +658,8 @@ query_mount_points_cb (GObject *source, g_hash_table_replace (volumes, removable_device_urn, GINT_TO_POINTER (state)); } - g_slist_foreach (udis, (GFunc) g_free, NULL); - g_slist_free (udis); -#endif + g_slist_foreach (uuids, (GFunc) g_free, NULL); + g_slist_free (uuids); accumulator = g_string_new (NULL); g_hash_table_iter_init (&iter, volumes); @@ -681,14 +673,12 @@ query_mount_points_cb (GObject *source, !(state & VOLUME_MOUNTED_IN_STORE)) { const gchar *mount_point = NULL; -#ifdef HAVE_HAL if (g_str_has_prefix (urn, TRACKER_DATASOURCE_URN_PREFIX)) { - const gchar *udi; + const gchar *uuid; - udi = urn + strlen (TRACKER_DATASOURCE_URN_PREFIX); - mount_point = tracker_storage_udi_get_mount_point (priv->storage, udi); + uuid = urn + strlen (TRACKER_DATASOURCE_URN_PREFIX); + mount_point = tracker_storage_get_mount_point_for_uuid (priv->storage, uuid); } -#endif if (urn) { if (mount_point) { @@ -733,11 +723,9 @@ init_mount_points (TrackerMinerFiles *miner) NULL); } -#ifdef HAVE_HAL - static void mount_point_removed_cb (TrackerStorage *storage, - const gchar *udi, + const gchar *uuid, const gchar *mount_point, gpointer user_data) { @@ -746,7 +734,7 @@ mount_point_removed_cb (TrackerStorage *storage, g_debug ("Removing mount point '%s'", mount_point); - urn = g_strdup_printf (TRACKER_DATASOURCE_URN_PREFIX "%s", udi); + urn = g_strdup_printf (TRACKER_DATASOURCE_URN_PREFIX "%s", uuid); set_up_mount_point (miner, urn, mount_point, FALSE, NULL); g_free (urn); @@ -754,7 +742,7 @@ mount_point_removed_cb (TrackerStorage *storage, static void mount_point_added_cb (TrackerStorage *storage, - const gchar *udi, + const gchar *uuid, const gchar *mount_point, gpointer user_data) { @@ -772,8 +760,8 @@ mount_point_added_cb (TrackerStorage *storage, file = g_file_new_for_path (mount_point); g_object_set_qdata_full (G_OBJECT (file), - priv->quark_mount_point_udi, - g_strdup (udi), + priv->quark_mount_point_uuid, + g_strdup (uuid), (GDestroyNotify) g_free); g_object_set_qdata (G_OBJECT (file), @@ -788,12 +776,14 @@ mount_point_added_cb (TrackerStorage *storage, g_debug ("Configuring added mount point '%s'", mount_point); - urn = g_strdup_printf (TRACKER_DATASOURCE_URN_PREFIX "%s", udi); + urn = g_strdup_printf (TRACKER_DATASOURCE_URN_PREFIX "%s", uuid); set_up_mount_point (miner, urn, mount_point, TRUE, NULL); g_free (urn); } +#ifdef HAVE_HAL + static void set_up_throttle (TrackerMinerFiles *mf, gboolean enable) @@ -1366,7 +1356,7 @@ miner_files_add_to_datasource (TrackerMinerFiles *mf, TrackerSparqlBuilder *sparql) { TrackerMinerFilesPrivate *priv; - const gchar *removable_device_udi; + const gchar *removable_device_uuid; gchar *removable_device_urn, *uri; const gchar *urn; gboolean is_iri; @@ -1374,15 +1364,11 @@ miner_files_add_to_datasource (TrackerMinerFiles *mf, priv = TRACKER_MINER_FILES_GET_PRIVATE (mf); uri = g_file_get_uri (file); -#ifdef HAVE_HAL - removable_device_udi = tracker_storage_get_volume_udi_for_file (priv->storage, file); -#else /* HAVE_HAL */ - removable_device_udi = NULL; -#endif /* HAVE_HAL */ + removable_device_uuid = tracker_storage_get_uuid_for_file (priv->storage, file); - if (removable_device_udi) { + if (removable_device_uuid) { removable_device_urn = g_strdup_printf (TRACKER_DATASOURCE_URN_PREFIX "%s", - removable_device_udi); + removable_device_uuid); } else { removable_device_urn = g_strdup (TRACKER_NON_REMOVABLE_MEDIA_DATASOURCE_URN); } @@ -1456,7 +1442,7 @@ extractor_get_embedded_metadata_cb (DBusGProxy *proxy, { TrackerMinerFilesPrivate *priv; ProcessFileData *data = user_data; - const gchar *udi; + const gchar *uuid; priv = TRACKER_MINER_FILES_GET_PRIVATE (data->miner); @@ -1494,15 +1480,15 @@ extractor_get_embedded_metadata_cb (DBusGProxy *proxy, tracker_sparql_builder_prepend (data->sparql, preupdate); } - udi = g_object_get_qdata (G_OBJECT (data->file), - data->miner->private->quark_mount_point_udi); + uuid = g_object_get_qdata (G_OBJECT (data->file), + data->miner->private->quark_mount_point_uuid); /* File represents a mount point */ - if (G_UNLIKELY (udi)) { + if (G_UNLIKELY (uuid)) { GString *queries; gchar *removable_device_urn, *uri; - removable_device_urn = g_strdup_printf (TRACKER_DATASOURCE_URN_PREFIX "%s", udi); + removable_device_urn = g_strdup_printf (TRACKER_DATASOURCE_URN_PREFIX "%s", uuid); uri = g_file_get_uri (G_FILE (data->file)); queries = g_string_new (""); |