From 1199ba5797a52cd895b83934b368f845c854618d Mon Sep 17 00:00:00 2001 From: Martyn Russell Date: Tue, 23 Feb 2010 09:54:39 +0000 Subject: libtracker-miner: Moved tracker-storage here from libtracker-common --- src/libtracker-miner/tracker-storage.c | 1167 ++++++++++++++++++++++++++++++++ src/libtracker-miner/tracker-storage.h | 72 ++ 2 files changed, 1239 insertions(+) create mode 100644 src/libtracker-miner/tracker-storage.c create mode 100644 src/libtracker-miner/tracker-storage.h diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c new file mode 100644 index 0000000..430d5d6 --- /dev/null +++ b/src/libtracker-miner/tracker-storage.c @@ -0,0 +1,1167 @@ +/* + * 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 + +#include + +#include +#include + +#include + +#include + +#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/tracker-storage.h b/src/libtracker-miner/tracker-storage.h new file mode 100644 index 0000000..f7e5b0f --- /dev/null +++ b/src/libtracker-miner/tracker-storage.h @@ -0,0 +1,72 @@ +/* + * 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. + */ + +#ifndef __LIBTRACKER_COMMON_STORAGE_H__ +#define __LIBTRACKER_COMMON_STORAGE_H__ + +#include +#include + +G_BEGIN_DECLS + +#if !defined (__LIBTRACKER_COMMON_INSIDE__) && !defined (TRACKER_COMPILATION) +#error "only 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)) +#define TRACKER_IS_STORAGE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_STORAGE)) +#define TRACKER_IS_STORAGE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TRACKER_TYPE_STORAGE)) +#define TRACKER_STORAGE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_STORAGE, TrackerStorageClass)) + +typedef struct _TrackerStorage TrackerStorage; +typedef struct _TrackerStorageClass TrackerStorageClass; + +struct _TrackerStorage { + GObject parent; +}; + +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 */ + +G_END_DECLS + +#endif /* __LIBTRACKER_COMMON_STORAGE_H__ */ -- cgit v1.2.1 From 1692c8425bda9235ea8ec746d5681571d70a58ae Mon Sep 17 00:00:00 2001 From: Martyn Russell Date: Tue, 23 Feb 2010 10:38:07 +0000 Subject: libtracker-miner: Removed unused storage functions --- src/libtracker-miner/tracker-storage.c | 206 ++++++--------------------------- src/libtracker-miner/tracker-storage.h | 24 ++-- 2 files changed, 40 insertions(+), 190 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index 430d5d6..4dd0b6d 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -20,8 +20,6 @@ #include "config.h" -#ifdef HAVE_HAL - #include #include @@ -41,7 +39,7 @@ #define PROP_IS_MOUNTED "volume.is_mounted" -#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_STORAGE, TrackerStoragePriv)) +#define TRACKER_STORAGE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_STORAGE, TrackerStoragePrivate)) typedef struct { LibHalContext *context; @@ -51,8 +49,7 @@ typedef struct { GNode *mounts; GHashTable *mounts_by_udi; - -} TrackerStoragePriv; +} TrackerStoragePrivate; typedef struct { gchar *mount_point; @@ -138,18 +135,18 @@ tracker_storage_class_init (TrackerStorageClass *klass) G_TYPE_STRING, G_TYPE_STRING); - g_type_class_add_private (object_class, sizeof (TrackerStoragePriv)); + g_type_class_add_private (object_class, sizeof (TrackerStoragePrivate)); } static void tracker_storage_init (TrackerStorage *storage) { - TrackerStoragePriv *priv; + TrackerStoragePrivate *priv; DBusError error; g_message ("Initializing HAL Storage..."); - priv = GET_PRIV (storage); + priv = TRACKER_STORAGE_GET_PRIVATE (storage); priv->all_devices = g_hash_table_new_full (g_str_hash, g_str_equal, @@ -248,9 +245,9 @@ free_mount_node (GNode *node) static void tracker_storage_finalize (GObject *object) { - TrackerStoragePriv *priv; + TrackerStoragePrivate *priv; - priv = GET_PRIV (object); + priv = TRACKER_STORAGE_GET_PRIVATE (object); if (priv->mounts_by_udi) { g_hash_table_unref (priv->mounts_by_udi); @@ -283,9 +280,9 @@ hal_get_property (GObject *object, GValue *value, GParamSpec *pspec) { - TrackerStoragePriv *priv; + TrackerStoragePrivate *priv; - priv = GET_PRIV (object); + priv = TRACKER_STORAGE_GET_PRIVATE (object); switch (param_id) { default: @@ -297,12 +294,12 @@ hal_get_property (GObject *object, static gboolean hal_setup_devices (TrackerStorage *storage) { - TrackerStoragePriv *priv; + TrackerStoragePrivate *priv; DBusError error; gchar **devices, **p; gint num; - priv = GET_PRIV (storage); + priv = TRACKER_STORAGE_GET_PRIVATE (storage); dbus_error_init (&error); @@ -442,10 +439,10 @@ hal_mount_point_add (TrackerStorage *storage, const gchar *mount_point, gboolean removable_device) { - TrackerStoragePriv *priv; + TrackerStoragePrivate *priv; GNode *node; - priv = GET_PRIV (storage); + priv = TRACKER_STORAGE_GET_PRIVATE (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), @@ -463,10 +460,10 @@ hal_mount_point_remove (TrackerStorage *storage, const gchar *udi) { MountInfo *info; - TrackerStoragePriv *priv; + TrackerStoragePrivate *priv; GNode *node; - priv = GET_PRIV (storage); + priv = TRACKER_STORAGE_GET_PRIVATE (storage); node = g_hash_table_lookup (priv->mounts_by_udi, udi); @@ -532,7 +529,7 @@ hal_device_is_user_removable (TrackerStorage *storage, const gchar *device_file, const gchar *mount_point) { - TrackerStoragePriv *priv; + TrackerStoragePrivate *priv; LibHalDrive *drive; gboolean removable; @@ -540,7 +537,7 @@ hal_device_is_user_removable (TrackerStorage *storage, return FALSE; } - priv = GET_PRIV (storage); + priv = TRACKER_STORAGE_GET_PRIVATE (storage); drive = libhal_drive_from_device_file (priv->context, device_file); if (!drive) { @@ -569,7 +566,7 @@ static gboolean hal_device_should_be_tracked (TrackerStorage *storage, const gchar *device_file) { - TrackerStoragePriv *priv; + TrackerStoragePrivate *priv; LibHalDrive *drive; LibHalDriveType drive_type; gboolean eligible; @@ -578,7 +575,7 @@ hal_device_should_be_tracked (TrackerStorage *storage, return FALSE; } - priv = GET_PRIV (storage); + priv = TRACKER_STORAGE_GET_PRIVATE (storage); drive = libhal_drive_from_device_file (priv->context, device_file); if (!drive) { @@ -636,13 +633,13 @@ static gboolean hal_device_add (TrackerStorage *storage, LibHalVolume *volume) { - TrackerStoragePriv *priv; + TrackerStoragePrivate *priv; DBusError error; const gchar *udi; const gchar *mount_point; const gchar *device_file; - priv = GET_PRIV (storage); + priv = TRACKER_STORAGE_GET_PRIVATE (storage); dbus_error_init (&error); @@ -727,11 +724,11 @@ hal_device_removed_cb (LibHalContext *context, const gchar *udi) { TrackerStorage *storage; - TrackerStoragePriv *priv; + TrackerStoragePrivate *priv; const gchar *device_file; storage = libhal_ctx_get_user_data (context); - priv = GET_PRIV (storage); + priv = TRACKER_STORAGE_GET_PRIVATE (storage); if (g_hash_table_lookup (priv->all_devices, udi)) { device_file = g_hash_table_lookup (priv->all_devices, udi); @@ -760,11 +757,11 @@ hal_device_property_modified_cb (LibHalContext *context, dbus_bool_t is_added) { TrackerStorage *storage; - TrackerStoragePriv *priv; + TrackerStoragePrivate *priv; DBusError error; storage = libhal_ctx_get_user_data (context); - priv = GET_PRIV (storage); + priv = TRACKER_STORAGE_GET_PRIVATE (storage); dbus_error_init (&error); @@ -871,39 +868,6 @@ hal_get_mount_point_by_udi_foreach (gpointer key, } } -/** - * 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 @@ -919,12 +883,12 @@ tracker_storage_get_mounted_directory_roots (TrackerStorage *storage) GSList * tracker_storage_get_removable_device_roots (TrackerStorage *storage) { - TrackerStoragePriv *priv; + TrackerStoragePrivate *priv; GetRoots gr; g_return_val_if_fail (TRACKER_IS_STORAGE (storage), NULL); - priv = GET_PRIV (storage); + priv = TRACKER_STORAGE_GET_PRIVATE (storage); gr.context = priv->context; gr.roots = NULL; @@ -937,70 +901,6 @@ tracker_storage_get_removable_device_roots (TrackerStorage *storage) 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 @@ -1014,14 +914,14 @@ tracker_storage_uri_is_on_removable_device (TrackerStorage *storage, GSList * tracker_storage_get_removable_device_udis (TrackerStorage *storage) { - TrackerStoragePriv *priv; + TrackerStoragePrivate *priv; GHashTableIter iter; gpointer key, value; GSList *udis; g_return_val_if_fail (TRACKER_IS_STORAGE (storage), NULL); - priv = GET_PRIV (storage); + priv = TRACKER_STORAGE_GET_PRIVATE (storage); udis = NULL; @@ -1055,14 +955,14 @@ const gchar * tracker_storage_udi_get_mount_point (TrackerStorage *storage, const gchar *udi) { - TrackerStoragePriv *priv; + TrackerStoragePrivate *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); + priv = TRACKER_STORAGE_GET_PRIVATE (storage); node = g_hash_table_lookup (priv->mounts_by_udi, udi); @@ -1074,44 +974,6 @@ tracker_storage_udi_get_mount_point (TrackerStorage *storage, 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 @@ -1125,7 +987,7 @@ const gchar * tracker_storage_get_volume_udi_for_file (TrackerStorage *storage, GFile *file) { - TrackerStoragePriv *priv; + TrackerStoragePrivate *priv; gchar *path; MountInfo *info; @@ -1146,8 +1008,7 @@ tracker_storage_get_volume_udi_for_file (TrackerStorage *storage, path = norm_path; } - - priv = GET_PRIV (storage); + priv = TRACKER_STORAGE_GET_PRIVATE (storage); info = find_mount_point_info (priv->mounts, path); @@ -1164,4 +1025,3 @@ tracker_storage_get_volume_udi_for_file (TrackerStorage *storage, return info->udi; } -#endif /* HAVE_HAL */ diff --git a/src/libtracker-miner/tracker-storage.h b/src/libtracker-miner/tracker-storage.h index f7e5b0f..4a113bd 100644 --- a/src/libtracker-miner/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 #include G_BEGIN_DECLS -#if !defined (__LIBTRACKER_COMMON_INSIDE__) && !defined (TRACKER_COMPILATION) -#error "only 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,20 @@ 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); + + +/* Needed */ 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 */ + G_END_DECLS -#endif /* __LIBTRACKER_COMMON_STORAGE_H__ */ +#endif /* __LIBTRACKER_MINER_STORAGE_H__ */ -- cgit v1.2.1 From 636016201af5243f63b73cc09edf45327fac831a Mon Sep 17 00:00:00 2001 From: Martyn Russell Date: Tue, 23 Feb 2010 15:43:42 +0000 Subject: libtracker-miner: Reimplemented tracker-store using GIO removing HAL. --- src/libtracker-miner/tracker-storage.c | 873 +++++++++++---------------------- src/libtracker-miner/tracker-storage.h | 21 +- 2 files changed, 295 insertions(+), 599 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index 4dd0b6d..8be8c0a 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -1,5 +1,4 @@ /* - * 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 @@ -24,36 +23,24 @@ #include -#include -#include - -#include - #include #include "tracker-storage.h" #include "tracker-utils.h" #include "tracker-marshal.h" -#define CAPABILITY_VOLUME "volume" - -#define PROP_IS_MOUNTED "volume.is_mounted" - #define TRACKER_STORAGE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_STORAGE, TrackerStoragePrivate)) typedef struct { - LibHalContext *context; - DBusConnection *connection; - - GHashTable *all_devices; + GVolumeMonitor *volume_monitor; GNode *mounts; - GHashTable *mounts_by_udi; + GHashTable *mounts_by_uuid; } TrackerStoragePrivate; typedef struct { gchar *mount_point; - gchar *udi; + gchar *uuid; guint removable : 1; } MountInfo; @@ -63,33 +50,24 @@ typedef struct { } 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, -}; +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, @@ -109,7 +87,6 @@ tracker_storage_class_init (TrackerStorageClass *klass) 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", @@ -142,106 +119,38 @@ static void tracker_storage_init (TrackerStorage *storage) { TrackerStoragePrivate *priv; - DBusError error; - g_message ("Initializing HAL Storage..."); + g_message ("Initializing Storage..."); priv = TRACKER_STORAGE_GET_PRIVATE (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; - } + 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_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); + 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 (!hal_setup_devices (storage)) { + if (!drives_setup (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) { @@ -249,112 +158,37 @@ tracker_storage_finalize (GObject *object) priv = TRACKER_STORAGE_GET_PRIVATE (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_by_uuid) { + g_hash_table_unref (priv->mounts_by_uuid); } 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); + mount_node_free (priv->mounts); } - if (priv->connection) { - dbus_connection_unref (priv->connection); + if (priv->volume_monitor) { + g_object_unref (priv->volume_monitor); } (G_OBJECT_CLASS (tracker_storage_parent_class)->finalize) (object); } static void -hal_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) +mount_node_free (GNode *node) { - TrackerStoragePrivate *priv; - - priv = TRACKER_STORAGE_GET_PRIVATE (object); - - switch (param_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - }; -} - -static gboolean -hal_setup_devices (TrackerStorage *storage) -{ - TrackerStoragePrivate *priv; - DBusError error; - gchar **devices, **p; - gint num; - - priv = TRACKER_STORAGE_GET_PRIVATE (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); + g_node_traverse (node, + G_POST_ORDER, + G_TRAVERSE_ALL, + -1, + mount_info_free, + NULL); - return TRUE; + g_node_destroy (node); } static gboolean -mount_point_traverse_func (GNode *node, - gpointer user_data) +mount_node_traverse_func (GNode *node, + gpointer user_data) { TraverseData *data; MountInfo *info; @@ -376,8 +210,8 @@ mount_point_traverse_func (GNode *node, } static GNode * -find_mount_point (GNode *root, - const gchar *path) +mount_node_find (GNode *root, + const gchar *path) { TraverseData data = { path, NULL }; @@ -385,30 +219,43 @@ find_mount_point (GNode *root, G_POST_ORDER, G_TRAVERSE_ALL, -1, - mount_point_traverse_func, + 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 * -find_mount_point_info (GNode *root, - const gchar *path) +mount_info_find (GNode *root, + const gchar *path) { GNode *node; - node = find_mount_point (root, path); + node = mount_node_find (root, path); return (node) ? node->data : NULL; } -static GNode * -mount_point_hierarchy_add (GNode *root, - const gchar *mount_point, - const gchar *udi, - gboolean removable) +static gchar * +mount_point_normalize (const gchar *mount_point) { - MountInfo *info; - GNode *node; gchar *mp; /* Normalize all mount points to have a / at the end */ @@ -418,7 +265,21 @@ mount_point_hierarchy_add (GNode *root, mp = g_strconcat (mount_point, G_DIR_SEPARATOR_S, NULL); } - node = find_mount_point (root, mp); + 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; @@ -426,402 +287,241 @@ mount_point_hierarchy_add (GNode *root, info = g_slice_new (MountInfo); info->mount_point = mp; - info->udi = g_strdup (udi); + info->uuid = g_strdup (uuid); 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) +mount_add (TrackerStorage *storage, + const gchar *uuid, + const gchar *mount_point, + gboolean removable_device) { TrackerStoragePrivate *priv; GNode *node; priv = TRACKER_STORAGE_GET_PRIVATE (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); + 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, udi, mount_point, NULL); + g_signal_emit (storage, signals[MOUNT_POINT_ADDED], 0, uuid, mount_point, NULL); } static void -hal_mount_point_remove (TrackerStorage *storage, - const gchar *udi) +volume_add (TrackerStorage *storage, + GVolume *volume) { - MountInfo *info; TrackerStoragePrivate *priv; - GNode *node; + GDrive *drive; + GMount *mount; + gchar *str; + gboolean is_mounted; + gchar *uuid; + gchar *mount_point; + gchar *device_file; - priv = TRACKER_STORAGE_GET_PRIVATE (storage); + drive = g_volume_get_drive (volume); - node = g_hash_table_lookup (priv->mounts_by_udi, udi); + g_debug ("Drive:'%s' added 1 volume:", + g_drive_get_name (drive)); - if (!node) { + 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; } - 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) -{ - TrackerStoragePrivate *priv; - LibHalDrive *drive; - gboolean removable; - - if (!device_file) { - return FALSE; - } - + device_file = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); + g_debug (" Device file : %s", device_file); + + /* mounted, so never NULL */ + 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); - 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; - } + if (mount_point && !g_hash_table_lookup (priv->mounts_by_uuid, uuid)) { + mount_add (storage, uuid, mount_point, TRUE); } - - libhal_drive_free (drive); - - return removable; + + g_free (uuid); + g_free (mount_point); + g_free (device_file); } static gboolean -hal_device_should_be_tracked (TrackerStorage *storage, - const gchar *device_file) +drives_setup (TrackerStorage *storage) { TrackerStoragePrivate *priv; - LibHalDrive *drive; - LibHalDriveType drive_type; - gboolean eligible; - - if (!device_file) { - return FALSE; - } + GList *drives, *ld; priv = TRACKER_STORAGE_GET_PRIVATE (storage); - drive = libhal_drive_from_device_file (priv->context, device_file); - if (!drive) { - return FALSE; - } + drives = g_volume_monitor_get_connected_drives (priv->volume_monitor); - /* 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)); + if (g_list_length (drives) < 1) { + g_message ("No drives found to iterate"); + return TRUE; } - return eligible; -} + for (ld = drives; ld; ld = ld->next) { + GDrive *drive; + GList *volumes, *lv; + guint n_volumes; -static gboolean -hal_device_add (TrackerStorage *storage, - LibHalVolume *volume) -{ - TrackerStoragePrivate *priv; - DBusError error; - const gchar *udi; - const gchar *mount_point; - const gchar *device_file; - - priv = TRACKER_STORAGE_GET_PRIVATE (storage); + drive = ld->data; - 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 (!drive) { + continue; + } + + volumes = g_drive_get_volumes (drive); + n_volumes = g_list_length (volumes); - /* If there is no mount point, then there is nothing to track */ - if (!hal_device_should_be_tracked (storage, device_file)) { - return TRUE; - } + g_debug ("Drive:'%s' found with %d %s:", + g_drive_get_name (drive), + n_volumes, + n_volumes == 1 ? "volume" : "volumes"); - /* Make sure we watch changes to the mount/umount state */ - libhal_device_add_property_watch (priv->context, udi, &error); + for (lv = volumes; lv; lv = lv->next) { + volume_add (storage, lv->data); + } - 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_list_free (volumes); + g_object_unref (ld->data); } - 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)); - } + g_list_free (drives); return TRUE; } static void -hal_device_added_cb (LibHalContext *context, - const gchar *udi) +mount_added_cb (GVolumeMonitor *monitor, + GMount *mount, + gpointer user_data) { 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; - TrackerStoragePrivate *priv; - const gchar *device_file; + GVolume *volume; + GFile *file; + gchar *device_file; + gchar *uuid; + gchar *mount_point; + gboolean removable_device = TRUE; - storage = libhal_ctx_get_user_data (context); - priv = TRACKER_STORAGE_GET_PRIVATE (storage); + storage = user_data; - if (g_hash_table_lookup (priv->all_devices, udi)) { - device_file = g_hash_table_lookup (priv->all_devices, udi); + volume = g_mount_get_volume (mount); + device_file = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); + uuid = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UUID); + file = g_mount_get_root (mount); + mount_point = g_file_get_path (file); - if (!device_file) { - /* Don't report about unknown devices */ - return; - } + /* NOTE: We only deal with removable devices */ + removable_device = TRUE; - g_message ("HAL device:'%s' removed:", - device_file); - g_message (" UDI : %s", - udi); + g_message ("Device:'%s', UUID:'%s' now mounted on:'%s', being tracked", + device_file, + uuid, + mount_point); - g_hash_table_remove (priv->all_devices, udi); + mount_add (storage, uuid, mount_point, removable_device); - hal_mount_point_remove (storage, udi); - } + g_free (mount_point); + g_object_unref (file); + g_free (uuid); + g_free (device_file); + g_object_unref (volume); } 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) +mount_removed_cb (GVolumeMonitor *monitor, + GMount *mount, + gpointer user_data) { TrackerStorage *storage; TrackerStoragePrivate *priv; - DBusError error; + MountInfo *info; + GNode *node; + GFile *file; + gchar *name; + gchar *mount_point; + gchar *mp; - storage = libhal_ctx_get_user_data (context); + storage = user_data; priv = TRACKER_STORAGE_GET_PRIVATE (storage); - dbus_error_init (&error); + file = g_mount_get_root (mount); + mount_point = g_file_get_path (file); + name = g_mount_get_name (mount); - if (g_hash_table_lookup (priv->all_devices, udi)) { - const gchar *device_file; - gboolean is_mounted; + /* device_file = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); */ + /* uuid = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UUID); */ + /* node = g_hash_table_lookup (priv->mounts_by_uuid, uuid); */ - 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; - } + mp = mount_point_normalize (mount_point); + node = mount_node_find (priv->mounts, mp); + g_free (mp); - 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); + if (node) { + info = node->data; - g_message ("HAL device:'%s' with udi:'%s' is now mounted", - device_file, - udi); + g_message ("Mount:'%s' with UUID:'%s' now unmounted from:'%s'", + name, + info->uuid, + mount_point); - hal_mount_point_add (storage, - udi, - mount_point, - hal_device_is_user_removable (storage, device_file, 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); + } - libhal_volume_free (volume); - } else { - g_message ("HAL device:'%s' with udi:'%s' is now unmounted", - device_file, - udi); + g_free (name); + g_free (mount_point); + g_object_unref (file); + /* g_free (uuid); */ + /* g_free (device_file); */ +} - hal_mount_point_remove (storage, udi); - } - } +static void +volume_added_cb (GVolumeMonitor *monitor, + GVolume *volume, + gpointer user_data) +{ + volume_add (user_data, volume); } /** @@ -838,17 +538,17 @@ tracker_storage_new (void) } static void -hal_get_mount_point_by_udi_foreach (gpointer key, - gpointer value, - gpointer user_data) +get_mount_point_by_uuid_foreach (gpointer key, + gpointer value, + gpointer user_data) { GetRoots *gr; - const gchar *udi; + const gchar *uuid; GNode *node; MountInfo *info; gr = user_data; - udi = key; + uuid = key; node = value; info = node->data; @@ -890,102 +590,103 @@ tracker_storage_get_removable_device_roots (TrackerStorage *storage) priv = TRACKER_STORAGE_GET_PRIVATE (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, + g_hash_table_foreach (priv->mounts_by_uuid, + get_mount_point_by_uuid_foreach, &gr); return g_slist_reverse (gr.roots); } /** - * tracker_storage_get_removable_device_udis: + * tracker_storage_get_removable_device_uuids: * @storage: A #TrackerStorage * - * Returns a #GSList of strings containing the UDI for removable devices. + * 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 UDIs. + * Returns: The list of UUIDs. **/ GSList * -tracker_storage_get_removable_device_udis (TrackerStorage *storage) +tracker_storage_get_removable_device_uuids (TrackerStorage *storage) { TrackerStoragePrivate *priv; GHashTableIter iter; gpointer key, value; - GSList *udis; + GSList *uuids; g_return_val_if_fail (TRACKER_IS_STORAGE (storage), NULL); priv = TRACKER_STORAGE_GET_PRIVATE (storage); - udis = NULL; + uuids = NULL; - g_hash_table_iter_init (&iter, priv->mounts_by_udi); + g_hash_table_iter_init (&iter, priv->mounts_by_uuid); while (g_hash_table_iter_next (&iter, &key, &value)) { - const gchar *udi; + const gchar *uuid; GNode *node; MountInfo *info; - udi = key; + uuid = key; node = value; info = node->data; if (info->removable) { - udis = g_slist_prepend (udis, g_strdup (udi)); + uuids = g_slist_prepend (uuids, g_strdup (uuid)); } } - return g_slist_reverse (udis); + return g_slist_reverse (uuids); } /** - * tracker_storage_udi_get_mount_point: + * tracker_storage_get_mount_point_for_uuid: * @storage: A #TrackerStorage - * @udi: A string pointer to the UDI for the device. + * @uuid: A string pointer to the UUID for the %GVolume. * - * Returns: The mount point for @udi, this should not be freed. + * Returns: The mount point for @uuid, this should not be freed. **/ const gchar * -tracker_storage_udi_get_mount_point (TrackerStorage *storage, - const gchar *udi) +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 (udi != NULL, NULL); + g_return_val_if_fail (uuid != NULL, NULL); priv = TRACKER_STORAGE_GET_PRIVATE (storage); - node = g_hash_table_lookup (priv->mounts_by_udi, udi); + node = g_hash_table_lookup (priv->mounts_by_uuid, uuid); if (!node) { return NULL; } info = node->data; + return info->mount_point; } /** - * tracker_storage_get_volume_udi_for_file: + * tracker_storage_get_uuid_for_file: * @storage: A #TrackerStorage * @file: a file * - * Returns the UDI of the removable device for @file + * Returns the UUID of the removable device for @file * - * Returns: Returns the UDI 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_volume_udi_for_file (TrackerStorage *storage, - GFile *file) +tracker_storage_get_uuid_for_file (TrackerStorage *storage, + GFile *file) { TrackerStoragePrivate *priv; gchar *path; @@ -1010,18 +711,18 @@ tracker_storage_get_volume_udi_for_file (TrackerStorage *storage, priv = TRACKER_STORAGE_GET_PRIVATE (storage); - info = find_mount_point_info (priv->mounts, path); + info = mount_info_find (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_debug ("Mount for path '%s' is '%s' (UUID:'%s')", */ + /* path, info->mount_point, info->uuid); */ g_free (path); - return info->udi; + return info->uuid; } diff --git a/src/libtracker-miner/tracker-storage.h b/src/libtracker-miner/tracker-storage.h index 4a113bd..ee40e91 100644 --- a/src/libtracker-miner/tracker-storage.h +++ b/src/libtracker-miner/tracker-storage.h @@ -43,19 +43,14 @@ struct _TrackerStorageClass { GObjectClass parent_class; }; -GType tracker_storage_get_type (void) G_GNUC_CONST; -TrackerStorage *tracker_storage_new (void); - - -/* Needed */ -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); -const gchar* tracker_storage_get_volume_udi_for_file (TrackerStorage *storage, - GFile *file); - - +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 -- cgit v1.2.1 From bb83732aaf610d0af64a1b4183c7b59a833e3fe1 Mon Sep 17 00:00:00 2001 From: Martyn Russell Date: Tue, 23 Feb 2010 16:13:39 +0000 Subject: libtracker-miner: Don't repeat the same message when adding volumes --- src/libtracker-miner/tracker-storage.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index 8be8c0a..6f5cdee 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -312,7 +312,8 @@ mount_add (TrackerStorage *storage, static void volume_add (TrackerStorage *storage, - GVolume *volume) + GVolume *volume, + gboolean initialization) { TrackerStoragePrivate *priv; GDrive *drive; @@ -325,8 +326,10 @@ volume_add (TrackerStorage *storage, drive = g_volume_get_drive (volume); - g_debug ("Drive:'%s' added 1 volume:", - g_drive_get_name (drive)); + if (!initialization) { + g_debug ("Drive:'%s' added 1 volume:", + g_drive_get_name (drive)); + } str = g_volume_get_name (volume); g_debug (" Volume:'%s' found", str); @@ -412,7 +415,7 @@ drives_setup (TrackerStorage *storage) n_volumes == 1 ? "volume" : "volumes"); for (lv = volumes; lv; lv = lv->next) { - volume_add (storage, lv->data); + volume_add (storage, lv->data, TRUE); } g_list_free (volumes); @@ -521,7 +524,7 @@ volume_added_cb (GVolumeMonitor *monitor, GVolume *volume, gpointer user_data) { - volume_add (user_data, volume); + volume_add (user_data, volume, FALSE); } /** -- cgit v1.2.1 From dfd38954294ee0fbb5f9df5212e6b92727495ada Mon Sep 17 00:00:00 2001 From: Martyn Russell Date: Tue, 23 Feb 2010 16:14:26 +0000 Subject: libtracker-miner: Don't add mount points if the UUID is NULL --- src/libtracker-miner/tracker-storage.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index 6f5cdee..02caf75 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -456,7 +456,13 @@ mount_added_cb (GVolumeMonitor *monitor, uuid, mount_point); - mount_add (storage, uuid, mount_point, removable_device); + /* 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 (mount_point); g_object_unref (file); -- cgit v1.2.1 From aafc2f10ea0f666b4de7dbb9058632aeb0b0c01d Mon Sep 17 00:00:00 2001 From: Martyn Russell Date: Tue, 23 Feb 2010 16:14:51 +0000 Subject: libtracker-miner: Removed unused code in storage module --- src/libtracker-miner/tracker-storage.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index 02caf75..099b00f 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -492,10 +492,6 @@ mount_removed_cb (GVolumeMonitor *monitor, mount_point = g_file_get_path (file); name = g_mount_get_name (mount); - /* device_file = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); */ - /* uuid = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UUID); */ - /* node = g_hash_table_lookup (priv->mounts_by_uuid, uuid); */ - mp = mount_point_normalize (mount_point); node = mount_node_find (priv->mounts, mp); g_free (mp); @@ -521,8 +517,6 @@ mount_removed_cb (GVolumeMonitor *monitor, g_free (name); g_free (mount_point); g_object_unref (file); - /* g_free (uuid); */ - /* g_free (device_file); */ } static void -- cgit v1.2.1 From e174900ba300c914371c529211793b37e46b3a60 Mon Sep 17 00:00:00 2001 From: Martyn Russell Date: Tue, 23 Feb 2010 16:17:25 +0000 Subject: libtracker-miner: Fixed debugging for storage --- src/libtracker-miner/tracker-storage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index 099b00f..1d205d0 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -451,7 +451,7 @@ mount_added_cb (GVolumeMonitor *monitor, /* NOTE: We only deal with removable devices */ removable_device = TRUE; - g_message ("Device:'%s', UUID:'%s' now mounted on:'%s', being tracked", + g_message ("Device:'%s', UUID:'%s' now mounted on:'%s'", device_file, uuid, mount_point); -- cgit v1.2.1 From d27e502492b944ccbe8bca5dff0ffca46f6ca730 Mon Sep 17 00:00:00 2001 From: Martyn Russell Date: Tue, 23 Feb 2010 16:57:17 +0000 Subject: libtracker-miner: Removed storage bogus comment --- src/libtracker-miner/tracker-storage.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index 1d205d0..daf3106 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -344,7 +344,6 @@ volume_add (TrackerStorage *storage, device_file = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); g_debug (" Device file : %s", device_file); - /* mounted, so never NULL */ mount = g_volume_get_mount (volume); if (mount) { -- cgit v1.2.1 From 0e39fd090b3569f978ba12562e7a54ad0da0f856 Mon Sep 17 00:00:00 2001 From: Martyn Russell Date: Tue, 23 Feb 2010 16:59:27 +0000 Subject: libtracker-miner: Fixed storage memory leak iterating volumes --- src/libtracker-miner/tracker-storage.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index daf3106..8b1b5f0 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -415,6 +415,7 @@ drives_setup (TrackerStorage *storage) for (lv = volumes; lv; lv = lv->next) { volume_add (storage, lv->data, TRUE); + g_object_unref (lv->data); } g_list_free (volumes); -- cgit v1.2.1 From de38c16db39d4b61a7099c4a77c72eecb301e8a2 Mon Sep 17 00:00:00 2001 From: Martyn Russell Date: Tue, 23 Feb 2010 17:18:13 +0000 Subject: libtracker-miner: Avoid warnings for CDROMs with no GDrive/GVolume --- src/libtracker-miner/tracker-storage.c | 69 ++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 25 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index 8b1b5f0..58df351 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -316,7 +316,6 @@ volume_add (TrackerStorage *storage, gboolean initialization) { TrackerStoragePrivate *priv; - GDrive *drive; GMount *mount; gchar *str; gboolean is_mounted; @@ -324,11 +323,17 @@ volume_add (TrackerStorage *storage, gchar *mount_point; gchar *device_file; - drive = g_volume_get_drive (volume); - if (!initialization) { - g_debug ("Drive:'%s' added 1 volume:", - g_drive_get_name (drive)); + 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); @@ -435,40 +440,54 @@ mount_added_cb (GVolumeMonitor *monitor, TrackerStorage *storage; GVolume *volume; GFile *file; - gchar *device_file; - gchar *uuid; gchar *mount_point; - gboolean removable_device = TRUE; + gchar *name; storage = user_data; - volume = g_mount_get_volume (mount); - device_file = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); - uuid = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UUID); + name = g_mount_get_name (mount); file = g_mount_get_root (mount); mount_point = g_file_get_path (file); - /* NOTE: We only deal with removable devices */ - removable_device = TRUE; - - g_message ("Device:'%s', UUID:'%s' now mounted on:'%s'", - device_file, - uuid, + g_message ("Mount:'%s', now mounted on:'%s'", + name, mount_point); - /* 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); + 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 UUID"); + g_message (" Being ignored because we have no GVolume"); } g_free (mount_point); g_object_unref (file); - g_free (uuid); - g_free (device_file); - g_object_unref (volume); + g_free (name); } static void -- cgit v1.2.1 From 4001f820854b8cb8edf109569c600ce482f62ea4 Mon Sep 17 00:00:00 2001 From: Martyn Russell Date: Tue, 23 Feb 2010 17:24:07 +0000 Subject: libtracker-miner: Don't reverse lists from hash tables --- src/libtracker-miner/tracker-storage.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index 58df351..d958de4 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -619,7 +619,7 @@ tracker_storage_get_removable_device_roots (TrackerStorage *storage) get_mount_point_by_uuid_foreach, &gr); - return g_slist_reverse (gr.roots); + return gr.roots; } /** @@ -662,7 +662,7 @@ tracker_storage_get_removable_device_uuids (TrackerStorage *storage) } } - return g_slist_reverse (uuids); + return uuids; } /** -- cgit v1.2.1 From bddebe8e32b218ac561ea004effebdeb5ae1ad54 Mon Sep 17 00:00:00 2001 From: Philip Van Hoof Date: Wed, 24 Feb 2010 15:07:12 +0100 Subject: libtracker-miner: Fixed a few problems after review --- src/libtracker-miner/tracker-storage.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index d958de4..e7e1803 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -134,13 +134,13 @@ tracker_storage_init (TrackerStorage *storage) priv->volume_monitor = g_volume_monitor_get (); /* Volume and property notification callbacks */ - g_signal_connect_object (priv->volume_monitor, "mount_removed", + 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_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_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_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..."); @@ -402,7 +402,6 @@ drives_setup (TrackerStorage *storage) for (ld = drives; ld; ld = ld->next) { GDrive *drive; GList *volumes, *lv; - guint n_volumes; drive = ld->data; @@ -411,12 +410,11 @@ drives_setup (TrackerStorage *storage) } volumes = g_drive_get_volumes (drive); - n_volumes = g_list_length (volumes); g_debug ("Drive:'%s' found with %d %s:", g_drive_get_name (drive), - n_volumes, - n_volumes == 1 ? "volume" : "volumes"); + g_list_length (volumes), + g_list_length (volumes) == 1 ? "volume" : "volumes"); for (lv = volumes; lv; lv = lv->next) { volume_add (storage, lv->data, TRUE); -- cgit v1.2.1 From d73f86e2b965576821707b5ff0d0f5fdd9df46cc Mon Sep 17 00:00:00 2001 From: Philip Van Hoof Date: Wed, 24 Feb 2010 15:15:51 +0100 Subject: libtracker-miner: Small optimization --- src/libtracker-miner/tracker-storage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index e7e1803..c086d59 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -414,7 +414,7 @@ drives_setup (TrackerStorage *storage) g_debug ("Drive:'%s' found with %d %s:", g_drive_get_name (drive), g_list_length (volumes), - g_list_length (volumes) == 1 ? "volume" : "volumes"); + (volumes && !volumes->next) ? "volume" : "volumes"); for (lv = volumes; lv; lv = lv->next) { volume_add (storage, lv->data, TRUE); -- cgit v1.2.1 From e75bb96a7e145ae5d294aa26919dbdd58e192de6 Mon Sep 17 00:00:00 2001 From: Martyn Russell Date: Thu, 25 Feb 2010 16:56:14 +0000 Subject: libtracker-miner: Fixed signal string _ and - mixing --- src/libtracker-miner/tracker-storage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index c086d59..a8f971c 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -136,7 +136,7 @@ tracker_storage_init (TrackerStorage *storage) /* 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_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); -- cgit v1.2.1 From 43014e33fdd91a7f2adee5471bd2ced4cdc231a5 Mon Sep 17 00:00:00 2001 From: Martyn Russell Date: Fri, 26 Feb 2010 10:25:21 +0000 Subject: libtracker-miner: Fixed crash when starting tracker with CD/DVDs mounted --- src/libtracker-miner/tracker-storage.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index a8f971c..6b587a6 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -346,6 +346,12 @@ volume_add (TrackerStorage *storage, return; } + uuid = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UUID); + if (!uuid) { + g_debug (" Ignoring, volume has no UUID"); + return; + } + device_file = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); g_debug (" Device file : %s", device_file); @@ -368,17 +374,15 @@ volume_add (TrackerStorage *storage, 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); -- cgit v1.2.1 From e61513d360b53ad833520facd18882c867fdfda9 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Wed, 3 Mar 2010 16:09:13 +0100 Subject: Plug some leaks in libtracker-miner. --- src/libtracker-miner/tracker-storage.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index 6b587a6..31ee229 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -406,6 +406,7 @@ drives_setup (TrackerStorage *storage) for (ld = drives; ld; ld = ld->next) { GDrive *drive; GList *volumes, *lv; + gchar *name; drive = ld->data; @@ -414,9 +415,10 @@ drives_setup (TrackerStorage *storage) } volumes = g_drive_get_volumes (drive); + name = g_drive_get_name (drive); g_debug ("Drive:'%s' found with %d %s:", - g_drive_get_name (drive), + name, g_list_length (volumes), (volumes && !volumes->next) ? "volume" : "volumes"); @@ -427,6 +429,7 @@ drives_setup (TrackerStorage *storage) g_list_free (volumes); g_object_unref (ld->data); + g_free (name); } g_list_free (drives); -- cgit v1.2.1 From 33d3e9d03bbe904536a5973f137fbe0d8f3c2c1b Mon Sep 17 00:00:00 2001 From: Martyn Russell Date: Thu, 4 Mar 2010 16:35:07 +0000 Subject: Fixes GB#611556, Need to support CD/DVD index --- src/libtracker-miner/tracker-storage.c | 211 +++++++++++++++++++++++++++++---- src/libtracker-miner/tracker-storage.h | 22 ++-- 2 files changed, 200 insertions(+), 33 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index 31ee229..727bc6c 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -42,6 +42,7 @@ typedef struct { gchar *mount_point; gchar *uuid; guint removable : 1; + guint optical : 1; } MountInfo; typedef struct { @@ -51,7 +52,9 @@ typedef struct { typedef struct { GSList *roots; - gboolean only_removable; + guint either_condition : 1; + guint removable : 1; + guint optical : 1; } GetRoots; static void tracker_storage_finalize (GObject *object); @@ -94,11 +97,13 @@ tracker_storage_class_init (TrackerStorageClass *klass) G_SIGNAL_RUN_LAST, 0, NULL, NULL, - tracker_marshal_VOID__STRING_STRING, + tracker_marshal_VOID__STRING_STRING_BOOLEAN_BOOLEAN, G_TYPE_NONE, - 2, + 4, G_TYPE_STRING, - G_TYPE_STRING); + G_TYPE_STRING, + G_TYPE_BOOLEAN, + G_TYPE_BOOLEAN); signals[MOUNT_POINT_REMOVED] = g_signal_new ("mount-point-removed", @@ -272,7 +277,8 @@ static GNode * mount_add_hierarchy (GNode *root, const gchar *uuid, const gchar *mount_point, - gboolean removable) + gboolean removable, + gboolean optical) { MountInfo *info; GNode *node; @@ -289,6 +295,7 @@ mount_add_hierarchy (GNode *root, info->mount_point = mp; info->uuid = g_strdup (uuid); info->removable = removable; + info->optical = optical; return g_node_append_data (node, info); } @@ -297,17 +304,92 @@ static void mount_add (TrackerStorage *storage, const gchar *uuid, const gchar *mount_point, - gboolean removable_device) + gboolean removable_device, + gboolean optical_disc) { TrackerStoragePrivate *priv; GNode *node; priv = TRACKER_STORAGE_GET_PRIVATE (storage); - node = mount_add_hierarchy (priv->mounts, uuid, mount_point, removable_device); + node = mount_add_hierarchy (priv->mounts, uuid, mount_point, removable_device, optical_disc); 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); + g_signal_emit (storage, + signals[MOUNT_POINT_ADDED], + 0, + uuid, + mount_point, + removable_device, + optical_disc, + NULL); +} + +static gchar * +mount_guess_content_type (GFile *mount_root, + gboolean *is_multimedia) +{ + gchar *content_type = NULL; + + /* Set defaults */ + *is_multimedia = FALSE; + + if (g_file_has_uri_scheme (mount_root, "cdda")) { + *is_multimedia = TRUE; + + content_type = g_strdup ("x-content/audio-cdda"); + } else { + gchar **guess_type; + gint i; + + guess_type = g_content_type_guess_for_tree (mount_root); + + for (i = 0; guess_type && guess_type[i]; i++) { + if (!g_strcmp0 (guess_type[i], "x-content/image-picturecd")) { + /* Images */ + content_type = g_strdup (guess_type[i]); + break; + } else if (!g_strcmp0 (guess_type[i], "x-content/video-bluray") || + !g_strcmp0 (guess_type[i], "x-content/video-dvd") || + !g_strcmp0 (guess_type[i], "x-content/video-hddvd") || + !g_strcmp0 (guess_type[i], "x-content/video-svcd") || + !g_strcmp0 (guess_type[i], "x-content/video-vcd")) { + /* Videos */ + *is_multimedia = TRUE; + content_type = g_strdup (guess_type[i]); + break; + } else if (!g_strcmp0 (guess_type[i], "x-content/audio-cdda") || + !g_strcmp0 (guess_type[i], "x-content/audio-dvd") || + !g_strcmp0 (guess_type[i], "x-content/audio-player")) { + /* Audios */ + *is_multimedia = TRUE; + content_type = g_strdup (guess_type[i]); + break; + } else if (!g_strcmp0 (guess_type[i], "x-content/blank-bd") || + !g_strcmp0 (guess_type[i], "x-content/blank-cd") || + !g_strcmp0 (guess_type[i], "x-content/blank-dvd") || + !g_strcmp0 (guess_type[i], "x-content/blank-hddvd")) { + /* Blank */ + content_type = g_strdup (guess_type[i]); + } else if (!g_strcmp0 (guess_type[i], "x-content/software") || + !g_strcmp0 (guess_type[i], "x-content/unix-software") || + !g_strcmp0 (guess_type[i], "x-content/win32-software")) { + /* NOTE: This one is a guess, can we + * have this content type on + * none-optical mount points? + */ + content_type = g_strdup (guess_type[i]); + } else if (!content_type) { + content_type = g_strdup (guess_type[i]); + } + } + + if (guess_type) { + g_strfreev (guess_type); + } + } + + return content_type; } static void @@ -317,8 +399,9 @@ volume_add (TrackerStorage *storage, { TrackerStoragePrivate *priv; GMount *mount; - gchar *str; + gchar *name; gboolean is_mounted; + gboolean is_optical; gchar *uuid; gchar *mount_point; gchar *device_file; @@ -336,22 +419,64 @@ volume_add (TrackerStorage *storage, } } - str = g_volume_get_name (volume); - g_debug (" Volume:'%s' found", str); - g_free (str); + name = g_volume_get_name (volume); + g_debug (" Volume:'%s' found", name); if (!g_volume_should_automount (volume) || !g_volume_can_mount (volume)) { g_debug (" Ignoring, volume can not be automatically mounted or mounted at all"); + g_free (name); return; } uuid = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UUID); if (!uuid) { - g_debug (" Ignoring, volume has no UUID"); - return; + GFile *file; + gchar *content_type; + gboolean is_multimedia; + + mount = g_volume_get_mount (volume); + + if (mount) { + file = g_mount_get_root (mount); + g_object_unref (mount); + } else { + g_debug (" Being ignored because there is no mount point and no UUID"); + g_free (name); + return; + } + + content_type = mount_guess_content_type (file, &is_multimedia); + g_object_unref (file); + + g_debug (" No UUID, guessed content type:'%s', has music/video:%s", + content_type, + is_multimedia ? "yes" : "no"); + + if (!is_multimedia) { + uuid = g_strdup (name); + g_debug (" Using UUID:'%s' for optical disc", uuid); + } + + g_free (content_type); + + if (!uuid) { + g_debug (" Being ignored because mount is not optical media or is music/video"); + g_free (name); + return; + } + + is_optical = TRUE; + } else { + /* We assume that all devices that are non-optical + * have UUIDS already. Since optical devices are the + * only ones which seem to have no UUID. + */ + is_optical = FALSE; } + g_free (name); + device_file = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); g_debug (" Device file : %s", device_file); @@ -380,7 +505,7 @@ volume_add (TrackerStorage *storage, 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); + mount_add (storage, uuid, mount_point, TRUE, is_optical); } g_free (uuid); @@ -463,7 +588,7 @@ mount_added_cb (GVolumeMonitor *monitor, if (volume) { gchar *device_file; gchar *uuid; - gboolean removable_device = TRUE; + gboolean removable_device; device_file = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); uuid = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UUID); @@ -478,9 +603,27 @@ mount_added_cb (GVolumeMonitor *monitor, /* 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); + mount_add (storage, uuid, mount_point, removable_device, FALSE); } else { - g_message (" Being ignored because we have no UUID"); + gchar *content_type; + gboolean is_multimedia; + + content_type = mount_guess_content_type (file, &is_multimedia); + + g_message (" No UUID, guessed content type:'%s', music/video:%s", + content_type, + is_multimedia ? "yes" : "no"); + + if (!is_multimedia) { + uuid = g_strdup (name); + + g_message (" Using UUID:'%s' for optical disc", uuid); + mount_add (storage, uuid, mount_point, removable_device, TRUE); + } else { + g_message (" Being ignored because mount is not optical media or is music/video"); + } + + g_free (content_type); } g_free (uuid); @@ -579,7 +722,12 @@ get_mount_point_by_uuid_foreach (gpointer key, node = value; info = node->data; - if (!gr->only_removable || info->removable) { + if ((gr->either_condition == TRUE && + (!gr->removable || info->removable) && + (!gr->optical || info->optical)) || + (gr->either_condition == FALSE && + gr->removable == info->removable && + gr->optical == info->optical)) { gchar *normalized_mount_point; gint len; @@ -596,7 +744,7 @@ get_mount_point_by_uuid_foreach (gpointer key, } /** - * tracker_storage_get_removable_device_roots: + * tracker_storage_get_device_roots: * @storage: A #TrackerStorage * * Returns a #GSList of strings containing the root directories for @@ -608,7 +756,10 @@ get_mount_point_by_uuid_foreach (gpointer key, * Returns: The list of root directories. **/ GSList * -tracker_storage_get_removable_device_roots (TrackerStorage *storage) +tracker_storage_get_device_roots (TrackerStorage *storage, + gboolean either_condition, + gboolean removable, + gboolean optical) { TrackerStoragePrivate *priv; GetRoots gr; @@ -618,7 +769,9 @@ tracker_storage_get_removable_device_roots (TrackerStorage *storage) priv = TRACKER_STORAGE_GET_PRIVATE (storage); gr.roots = NULL; - gr.only_removable = TRUE; + gr.either_condition = either_condition; + gr.removable = removable; + gr.optical = optical; g_hash_table_foreach (priv->mounts_by_uuid, get_mount_point_by_uuid_foreach, @@ -628,7 +781,7 @@ tracker_storage_get_removable_device_roots (TrackerStorage *storage) } /** - * tracker_storage_get_removable_device_uuids: + * tracker_storage_get_device_uuids: * @storage: A #TrackerStorage * * Returns a #GSList of strings containing the UUID for removable devices. @@ -638,7 +791,10 @@ tracker_storage_get_removable_device_roots (TrackerStorage *storage) * Returns: The list of UUIDs. **/ GSList * -tracker_storage_get_removable_device_uuids (TrackerStorage *storage) +tracker_storage_get_device_uuids (TrackerStorage *storage, + gboolean either_condition, + gboolean removable, + gboolean optical) { TrackerStoragePrivate *priv; GHashTableIter iter; @@ -662,7 +818,12 @@ tracker_storage_get_removable_device_uuids (TrackerStorage *storage) node = value; info = node->data; - if (info->removable) { + if ((either_condition == TRUE && + (!removable || info->removable) && + (!optical || info->optical)) || + (either_condition == FALSE && + removable == info->removable && + optical == info->optical)) { uuids = g_slist_prepend (uuids, g_strdup (uuid)); } } diff --git a/src/libtracker-miner/tracker-storage.h b/src/libtracker-miner/tracker-storage.h index ee40e91..f65d5b6 100644 --- a/src/libtracker-miner/tracker-storage.h +++ b/src/libtracker-miner/tracker-storage.h @@ -43,14 +43,20 @@ struct _TrackerStorageClass { GObjectClass parent_class; }; -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); +GType tracker_storage_get_type (void) G_GNUC_CONST; +TrackerStorage *tracker_storage_new (void); +GSList * tracker_storage_get_device_roots (TrackerStorage *storage, + gboolean either_condition, + gboolean removable, + gboolean optical); +GSList * tracker_storage_get_device_uuids (TrackerStorage *storage, + gboolean either_condition, + gboolean removable, + gboolean optical); +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 -- cgit v1.2.1 From 78ae9b5902cdeaf3019daa3f053bede19e52fe04 Mon Sep 17 00:00:00 2001 From: Philip Van Hoof Date: Thu, 4 Mar 2010 17:57:50 +0100 Subject: libtracker-miner: Fixed possible memory leak on content_type --- src/libtracker-miner/tracker-storage.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index 727bc6c..2de4f5c 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -371,6 +371,7 @@ mount_guess_content_type (GFile *mount_root, !g_strcmp0 (guess_type[i], "x-content/blank-hddvd")) { /* Blank */ content_type = g_strdup (guess_type[i]); + break; } else if (!g_strcmp0 (guess_type[i], "x-content/software") || !g_strcmp0 (guess_type[i], "x-content/unix-software") || !g_strcmp0 (guess_type[i], "x-content/win32-software")) { @@ -379,8 +380,10 @@ mount_guess_content_type (GFile *mount_root, * none-optical mount points? */ content_type = g_strdup (guess_type[i]); + break; } else if (!content_type) { content_type = g_strdup (guess_type[i]); + break; } } -- cgit v1.2.1 From 71c282622734564a6471a28552d2419754b31aa1 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Thu, 4 Mar 2010 18:48:57 +0100 Subject: TrackerStorage: Add flag set to determine storage type. now get_device_roots() and get_device_uuids() have a TrackerStorageType parameter to pass (removable|optical) flags. If exact_match is TRUE, only devices that fully match the passed flags are returned. --- src/libtracker-miner/tracker-storage.c | 63 ++++++++++++++++++++-------------- src/libtracker-miner/tracker-storage.h | 19 +++++----- 2 files changed, 48 insertions(+), 34 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index 2de4f5c..11fcdbe 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -52,9 +52,8 @@ typedef struct { typedef struct { GSList *roots; - guint either_condition : 1; - guint removable : 1; - guint optical : 1; + TrackerStorageType type; + gboolean exact_match; } GetRoots; static void tracker_storage_finalize (GObject *object); @@ -258,6 +257,22 @@ mount_info_find (GNode *root, return (node) ? node->data : NULL; } +static TrackerStorageType +mount_info_get_type (MountInfo *info) +{ + TrackerStorageType mount_type = 0; + + if (info->removable) { + mount_type |= TRACKER_STORAGE_REMOVABLE; + } + + if (info->optical) { + mount_type |= TRACKER_STORAGE_OPTICAL; + } + + return mount_type; +} + static gchar * mount_point_normalize (const gchar *mount_point) { @@ -719,18 +734,17 @@ get_mount_point_by_uuid_foreach (gpointer key, const gchar *uuid; GNode *node; MountInfo *info; + TrackerStorageType mount_type; gr = user_data; uuid = key; node = value; info = node->data; + mount_type = mount_info_get_type (info); - if ((gr->either_condition == TRUE && - (!gr->removable || info->removable) && - (!gr->optical || info->optical)) || - (gr->either_condition == FALSE && - gr->removable == info->removable && - gr->optical == info->optical)) { + /* is mount of the type we're looking for? */ + if ((gr->exact_match && mount_type == gr->type) || + (!gr->exact_match && ((mount_type & gr->type) == gr->type))) { gchar *normalized_mount_point; gint len; @@ -759,10 +773,9 @@ get_mount_point_by_uuid_foreach (gpointer key, * Returns: The list of root directories. **/ GSList * -tracker_storage_get_device_roots (TrackerStorage *storage, - gboolean either_condition, - gboolean removable, - gboolean optical) +tracker_storage_get_device_roots (TrackerStorage *storage, + TrackerStorageType type, + gboolean exact_match) { TrackerStoragePrivate *priv; GetRoots gr; @@ -772,9 +785,8 @@ tracker_storage_get_device_roots (TrackerStorage *storage, priv = TRACKER_STORAGE_GET_PRIVATE (storage); gr.roots = NULL; - gr.either_condition = either_condition; - gr.removable = removable; - gr.optical = optical; + gr.type = type; + gr.exact_match = exact_match; g_hash_table_foreach (priv->mounts_by_uuid, get_mount_point_by_uuid_foreach, @@ -794,10 +806,9 @@ tracker_storage_get_device_roots (TrackerStorage *storage, * Returns: The list of UUIDs. **/ GSList * -tracker_storage_get_device_uuids (TrackerStorage *storage, - gboolean either_condition, - gboolean removable, - gboolean optical) +tracker_storage_get_device_uuids (TrackerStorage *storage, + TrackerStorageType type, + gboolean exact_match) { TrackerStoragePrivate *priv; GHashTableIter iter; @@ -816,17 +827,17 @@ tracker_storage_get_device_uuids (TrackerStorage *storage, const gchar *uuid; GNode *node; MountInfo *info; + TrackerStorageType mount_type; uuid = key; node = value; info = node->data; - if ((either_condition == TRUE && - (!removable || info->removable) && - (!optical || info->optical)) || - (either_condition == FALSE && - removable == info->removable && - optical == info->optical)) { + mount_type = mount_info_get_type (info); + + /* is mount of the type we're looking for? */ + if ((exact_match && mount_type == type) || + (!exact_match && ((mount_type & type) == type))) { uuids = g_slist_prepend (uuids, g_strdup (uuid)); } } diff --git a/src/libtracker-miner/tracker-storage.h b/src/libtracker-miner/tracker-storage.h index f65d5b6..dc2a92e 100644 --- a/src/libtracker-miner/tracker-storage.h +++ b/src/libtracker-miner/tracker-storage.h @@ -43,16 +43,19 @@ struct _TrackerStorageClass { GObjectClass parent_class; }; +typedef enum { + TRACKER_STORAGE_REMOVABLE = 1 << 0, + TRACKER_STORAGE_OPTICAL = 1 << 1 +} TrackerStorageType; + GType tracker_storage_get_type (void) G_GNUC_CONST; TrackerStorage *tracker_storage_new (void); -GSList * tracker_storage_get_device_roots (TrackerStorage *storage, - gboolean either_condition, - gboolean removable, - gboolean optical); -GSList * tracker_storage_get_device_uuids (TrackerStorage *storage, - gboolean either_condition, - gboolean removable, - gboolean optical); +GSList * tracker_storage_get_device_roots (TrackerStorage *storage, + TrackerStorageType type, + gboolean exact_match); +GSList * tracker_storage_get_device_uuids (TrackerStorage *storage, + TrackerStorageType type, + gboolean exact_match); const gchar * tracker_storage_get_mount_point_for_uuid (TrackerStorage *storage, const gchar *uuid); const gchar* tracker_storage_get_uuid_for_file (TrackerStorage *storage, -- cgit v1.2.1 From 810a1531221ebe442b63a3f6383f53dcf6e5555b Mon Sep 17 00:00:00 2001 From: Martyn Russell Date: Fri, 5 Mar 2010 16:06:55 +0000 Subject: libtracker-miner: Fixed documentation breaks --- src/libtracker-miner/tracker-storage.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index 11fcdbe..e8a41a0 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -763,14 +763,12 @@ get_mount_point_by_uuid_foreach (gpointer key, /** * tracker_storage_get_device_roots: * @storage: A #TrackerStorage + * @type: A #TrackerStorageType + * @exact_match: if all devices should exactly match the types * - * 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. + * Returns: a #GSList of strings containing the root directories for + * devices with @type based on @exact_match. Each element must be + * freed using g_free() and the list itself through g_slist_free(). **/ GSList * tracker_storage_get_device_roots (TrackerStorage *storage, @@ -798,12 +796,12 @@ tracker_storage_get_device_roots (TrackerStorage *storage, /** * tracker_storage_get_device_uuids: * @storage: A #TrackerStorage + * @type: A #TrackerStorageType + * @exact_match: if all devices should exactly match the types * - * 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. + * Returns: a #GSList of strings containing the UUID for devices with + * @type based on @exact_match. Each element must be freed using + * g_free() and the list itself through g_slist_free(). **/ GSList * tracker_storage_get_device_uuids (TrackerStorage *storage, -- cgit v1.2.1 From bc65f553e1f416a26285a884be03c708fd21599f Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Mon, 22 Mar 2010 14:13:19 +0100 Subject: libtracker-miner: Add single tracker-miner.h header. This should be the only include point from now on to libtracker-miner. All code including individual libtracker-miner headers in Tracker has been updated to #include . --- src/libtracker-miner/tracker-storage.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libtracker-miner/tracker-storage.h b/src/libtracker-miner/tracker-storage.h index dc2a92e..83ea64b 100644 --- a/src/libtracker-miner/tracker-storage.h +++ b/src/libtracker-miner/tracker-storage.h @@ -17,6 +17,10 @@ * Boston, MA 02110-1301, USA. */ +#if !defined (__TRACKER_MINER_H_INSIDE__) && !defined (TRACKER_MINER_COMPILATION) +#error "Only can be included directly." +#endif + #ifndef __LIBTRACKER_MINER_STORAGE_H__ #define __LIBTRACKER_MINER_STORAGE_H__ -- cgit v1.2.1 From d48adb230795284aa4a5dad83e9203bb811ce5ac Mon Sep 17 00:00:00 2001 From: Martyn Russell Date: Wed, 24 Mar 2010 14:59:52 +0000 Subject: libtracker-miner: Various code code consistency fixes --- src/libtracker-miner/tracker-storage.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.h b/src/libtracker-miner/tracker-storage.h index 83ea64b..0df074b 100644 --- a/src/libtracker-miner/tracker-storage.h +++ b/src/libtracker-miner/tracker-storage.h @@ -17,13 +17,13 @@ * Boston, MA 02110-1301, USA. */ -#if !defined (__TRACKER_MINER_H_INSIDE__) && !defined (TRACKER_MINER_COMPILATION) -#error "Only can be included directly." -#endif - #ifndef __LIBTRACKER_MINER_STORAGE_H__ #define __LIBTRACKER_MINER_STORAGE_H__ +#if !defined (__LIBTRACKER_MINER_H_INSIDE__) && !defined (TRACKER_COMPILATION) +#error "Only can be included directly." +#endif + #include #include @@ -55,15 +55,15 @@ typedef enum { GType tracker_storage_get_type (void) G_GNUC_CONST; TrackerStorage *tracker_storage_new (void); GSList * tracker_storage_get_device_roots (TrackerStorage *storage, - TrackerStorageType type, - gboolean exact_match); + TrackerStorageType type, + gboolean exact_match); GSList * tracker_storage_get_device_uuids (TrackerStorage *storage, - TrackerStorageType type, - gboolean exact_match); -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); + TrackerStorageType type, + gboolean exact_match); +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 -- cgit v1.2.1 From 659ee167287a3b5b11119cac39239324240f757a Mon Sep 17 00:00:00 2001 From: Martyn Russell Date: Mon, 29 Mar 2010 15:59:17 +0100 Subject: Change Urho's contact name for Ivan's --- src/libtracker-miner/tracker-storage.c | 2 +- src/libtracker-miner/tracker-storage.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index e8a41a0..b8aa2dc 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008, Nokia (urho.konttori@nokia.com) + * Copyright (C) 2008, Nokia * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/src/libtracker-miner/tracker-storage.h b/src/libtracker-miner/tracker-storage.h index 0df074b..a39393c 100644 --- a/src/libtracker-miner/tracker-storage.h +++ b/src/libtracker-miner/tracker-storage.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008, Nokia (urho.konttori@nokia.com) + * Copyright (C) 2008, Nokia * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public -- cgit v1.2.1 From eea9b7c274f2aab3bc21b736467a8b2eb660fe86 Mon Sep 17 00:00:00 2001 From: Martyn Russell Date: Wed, 31 Mar 2010 13:19:14 +0100 Subject: libtracker-miner: Fixed documentation errors and added some Some major sections like tracker-password-provider, tracker-storage and tracker-thumbnailer had no section description. --- src/libtracker-miner/tracker-storage.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index b8aa2dc..90a9b13 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -29,6 +29,16 @@ #include "tracker-utils.h" #include "tracker-marshal.h" +/** + * SECTION:tracker-storage + * @short_description: Removable storage and mount point convenience API + * @include: libtracker-miner/tracker-miner.h + * + * This API is a convenience to to be able to keep track of volumes + * which are mounted and also the type of removable media available. + * The API is built upon the top of GIO's #GMount, #GDrive and #GVolume API. + **/ + #define TRACKER_STORAGE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_STORAGE, TrackerStoragePrivate)) typedef struct { -- cgit v1.2.1 From 48b66fe7bd9b2106b636b783904ad8fc5422ebe6 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 8 Jun 2010 11:09:42 +0200 Subject: Fixes NB#172818: Tracker is not indexing new content on EMMC * If the mount point detected doesn't setup a GVolume (as it is in fstab), then just force a re-check of the directories indexed to see if anything changed. --- src/libtracker-miner/tracker-storage.c | 45 ++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index 90a9b13..d5f40d0 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -337,11 +337,13 @@ mount_add (TrackerStorage *storage, priv = TRACKER_STORAGE_GET_PRIVATE (storage); - node = mount_add_hierarchy (priv->mounts, uuid, mount_point, removable_device, optical_disc); - g_hash_table_insert (priv->mounts_by_uuid, g_strdup (uuid), node); + if (uuid) { + node = mount_add_hierarchy (priv->mounts, uuid, mount_point, removable_device, optical_disc); + g_hash_table_insert (priv->mounts_by_uuid, g_strdup (uuid), node); + } - g_signal_emit (storage, - signals[MOUNT_POINT_ADDED], + g_signal_emit (storage, + signals[MOUNT_POINT_ADDED], 0, uuid, mount_point, @@ -366,9 +368,9 @@ mount_guess_content_type (GFile *mount_root, } else { gchar **guess_type; gint i; - + guess_type = g_content_type_guess_for_tree (mount_root); - + for (i = 0; guess_type && guess_type[i]; i++) { if (!g_strcmp0 (guess_type[i], "x-content/image-picturecd")) { /* Images */ @@ -411,7 +413,7 @@ mount_guess_content_type (GFile *mount_root, break; } } - + if (guess_type) { g_strfreev (guess_type); } @@ -449,7 +451,7 @@ volume_add (TrackerStorage *storage, name = g_volume_get_name (volume); g_debug (" Volume:'%s' found", name); - + if (!g_volume_should_automount (volume) || !g_volume_can_mount (volume)) { g_debug (" Ignoring, volume can not be automatically mounted or mounted at all"); @@ -463,8 +465,8 @@ volume_add (TrackerStorage *storage, gchar *content_type; gboolean is_multimedia; - mount = g_volume_get_mount (volume); - + mount = g_volume_get_mount (volume); + if (mount) { file = g_mount_get_root (mount); g_object_unref (mount); @@ -507,26 +509,26 @@ volume_add (TrackerStorage *storage, 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); + + 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; } - + g_debug (" UUID : %s", uuid); g_debug (" Mounted : %s", is_mounted ? "yes" : "no"); @@ -566,7 +568,7 @@ drives_setup (TrackerStorage *storage) if (!drive) { continue; } - + volumes = g_drive_get_volumes (drive); name = g_drive_get_name (drive); @@ -658,7 +660,8 @@ mount_added_cb (GVolumeMonitor *monitor, g_free (device_file); g_object_unref (volume); } else { - g_message (" Being ignored because we have no GVolume"); + g_message (" Non-Volume mount detected, forcing re-check"); + mount_add (storage, NULL, mount_point, FALSE, FALSE); } g_free (mount_point); @@ -700,7 +703,7 @@ mount_removed_cb (GVolumeMonitor *monitor, 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 { @@ -811,7 +814,7 @@ tracker_storage_get_device_roots (TrackerStorage *storage, * * Returns: a #GSList of strings containing the UUID for devices with * @type based on @exact_match. Each element must be freed using - * g_free() and the list itself through g_slist_free(). + * g_free() and the list itself through g_slist_free(). **/ GSList * tracker_storage_get_device_uuids (TrackerStorage *storage, -- cgit v1.2.1 From 363b88f52cec9db8a304d9890deefa1c1d3a42e2 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 8 Jun 2010 20:05:07 +0200 Subject: libtracker-miner: Use GMounts instead of GVolumes (as not all GMounts have a corresponding GVolume) --- src/libtracker-miner/tracker-storage.c | 329 +++++++++++---------------------- 1 file changed, 103 insertions(+), 226 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index d5f40d0..18b8ad1 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -70,16 +70,13 @@ 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 gboolean mounts_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, @@ -154,13 +151,11 @@ tracker_storage_init (TrackerStorage *storage) 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..."); + g_message ("Mount 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)) { + /* Get all mounts and set them up */ + if (!mounts_setup (storage)) { return; } } @@ -326,21 +321,19 @@ mount_add_hierarchy (GNode *root, } static void -mount_add (TrackerStorage *storage, - const gchar *uuid, - const gchar *mount_point, - gboolean removable_device, - gboolean optical_disc) +mount_add_new (TrackerStorage *storage, + const gchar *uuid, + const gchar *mount_point, + gboolean removable_device, + gboolean optical_disc) { TrackerStoragePrivate *priv; GNode *node; priv = TRACKER_STORAGE_GET_PRIVATE (storage); - if (uuid) { - node = mount_add_hierarchy (priv->mounts, uuid, mount_point, removable_device, optical_disc); - g_hash_table_insert (priv->mounts_by_uuid, g_strdup (uuid), node); - } + node = mount_add_hierarchy (priv->mounts, uuid, mount_point, removable_device, optical_disc); + g_hash_table_insert (priv->mounts_by_uuid, g_strdup (uuid), node); g_signal_emit (storage, signals[MOUNT_POINT_ADDED], @@ -422,172 +415,133 @@ mount_guess_content_type (GFile *mount_root, return content_type; } + static void -volume_add (TrackerStorage *storage, - GVolume *volume, - gboolean initialization) +mount_add (TrackerStorage *storage, + GMount *mount) { TrackerStoragePrivate *priv; - GMount *mount; - gchar *name; - gboolean is_mounted; - gboolean is_optical; - gchar *uuid; - gchar *mount_point; - gchar *device_file; - - if (!initialization) { - GDrive *drive; + GFile *root; + GVolume *volume; + gchar *mount_name, *mount_path, *uuid; + gboolean is_optical = FALSE; + gboolean is_removable = FALSE; - drive = g_volume_get_drive (volume); + g_return_if_fail (storage); + g_return_if_fail (mount); - if (drive) { - g_debug ("Drive:'%s' added 1 volume:", - g_drive_get_name (drive)); - } else { - g_debug ("No drive associated with volume being added:"); - } - } + priv = TRACKER_STORAGE_GET_PRIVATE (storage); - name = g_volume_get_name (volume); - g_debug (" Volume:'%s' found", name); + /* Get mount name */ + mount_name = g_mount_get_name (mount); - if (!g_volume_should_automount (volume) || - !g_volume_can_mount (volume)) { - g_debug (" Ignoring, volume can not be automatically mounted or mounted at all"); - g_free (name); - return; - } + /* Get root path of the mount */ + root = g_mount_get_root (mount); + mount_path = g_file_get_path (root); - uuid = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UUID); - if (!uuid) { - GFile *file; - gchar *content_type; - gboolean is_multimedia; + g_debug ("Mount '%s' found (path: '%s')", + mount_name, mount_path); - mount = g_volume_get_mount (volume); + /* fstab partitions may not have corresponding + * GVolumes, so volume may be NULL */ + volume = g_mount_get_volume (mount); + if (volume) { + /* GMount with GVolume */ - if (mount) { - file = g_mount_get_root (mount); - g_object_unref (mount); - } else { - g_debug (" Being ignored because there is no mount point and no UUID"); - g_free (name); - return; - } + /* Try to get UUID from the Volume. + * Note that g_volume_get_uuid() is NOT equivalent */ + uuid = g_volume_get_identifier (volume, + G_VOLUME_IDENTIFIER_KIND_UUID); + if (!uuid) { + /* Optical discs won't have UUID in the GVolume */ + gchar *content_type; + gboolean is_multimedia; - content_type = mount_guess_content_type (file, &is_multimedia); - g_object_unref (file); + content_type = mount_guess_content_type (root, + &is_multimedia); + g_debug (" No UUID, guessed content type:'%s', has music/video:%s", + content_type, + is_multimedia ? "yes" : "no"); - g_debug (" No UUID, guessed content type:'%s', has music/video:%s", - content_type, - is_multimedia ? "yes" : "no"); + if (!is_multimedia) { + uuid = g_strdup (mount_name); + is_optical = TRUE; + is_removable = TRUE; + g_debug (" Using UUID:'%s' for optical disc", uuid); + } else { + g_debug (" Being ignored because mount is not optical " + "media or is music/video"); + } - if (!is_multimedia) { - uuid = g_strdup (name); - g_debug (" Using UUID:'%s' for optical disc", uuid); + g_free (content_type); + } else { + /* Any other removable media will have UUID in the GVolume. + * Note that this also may include some partitions in the machine + * which have GVolumes associated to the GMounts */ + is_removable = TRUE; } - g_free (content_type); - + g_object_unref (volume); + } else { + /* GMount without GVolume. + * Note: Did never found a case where this g_mount_get_uuid() returns + * non-NULL... :-) */ + uuid = g_mount_get_uuid (mount); if (!uuid) { - g_debug (" Being ignored because mount is not optical media or is music/video"); - g_free (name); - return; + if(mount_path) { + uuid = g_strdup (mount_path); + g_debug (" No UUID, so using:'%s' for mount without volume", + uuid); + } else { + g_debug (" Being ignored because mount without volume " + "and no root path available"); + } } - - is_optical = TRUE; - } else { - /* We assume that all devices that are non-optical - * have UUIDS already. Since optical devices are the - * only ones which seem to have no UUID. - */ - is_optical = FALSE; - } - - g_free (name); - - 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; } - 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, is_optical); + /* If we got something to be used as UUID, then add the mount + * to the TrackerStorage */ + if (uuid && !g_hash_table_lookup (priv->mounts_by_uuid, uuid)) { + g_debug (" Adding new mount '%s' with UUID '%s' at '%s' " + "(removable: %s, optical: %s)", + mount_name, + uuid, + mount_path, + is_removable ? "yes" : "no", + is_optical ? "yes" : "no"); + mount_add_new (storage, uuid, mount_path, is_removable, is_optical); } + g_free (mount_name); + g_free (mount_path); g_free (uuid); - g_free (mount_point); - g_free (device_file); + g_object_unref (root); } static gboolean -drives_setup (TrackerStorage *storage) +mounts_setup (TrackerStorage *storage) { TrackerStoragePrivate *priv; - GList *drives, *ld; + GList *mounts, *lm; priv = TRACKER_STORAGE_GET_PRIVATE (storage); - drives = g_volume_monitor_get_connected_drives (priv->volume_monitor); + mounts = g_volume_monitor_get_mounts (priv->volume_monitor); - if (g_list_length (drives) < 1) { - g_message ("No drives found to iterate"); + if (!mounts) { + g_message ("No mounts found to iterate"); return TRUE; } - for (ld = drives; ld; ld = ld->next) { - GDrive *drive; - GList *volumes, *lv; - gchar *name; - - drive = ld->data; - - if (!drive) { - continue; - } - - volumes = g_drive_get_volumes (drive); - name = g_drive_get_name (drive); - - g_debug ("Drive:'%s' found with %d %s:", - name, - 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_free (name); + /* Iterate over all available mounts and add them. + * Note that GVolumeMonitor shows only those mounts which are + * actually mounted. */ + for (lm = mounts; lm; lm = g_list_next (lm)) { + mount_add (storage, lm->data); + g_object_unref (lm->data); } - g_list_free (drives); + g_list_free (mounts); return TRUE; } @@ -597,76 +551,7 @@ 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; - - 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, FALSE); - } else { - gchar *content_type; - gboolean is_multimedia; - - content_type = mount_guess_content_type (file, &is_multimedia); - - g_message (" No UUID, guessed content type:'%s', music/video:%s", - content_type, - is_multimedia ? "yes" : "no"); - - if (!is_multimedia) { - uuid = g_strdup (name); - - g_message (" Using UUID:'%s' for optical disc", uuid); - mount_add (storage, uuid, mount_point, removable_device, TRUE); - } else { - g_message (" Being ignored because mount is not optical media or is music/video"); - } - - g_free (content_type); - } - - g_free (uuid); - g_free (device_file); - g_object_unref (volume); - } else { - g_message (" Non-Volume mount detected, forcing re-check"); - mount_add (storage, NULL, mount_point, FALSE, FALSE); - } - - g_free (mount_point); - g_object_unref (file); - g_free (name); + mount_add (user_data, mount); } static void @@ -717,14 +602,6 @@ mount_removed_cb (GVolumeMonitor *monitor, 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: * -- cgit v1.2.1 From 840e1c8de10161c888b3d09a56ab770bff71afd7 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 8 Jun 2010 20:43:27 +0200 Subject: Fixes GB#621001: don't allow whitespaces in UUIDs * Using MD5 of the mount name for the UUID of optical media * Using MD5 of the mount path for the UUID of GMounts without a corresponding GVolume --- src/libtracker-miner/tracker-storage.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index 18b8ad1..47c215d 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -464,7 +464,10 @@ mount_add (TrackerStorage *storage, is_multimedia ? "yes" : "no"); if (!is_multimedia) { - uuid = g_strdup (mount_name); + /* Get UUID as MD5 digest of the mount name */ + uuid = g_compute_checksum_for_string (G_CHECKSUM_MD5, + mount_name, + -1); is_optical = TRUE; is_removable = TRUE; g_debug (" Using UUID:'%s' for optical disc", uuid); @@ -489,7 +492,10 @@ mount_add (TrackerStorage *storage, uuid = g_mount_get_uuid (mount); if (!uuid) { if(mount_path) { - uuid = g_strdup (mount_path); + /* Get UUID as MD5 digest of the mount path */ + uuid = g_compute_checksum_for_string (G_CHECKSUM_MD5, + mount_path, + -1); g_debug (" No UUID, so using:'%s' for mount without volume", uuid); } else { -- cgit v1.2.1 From 8cea03ad3d6127abdcf5c6bd86627986a4e57def Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 8 Jun 2010 22:02:44 +0200 Subject: libtracker-miner: properly detect removable media --- src/libtracker-miner/tracker-storage.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index 47c215d..a7f597f 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -480,8 +480,19 @@ mount_add (TrackerStorage *storage, } else { /* Any other removable media will have UUID in the GVolume. * Note that this also may include some partitions in the machine - * which have GVolumes associated to the GMounts */ - is_removable = TRUE; + * which have GVolumes associated to the GMounts. So, we need to + * explicitly check if the drive is media-removable (machine + * partitions won't be media-removable) */ + GDrive *drive; + + drive = g_volume_get_drive (volume); + if (drive) { + is_removable = g_drive_is_media_removable (drive); + g_object_unref (drive); + } else { + /* Note: not sure when this can happen... */ + is_removable = TRUE; + } } g_object_unref (volume); -- cgit v1.2.1 From 7842e07717ad78d162137bb64226fec8255b9393 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 14 Jun 2010 11:09:00 +0200 Subject: libtracker-miner: don't consider shadowed GMounts --- src/libtracker-miner/tracker-storage.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index a7f597f..4813773 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -430,11 +430,18 @@ mount_add (TrackerStorage *storage, g_return_if_fail (storage); g_return_if_fail (mount); - priv = TRACKER_STORAGE_GET_PRIVATE (storage); - /* Get mount name */ mount_name = g_mount_get_name (mount); + /* Do not process shadowed mounts! */ + if (g_mount_is_shadowed (mount)) { + g_debug ("Skipping shadowed mount '%s'", mount_name); + g_free (mount_name); + return; + } + + priv = TRACKER_STORAGE_GET_PRIVATE (storage); + /* Get root path of the mount */ root = g_mount_get_root (mount); mount_path = g_file_get_path (root); -- cgit v1.2.1 From 0afdf59c5be3960e17cc8e13a56fa28d1d33ca91 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 14 Jun 2010 13:21:11 +0200 Subject: libtracker-miner: minor indentation fixes --- src/libtracker-miner/tracker-storage.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index 4813773..5cc9161 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -418,7 +418,7 @@ mount_guess_content_type (GFile *mount_root, static void mount_add (TrackerStorage *storage, - GMount *mount) + GMount *mount) { TrackerStoragePrivate *priv; GFile *root; @@ -427,9 +427,6 @@ mount_add (TrackerStorage *storage, gboolean is_optical = FALSE; gboolean is_removable = FALSE; - g_return_if_fail (storage); - g_return_if_fail (mount); - /* Get mount name */ mount_name = g_mount_get_name (mount); @@ -450,13 +447,13 @@ mount_add (TrackerStorage *storage, mount_name, mount_path); /* fstab partitions may not have corresponding - * GVolumes, so volume may be NULL */ + * GVolumes, so volume may be NULL */ volume = g_mount_get_volume (mount); if (volume) { /* GMount with GVolume */ /* Try to get UUID from the Volume. - * Note that g_volume_get_uuid() is NOT equivalent */ + * Note that g_volume_get_uuid() is NOT equivalent */ uuid = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UUID); if (!uuid) { @@ -486,10 +483,10 @@ mount_add (TrackerStorage *storage, g_free (content_type); } else { /* Any other removable media will have UUID in the GVolume. - * Note that this also may include some partitions in the machine - * which have GVolumes associated to the GMounts. So, we need to - * explicitly check if the drive is media-removable (machine - * partitions won't be media-removable) */ + * Note that this also may include some partitions in the machine + * which have GVolumes associated to the GMounts. So, we need to + * explicitly check if the drive is media-removable (machine + * partitions won't be media-removable) */ GDrive *drive; drive = g_volume_get_drive (volume); @@ -506,10 +503,10 @@ mount_add (TrackerStorage *storage, } else { /* GMount without GVolume. * Note: Did never found a case where this g_mount_get_uuid() returns - * non-NULL... :-) */ + * non-NULL... :-) */ uuid = g_mount_get_uuid (mount); if (!uuid) { - if(mount_path) { + if (mount_path) { /* Get UUID as MD5 digest of the mount path */ uuid = g_compute_checksum_for_string (G_CHECKSUM_MD5, mount_path, @@ -524,9 +521,9 @@ mount_add (TrackerStorage *storage, } /* If we got something to be used as UUID, then add the mount - * to the TrackerStorage */ + * to the TrackerStorage */ if (uuid && !g_hash_table_lookup (priv->mounts_by_uuid, uuid)) { - g_debug (" Adding new mount '%s' with UUID '%s' at '%s' " + g_debug (" Adding new mount '%s' with UUID '%s' at '%s' " "(removable: %s, optical: %s)", mount_name, uuid, @@ -559,7 +556,7 @@ mounts_setup (TrackerStorage *storage) /* Iterate over all available mounts and add them. * Note that GVolumeMonitor shows only those mounts which are - * actually mounted. */ + * actually mounted. */ for (lm = mounts; lm; lm = g_list_next (lm)) { mount_add (storage, lm->data); g_object_unref (lm->data); -- cgit v1.2.1 From 24b958d6f2d70bae5d0684f6e080381fec316865 Mon Sep 17 00:00:00 2001 From: Martyn Russell Date: Mon, 14 Jun 2010 17:34:19 +0100 Subject: libtracker-miner: Fixed broken is_optical detection Previously we used content type guessing, this isn't full proof as I discovered during testing this branch. Now we use the same method GIO uses by looking at the filesystem type/device/mount point (in that order). Seems to work for all the formats tested here for me: - Compaq flash (EOS Canon card) - USB stick - CD (audio) - CD (game) - DVD (movie) - MMC (SD) - USB hard disk --- src/libtracker-miner/tracker-storage.c | 252 +++++++++++++++++++++------------ 1 file changed, 163 insertions(+), 89 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index 5cc9161..ddd0ad0 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -22,6 +22,7 @@ #include #include +#include #include @@ -347,75 +348,141 @@ mount_add_new (TrackerStorage *storage, static gchar * mount_guess_content_type (GFile *mount_root, - gboolean *is_multimedia) + GVolume *volume, + gboolean *is_optical, + gboolean *is_multimedia) { + GUnixMountEntry *entry; gchar *content_type = NULL; - - /* Set defaults */ - *is_multimedia = FALSE; + gchar *mount_path; + gchar *device_path; + const gchar *filesystem_type = NULL; + gchar **guess_type; + gint i; + + /* This function has 2 purposes: + * + * 1. Detect if we are using optical media + * 2. Detect if we are video or music, we can't index those types + */ if (g_file_has_uri_scheme (mount_root, "cdda")) { + g_debug (" Scheme is CDDA, assuming this is a CD"); + + *is_optical = TRUE; *is_multimedia = TRUE; - content_type = g_strdup ("x-content/audio-cdda"); - } else { - gchar **guess_type; - gint i; - - guess_type = g_content_type_guess_for_tree (mount_root); - - for (i = 0; guess_type && guess_type[i]; i++) { - if (!g_strcmp0 (guess_type[i], "x-content/image-picturecd")) { - /* Images */ - content_type = g_strdup (guess_type[i]); - break; - } else if (!g_strcmp0 (guess_type[i], "x-content/video-bluray") || - !g_strcmp0 (guess_type[i], "x-content/video-dvd") || - !g_strcmp0 (guess_type[i], "x-content/video-hddvd") || - !g_strcmp0 (guess_type[i], "x-content/video-svcd") || - !g_strcmp0 (guess_type[i], "x-content/video-vcd")) { - /* Videos */ - *is_multimedia = TRUE; - content_type = g_strdup (guess_type[i]); - break; - } else if (!g_strcmp0 (guess_type[i], "x-content/audio-cdda") || - !g_strcmp0 (guess_type[i], "x-content/audio-dvd") || - !g_strcmp0 (guess_type[i], "x-content/audio-player")) { - /* Audios */ - *is_multimedia = TRUE; - content_type = g_strdup (guess_type[i]); - break; - } else if (!g_strcmp0 (guess_type[i], "x-content/blank-bd") || - !g_strcmp0 (guess_type[i], "x-content/blank-cd") || - !g_strcmp0 (guess_type[i], "x-content/blank-dvd") || - !g_strcmp0 (guess_type[i], "x-content/blank-hddvd")) { - /* Blank */ - content_type = g_strdup (guess_type[i]); - break; - } else if (!g_strcmp0 (guess_type[i], "x-content/software") || - !g_strcmp0 (guess_type[i], "x-content/unix-software") || - !g_strcmp0 (guess_type[i], "x-content/win32-software")) { - /* NOTE: This one is a guess, can we - * have this content type on - * none-optical mount points? - */ - content_type = g_strdup (guess_type[i]); - break; - } else if (!content_type) { - content_type = g_strdup (guess_type[i]); - break; + return g_strdup ("x-content/audio-cdda"); + } + + *is_optical = FALSE; + *is_multimedia = FALSE; + + mount_path = g_file_get_path (mount_root); + + /* FIXME: Try to assume we have a unix mount :( + * EEK, once in a while, I have to write crack, oh well + */ + entry = g_unix_mount_at (mount_path, NULL); + + if (entry) { + filesystem_type = g_unix_mount_get_fs_type (entry); + g_debug (" Using filesystem type:'%s'", + filesystem_type); + + device_path = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); + + g_debug (" Using device path:'%s'", + device_path); + + if (strcmp (filesystem_type, "udf") == 0 || + strcmp (filesystem_type, "iso9660") == 0 || + strcmp (filesystem_type, "cd9660") == 0 || + g_str_has_prefix (device_path, "/dev/cdrom") || + g_str_has_prefix (device_path, "/dev/acd") || + g_str_has_prefix (device_path, "/dev/cd")) { + *is_optical = TRUE; + } else if (g_str_has_prefix (device_path, "/vol/")) { + const gchar *name; + + name = mount_path + strlen ("/"); + + if (g_str_has_prefix (name, "cdrom")) { + *is_optical = TRUE; } + } else { + gchar *basename = g_path_get_basename (mount_path); + + if (g_str_has_prefix (basename, "cdr") || + g_str_has_prefix (basename, "cdwriter") || + g_str_has_prefix (basename, "burn") || + g_str_has_prefix (basename, "dvdr")) { + *is_optical = TRUE; + } + + g_free (basename); } - if (guess_type) { - g_strfreev (guess_type); + g_free (device_path); + g_free (mount_path); + } else { + g_debug (" No GUnixMountEntry found, needed for detecting if optical media... :("); + g_free (mount_path); + } + + /* Check we don't have multimedia */ + guess_type = g_content_type_guess_for_tree (mount_root); + + for (i = 0; guess_type && guess_type[i]; i++) { + if (!g_strcmp0 (guess_type[i], "x-content/image-picturecd")) { + /* Images */ + content_type = g_strdup (guess_type[i]); + break; + } else if (!g_strcmp0 (guess_type[i], "x-content/video-bluray") || + !g_strcmp0 (guess_type[i], "x-content/video-dvd") || + !g_strcmp0 (guess_type[i], "x-content/video-hddvd") || + !g_strcmp0 (guess_type[i], "x-content/video-svcd") || + !g_strcmp0 (guess_type[i], "x-content/video-vcd")) { + /* Videos */ + *is_multimedia = TRUE; + content_type = g_strdup (guess_type[i]); + break; + } else if (!g_strcmp0 (guess_type[i], "x-content/audio-cdda") || + !g_strcmp0 (guess_type[i], "x-content/audio-dvd") || + !g_strcmp0 (guess_type[i], "x-content/audio-player")) { + /* Audios */ + *is_multimedia = TRUE; + content_type = g_strdup (guess_type[i]); + break; + } else if (!g_strcmp0 (guess_type[i], "x-content/blank-bd") || + !g_strcmp0 (guess_type[i], "x-content/blank-cd") || + !g_strcmp0 (guess_type[i], "x-content/blank-dvd") || + !g_strcmp0 (guess_type[i], "x-content/blank-hddvd")) { + /* Blank */ + content_type = g_strdup (guess_type[i]); + break; + } else if (!g_strcmp0 (guess_type[i], "x-content/software") || + !g_strcmp0 (guess_type[i], "x-content/unix-software") || + !g_strcmp0 (guess_type[i], "x-content/win32-software")) { + /* NOTE: This one is a guess, can we + * have this content type on + * none-optical mount points? + */ + content_type = g_strdup (guess_type[i]); + break; + } else if (!content_type) { + content_type = g_strdup (guess_type[i]); + break; } } + if (guess_type) { + g_strfreev (guess_type); + } + return content_type; } - static void mount_add (TrackerStorage *storage, GMount *mount) @@ -430,22 +497,25 @@ mount_add (TrackerStorage *storage, /* Get mount name */ mount_name = g_mount_get_name (mount); + /* Get root path of the mount */ + root = g_mount_get_root (mount); + mount_path = g_file_get_path (root); + + g_debug ("Found '%s' mounted on path '%s'", + mount_name, + mount_path); + /* Do not process shadowed mounts! */ if (g_mount_is_shadowed (mount)) { - g_debug ("Skipping shadowed mount '%s'", mount_name); + g_debug (" Skipping shadowed mount '%s'", mount_name); + g_object_unref (root); + g_free (mount_path); g_free (mount_name); return; } priv = TRACKER_STORAGE_GET_PRIVATE (storage); - /* Get root path of the mount */ - root = g_mount_get_root (mount); - mount_path = g_file_get_path (root); - - g_debug ("Mount '%s' found (path: '%s')", - mount_name, mount_path); - /* fstab partitions may not have corresponding * GVolumes, so volume may be NULL */ volume = g_mount_get_volume (mount); @@ -457,27 +527,23 @@ mount_add (TrackerStorage *storage, uuid = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UUID); if (!uuid) { - /* Optical discs won't have UUID in the GVolume */ gchar *content_type; gboolean is_multimedia; - content_type = mount_guess_content_type (root, - &is_multimedia); - g_debug (" No UUID, guessed content type:'%s', has music/video:%s", - content_type, - is_multimedia ? "yes" : "no"); + /* Optical discs usually won't have UUID in the GVolume */ + content_type = mount_guess_content_type (root, volume, &is_optical, &is_multimedia); + is_removable = TRUE; + /* We don't index content which is video or music, nothing to index */ if (!is_multimedia) { - /* Get UUID as MD5 digest of the mount name */ uuid = g_compute_checksum_for_string (G_CHECKSUM_MD5, - mount_name, - -1); - is_optical = TRUE; - is_removable = TRUE; - g_debug (" Using UUID:'%s' for optical disc", uuid); + mount_name, + -1); + g_debug (" No UUID, generated:'%s' (based on mount name)", uuid); + g_debug (" Assuming GVolume has removable media, if wrong report a bug!"); } else { - g_debug (" Being ignored because mount is not optical " - "media or is music/video"); + g_debug (" Being ignored because mount is music/video, content type is '%s'", + content_type); } g_free (content_type); @@ -495,6 +561,7 @@ mount_add (TrackerStorage *storage, g_object_unref (drive); } else { /* Note: not sure when this can happen... */ + g_debug (" Assuming GDrive has removable media, if wrong report a bug!"); is_removable = TRUE; } } @@ -502,20 +569,30 @@ mount_add (TrackerStorage *storage, g_object_unref (volume); } else { /* GMount without GVolume. - * Note: Did never found a case where this g_mount_get_uuid() returns + * Note: Never found a case where this g_mount_get_uuid() returns * non-NULL... :-) */ uuid = g_mount_get_uuid (mount); if (!uuid) { if (mount_path) { - /* Get UUID as MD5 digest of the mount path */ - uuid = g_compute_checksum_for_string (G_CHECKSUM_MD5, - mount_path, - -1); - g_debug (" No UUID, so using:'%s' for mount without volume", - uuid); + gchar *content_type; + gboolean is_multimedia; + + content_type = mount_guess_content_type (root, volume, &is_optical, &is_multimedia); + + if (!is_multimedia) { + uuid = g_compute_checksum_for_string (G_CHECKSUM_MD5, + mount_path, + -1); + g_debug (" No UUID, generated:'%s' (based on mount path)", uuid); + } else { + g_debug (" Being ignored because mount is music/video, content type is '%s'", + content_type); + } + + g_free (content_type); } else { - g_debug (" Being ignored because mount without volume " - "and no root path available"); + g_debug (" Being ignored because mount has no GVolume (i.e. not user mountable) " + "and has mount root path available"); } } } @@ -523,11 +600,8 @@ mount_add (TrackerStorage *storage, /* If we got something to be used as UUID, then add the mount * to the TrackerStorage */ if (uuid && !g_hash_table_lookup (priv->mounts_by_uuid, uuid)) { - g_debug (" Adding new mount '%s' with UUID '%s' at '%s' " - "(removable: %s, optical: %s)", - mount_name, + g_debug (" Adding mount point with UUID:'%s', removable: %s, optical: %s", uuid, - mount_path, is_removable ? "yes" : "no", is_optical ? "yes" : "no"); mount_add_new (storage, uuid, mount_path, is_removable, is_optical); -- cgit v1.2.1 From ed5e03aaeee3aa1c23dff1f1c384aa67b33ec21a Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 14 Jun 2010 19:52:17 +0200 Subject: libtracker-miner, miner-fs: remove trailing whitespaces --- src/libtracker-miner/tracker-storage.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index ddd0ad0..c2e6c28 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -392,7 +392,7 @@ mount_guess_content_type (GFile *mount_root, device_path = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); - g_debug (" Using device path:'%s'", + g_debug (" Using device path:'%s'", device_path); if (strcmp (filesystem_type, "udf") == 0 || @@ -502,7 +502,7 @@ mount_add (TrackerStorage *storage, mount_path = g_file_get_path (root); g_debug ("Found '%s' mounted on path '%s'", - mount_name, + mount_name, mount_path); /* Do not process shadowed mounts! */ -- cgit v1.2.1 From f074233ef077b6bd172d057493fc4c64cf3a0775 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 14 Jun 2010 20:12:44 +0200 Subject: libtracker-miner: support GMounts without GVolume in mount_guess_content_type() --- src/libtracker-miner/tracker-storage.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index c2e6c28..31f9eaa 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -355,8 +355,6 @@ mount_guess_content_type (GFile *mount_root, GUnixMountEntry *entry; gchar *content_type = NULL; gchar *mount_path; - gchar *device_path; - const gchar *filesystem_type = NULL; gchar **guess_type; gint i; @@ -386,23 +384,30 @@ mount_guess_content_type (GFile *mount_root, entry = g_unix_mount_at (mount_path, NULL); if (entry) { + const gchar *filesystem_type; + gchar *device_path = NULL; + filesystem_type = g_unix_mount_get_fs_type (entry); g_debug (" Using filesystem type:'%s'", filesystem_type); - device_path = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); - - g_debug (" Using device path:'%s'", - device_path); + /* Volume may be NULL */ + if (volume) { + device_path = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); + g_debug (" Using device path:'%s'", + device_path); + } if (strcmp (filesystem_type, "udf") == 0 || strcmp (filesystem_type, "iso9660") == 0 || strcmp (filesystem_type, "cd9660") == 0 || - g_str_has_prefix (device_path, "/dev/cdrom") || - g_str_has_prefix (device_path, "/dev/acd") || - g_str_has_prefix (device_path, "/dev/cd")) { + (device_path && + (g_str_has_prefix (device_path, "/dev/cdrom") || + g_str_has_prefix (device_path, "/dev/acd") || + g_str_has_prefix (device_path, "/dev/cd")))) { *is_optical = TRUE; - } else if (g_str_has_prefix (device_path, "/vol/")) { + } else if (device_path && + g_str_has_prefix (device_path, "/vol/")) { const gchar *name; name = mount_path + strlen ("/"); -- cgit v1.2.1 From de79b57916123fd6948714dc79ad7ecb7e008e58 Mon Sep 17 00:00:00 2001 From: Martyn Russell Date: Tue, 15 Jun 2010 09:56:35 +0100 Subject: libtracker-miner: Added some comments to the content guessing code() - Added information about WHERE we got the code from - GIO - Added reasoning for why we have the is_multimedia check --- src/libtracker-miner/tracker-storage.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index 31f9eaa..9fde62e 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -398,6 +398,17 @@ mount_guess_content_type (GFile *mount_root, device_path); } + /* NOTE: This code was taken from guess_mount_type() + * in GIO's gunixmounts.c and adapted purely for + * guessing optical media. We don't use the guessing + * code for other types such as MEMSTICKS, ZIPs, + * IPODs, etc. + * + * This code may need updating over time since it is + * very situational depending on how distributions + * mount their devices and how devices are named in + * /dev. + */ if (strcmp (filesystem_type, "udf") == 0 || strcmp (filesystem_type, "iso9660") == 0 || strcmp (filesystem_type, "cd9660") == 0 || @@ -435,7 +446,13 @@ mount_guess_content_type (GFile *mount_root, g_free (mount_path); } - /* Check we don't have multimedia */ + /* We try to determine the content type because we don't want + * to store Volume information in Tracker about DVDs and media + * which has no real data for us to mine. + * + * Generally, if is_multimedia is TRUE then we end up ignoring + * the media. + */ guess_type = g_content_type_guess_for_tree (mount_root); for (i = 0; guess_type && guess_type[i]; i++) { -- cgit v1.2.1 From 10cefbfb276b8a50572f3775d3840444a6269f75 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 15 Jun 2010 17:38:59 +0200 Subject: Fixes GB#621015: Index removable media when miner-fs starts and configured to do so --- src/libtracker-miner/tracker-storage.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index 9fde62e..df7f7e8 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -751,7 +751,7 @@ get_mount_point_by_uuid_foreach (gpointer key, /* is mount of the type we're looking for? */ if ((gr->exact_match && mount_type == gr->type) || - (!gr->exact_match && ((mount_type & gr->type) == gr->type))) { + (!gr->exact_match && (mount_type & gr->type))) { gchar *normalized_mount_point; gint len; @@ -842,7 +842,7 @@ tracker_storage_get_device_uuids (TrackerStorage *storage, /* is mount of the type we're looking for? */ if ((exact_match && mount_type == type) || - (!exact_match && ((mount_type & type) == type))) { + (!exact_match && (mount_type & type))) { uuids = g_slist_prepend (uuids, g_strdup (uuid)); } } -- cgit v1.2.1 From 50f955526d60ef05a21f92dec9a8fb7941befca6 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 16 Jun 2010 18:20:21 +0200 Subject: libtracker-miner: New tracker_storage_get_type_for_uuid API method --- src/libtracker-miner/tracker-storage.c | 38 ++++++++++++++++++++++++++++++++++ src/libtracker-miner/tracker-storage.h | 26 ++++++++++++----------- 2 files changed, 52 insertions(+), 12 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index df7f7e8..5eafe42 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -881,6 +881,44 @@ tracker_storage_get_mount_point_for_uuid (TrackerStorage *storage, return info->mount_point; } +/** + * tracker_storage_get_type_for_uuid: + * @storage: A #TrackerStorage + * @uuid: A string pointer to the UUID for the %GVolume. + * + * Returns: The type flags for @uuid. + **/ +TrackerStorageType +tracker_storage_get_type_for_uuid (TrackerStorage *storage, + const gchar *uuid) +{ + TrackerStoragePrivate *priv; + GNode *node; + TrackerStorageType type = 0; + + g_return_val_if_fail (TRACKER_IS_STORAGE (storage), 0); + g_return_val_if_fail (uuid != NULL, 0); + + priv = TRACKER_STORAGE_GET_PRIVATE (storage); + + node = g_hash_table_lookup (priv->mounts_by_uuid, uuid); + + if (node) { + MountInfo *info; + + info = node->data; + + if (info->removable) { + type |= TRACKER_STORAGE_REMOVABLE; + } + if (info->optical) { + type |= TRACKER_STORAGE_OPTICAL; + } + } + + return type; +} + /** * tracker_storage_get_uuid_for_file: * @storage: A #TrackerStorage diff --git a/src/libtracker-miner/tracker-storage.h b/src/libtracker-miner/tracker-storage.h index a39393c..27d0e28 100644 --- a/src/libtracker-miner/tracker-storage.h +++ b/src/libtracker-miner/tracker-storage.h @@ -52,18 +52,20 @@ typedef enum { TRACKER_STORAGE_OPTICAL = 1 << 1 } TrackerStorageType; -GType tracker_storage_get_type (void) G_GNUC_CONST; -TrackerStorage *tracker_storage_new (void); -GSList * tracker_storage_get_device_roots (TrackerStorage *storage, - TrackerStorageType type, - gboolean exact_match); -GSList * tracker_storage_get_device_uuids (TrackerStorage *storage, - TrackerStorageType type, - gboolean exact_match); -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); +GType tracker_storage_get_type (void) G_GNUC_CONST; +TrackerStorage * tracker_storage_new (void); +GSList * tracker_storage_get_device_roots (TrackerStorage *storage, + TrackerStorageType type, + gboolean exact_match); +GSList * tracker_storage_get_device_uuids (TrackerStorage *storage, + TrackerStorageType type, + gboolean exact_match); +const gchar * tracker_storage_get_mount_point_for_uuid (TrackerStorage *storage, + const gchar *uuid); +TrackerStorageType tracker_storage_get_type_for_uuid (TrackerStorage *storage, + const gchar *uuid); +const gchar* tracker_storage_get_uuid_for_file (TrackerStorage *storage, + GFile *file); G_END_DECLS -- cgit v1.2.1 From c74a82f8c4e234ac235b15327a22ffbb3aab5065 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 17 Jun 2010 15:27:00 +0200 Subject: libtracker-miner: New helper macros to work with storage types * TRACKER_STORAGE_TYPE_IS_REMOVABLE * TRACKER_STORAGE_TYPE_IS_OPTICAL --- src/libtracker-miner/tracker-storage.h | 40 +++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.h b/src/libtracker-miner/tracker-storage.h index 27d0e28..3ac584f 100644 --- a/src/libtracker-miner/tracker-storage.h +++ b/src/libtracker-miner/tracker-storage.h @@ -29,6 +29,39 @@ G_BEGIN_DECLS +/** + * TrackerStorageType: + * @TRACKER_STORAGE_REMOVABLE: Storage is a removable media + * @TRACKER_STORAGE_OPTICAL: Storage is an optical disc + * + * Flags specifying properties of the type of storage. + */ +typedef enum { + TRACKER_STORAGE_REMOVABLE = 1 << 0, + TRACKER_STORAGE_OPTICAL = 1 << 1 +} TrackerStorageType; + +/** + * TRACKER_STORAGE_TYPE_IS_REMOVABLE: + * @type: Mask of TrackerStorageType flags + * + * Check if the given storage type is marked as being removable media. + * + * Returns: %TRUE if the storage is marked as removable media, %FALSE otherwise + */ +#define TRACKER_STORAGE_TYPE_IS_REMOVABLE(type) ((type & TRACKER_STORAGE_REMOVABLE) ? TRUE : FALSE) + +/** + * TRACKER_STORAGE_TYPE_IS_OPTICAL: + * @type: Mask of TrackerStorageType flags + * + * Check if the given storage type is marked as being optical disc + * + * Returns: %TRUE if the storage is marked as optical disc, %FALSE otherwise + */ +#define TRACKER_STORAGE_TYPE_IS_OPTICAL(type) ((type & TRACKER_STORAGE_OPTICAL) ? TRUE : FALSE) + + #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,11 +80,6 @@ struct _TrackerStorageClass { GObjectClass parent_class; }; -typedef enum { - TRACKER_STORAGE_REMOVABLE = 1 << 0, - TRACKER_STORAGE_OPTICAL = 1 << 1 -} TrackerStorageType; - GType tracker_storage_get_type (void) G_GNUC_CONST; TrackerStorage * tracker_storage_new (void); GSList * tracker_storage_get_device_roots (TrackerStorage *storage, @@ -64,7 +92,7 @@ const gchar * tracker_storage_get_mount_point_for_uuid (TrackerStorage const gchar *uuid); TrackerStorageType tracker_storage_get_type_for_uuid (TrackerStorage *storage, const gchar *uuid); -const gchar* tracker_storage_get_uuid_for_file (TrackerStorage *storage, +const gchar * tracker_storage_get_uuid_for_file (TrackerStorage *storage, GFile *file); G_END_DECLS -- cgit v1.2.1 From 9df87bcc926afacf3dea48ccf8254bba93e9faf9 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 1 Jul 2010 09:18:37 +0200 Subject: Fixes GB#623203: Fix segfault when guessing content type in mounts without path --- src/libtracker-miner/tracker-storage.c | 36 ++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index 5eafe42..ed2cf0d 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -350,7 +350,8 @@ static gchar * mount_guess_content_type (GFile *mount_root, GVolume *volume, gboolean *is_optical, - gboolean *is_multimedia) + gboolean *is_multimedia, + gboolean *is_blank) { GUnixMountEntry *entry; gchar *content_type = NULL; @@ -375,15 +376,15 @@ mount_guess_content_type (GFile *mount_root, *is_optical = FALSE; *is_multimedia = FALSE; + *is_blank = FALSE; mount_path = g_file_get_path (mount_root); /* FIXME: Try to assume we have a unix mount :( * EEK, once in a while, I have to write crack, oh well */ - entry = g_unix_mount_at (mount_path, NULL); - - if (entry) { + if (mount_path && + (entry = g_unix_mount_at (mount_path, NULL)) != NULL) { const gchar *filesystem_type; gchar *device_path = NULL; @@ -481,6 +482,7 @@ mount_guess_content_type (GFile *mount_root, !g_strcmp0 (guess_type[i], "x-content/blank-dvd") || !g_strcmp0 (guess_type[i], "x-content/blank-hddvd")) { /* Blank */ + *is_blank = TRUE; content_type = g_strdup (guess_type[i]); break; } else if (!g_strcmp0 (guess_type[i], "x-content/software") || @@ -502,6 +504,12 @@ mount_guess_content_type (GFile *mount_root, g_strfreev (guess_type); } + /* If none of the previous methods worked, return NULL content type and + * set is_blank so that it's not indexed */ + if (!content_type) { + *is_blank = TRUE; + } + return content_type; } @@ -551,20 +559,23 @@ mount_add (TrackerStorage *storage, if (!uuid) { gchar *content_type; gboolean is_multimedia; + gboolean is_blank; /* Optical discs usually won't have UUID in the GVolume */ - content_type = mount_guess_content_type (root, volume, &is_optical, &is_multimedia); + content_type = mount_guess_content_type (root, volume, &is_optical, &is_multimedia, &is_blank); is_removable = TRUE; - /* We don't index content which is video or music, nothing to index */ - if (!is_multimedia) { + /* We don't index content which is video, music or blank */ + if (!is_multimedia && !is_blank) { uuid = g_compute_checksum_for_string (G_CHECKSUM_MD5, mount_name, -1); g_debug (" No UUID, generated:'%s' (based on mount name)", uuid); - g_debug (" Assuming GVolume has removable media, if wrong report a bug!"); + g_debug (" Assuming GVolume has removable media, if wrong report a bug! " + "content type is '%s'", + content_type); } else { - g_debug (" Being ignored because mount is music/video, content type is '%s'", + g_debug (" Being ignored because mount is music/video/blank, content type is '%s'", content_type); } @@ -598,16 +609,17 @@ mount_add (TrackerStorage *storage, if (mount_path) { gchar *content_type; gboolean is_multimedia; + gboolean is_blank; - content_type = mount_guess_content_type (root, volume, &is_optical, &is_multimedia); + content_type = mount_guess_content_type (root, volume, &is_optical, &is_multimedia, &is_blank); - if (!is_multimedia) { + if (!is_multimedia && !is_blank) { uuid = g_compute_checksum_for_string (G_CHECKSUM_MD5, mount_path, -1); g_debug (" No UUID, generated:'%s' (based on mount path)", uuid); } else { - g_debug (" Being ignored because mount is music/video, content type is '%s'", + g_debug (" Being ignored because mount is music/video/blank, content type is '%s'", content_type); } -- cgit v1.2.1 From aaf7c94ae076e17b35c7b81b2713fd02b62f3bef Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 1 Jul 2010 09:25:26 +0200 Subject: libtracker-miner: small alignment fixes --- src/libtracker-miner/tracker-storage.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index ed2cf0d..b57ef4c 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -348,8 +348,8 @@ mount_add_new (TrackerStorage *storage, static gchar * mount_guess_content_type (GFile *mount_root, - GVolume *volume, - gboolean *is_optical, + GVolume *volume, + gboolean *is_optical, gboolean *is_multimedia, gboolean *is_blank) { @@ -791,8 +791,8 @@ get_mount_point_by_uuid_foreach (gpointer key, **/ GSList * tracker_storage_get_device_roots (TrackerStorage *storage, - TrackerStorageType type, - gboolean exact_match) + TrackerStorageType type, + gboolean exact_match) { TrackerStoragePrivate *priv; GetRoots gr; @@ -824,8 +824,8 @@ tracker_storage_get_device_roots (TrackerStorage *storage, **/ GSList * tracker_storage_get_device_uuids (TrackerStorage *storage, - TrackerStorageType type, - gboolean exact_match) + TrackerStorageType type, + gboolean exact_match) { TrackerStoragePrivate *priv; GHashTableIter iter; -- cgit v1.2.1 From 7ec03f16191e399f95abd200501f02728243b78b Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 7 Jul 2010 12:16:38 +0200 Subject: libtracker-miner: avoid dead code in mount_guess_content_type() --- src/libtracker-miner/tracker-storage.c | 89 +++++++++++++++++----------------- 1 file changed, 45 insertions(+), 44 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index b57ef4c..9522bf2 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -357,7 +357,6 @@ mount_guess_content_type (GFile *mount_root, gchar *content_type = NULL; gchar *mount_path; gchar **guess_type; - gint i; /* This function has 2 purposes: * @@ -455,52 +454,54 @@ mount_guess_content_type (GFile *mount_root, * the media. */ guess_type = g_content_type_guess_for_tree (mount_root); + if (guess_type) { + gint i = 0; + + while (!content_type && guess_type[i]) { + if (!g_strcmp0 (guess_type[i], "x-content/image-picturecd")) { + /* Images */ + content_type = g_strdup (guess_type[i]); + } else if (!g_strcmp0 (guess_type[i], "x-content/video-bluray") || + !g_strcmp0 (guess_type[i], "x-content/video-dvd") || + !g_strcmp0 (guess_type[i], "x-content/video-hddvd") || + !g_strcmp0 (guess_type[i], "x-content/video-svcd") || + !g_strcmp0 (guess_type[i], "x-content/video-vcd")) { + /* Videos */ + *is_multimedia = TRUE; + content_type = g_strdup (guess_type[i]); + } else if (!g_strcmp0 (guess_type[i], "x-content/audio-cdda") || + !g_strcmp0 (guess_type[i], "x-content/audio-dvd") || + !g_strcmp0 (guess_type[i], "x-content/audio-player")) { + /* Audios */ + *is_multimedia = TRUE; + content_type = g_strdup (guess_type[i]); + } else if (!g_strcmp0 (guess_type[i], "x-content/blank-bd") || + !g_strcmp0 (guess_type[i], "x-content/blank-cd") || + !g_strcmp0 (guess_type[i], "x-content/blank-dvd") || + !g_strcmp0 (guess_type[i], "x-content/blank-hddvd")) { + /* Blank */ + *is_blank = TRUE; + content_type = g_strdup (guess_type[i]); + } else if (!g_strcmp0 (guess_type[i], "x-content/software") || + !g_strcmp0 (guess_type[i], "x-content/unix-software") || + !g_strcmp0 (guess_type[i], "x-content/win32-software")) { + /* NOTE: This one is a guess, can we + * have this content type on + * none-optical mount points? + */ + content_type = g_strdup (guess_type[i]); + } else { + /* else, keep on with the next guess, if any */ + i++; + } + } - for (i = 0; guess_type && guess_type[i]; i++) { - if (!g_strcmp0 (guess_type[i], "x-content/image-picturecd")) { - /* Images */ - content_type = g_strdup (guess_type[i]); - break; - } else if (!g_strcmp0 (guess_type[i], "x-content/video-bluray") || - !g_strcmp0 (guess_type[i], "x-content/video-dvd") || - !g_strcmp0 (guess_type[i], "x-content/video-hddvd") || - !g_strcmp0 (guess_type[i], "x-content/video-svcd") || - !g_strcmp0 (guess_type[i], "x-content/video-vcd")) { - /* Videos */ - *is_multimedia = TRUE; - content_type = g_strdup (guess_type[i]); - break; - } else if (!g_strcmp0 (guess_type[i], "x-content/audio-cdda") || - !g_strcmp0 (guess_type[i], "x-content/audio-dvd") || - !g_strcmp0 (guess_type[i], "x-content/audio-player")) { - /* Audios */ - *is_multimedia = TRUE; - content_type = g_strdup (guess_type[i]); - break; - } else if (!g_strcmp0 (guess_type[i], "x-content/blank-bd") || - !g_strcmp0 (guess_type[i], "x-content/blank-cd") || - !g_strcmp0 (guess_type[i], "x-content/blank-dvd") || - !g_strcmp0 (guess_type[i], "x-content/blank-hddvd")) { - /* Blank */ - *is_blank = TRUE; - content_type = g_strdup (guess_type[i]); - break; - } else if (!g_strcmp0 (guess_type[i], "x-content/software") || - !g_strcmp0 (guess_type[i], "x-content/unix-software") || - !g_strcmp0 (guess_type[i], "x-content/win32-software")) { - /* NOTE: This one is a guess, can we - * have this content type on - * none-optical mount points? - */ - content_type = g_strdup (guess_type[i]); - break; - } else if (!content_type) { - content_type = g_strdup (guess_type[i]); - break; + /* If we didn't have an exact match on possible guessed content types, + * then use the first one returned (best guess always first) if any */ + if (!content_type && guess_type[0]) { + content_type = g_strdup (guess_type[0]); } - } - if (guess_type) { g_strfreev (guess_type); } -- cgit v1.2.1 From 4522e442692124b3345d08b47b4f8d3df67a382b Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 8 Jul 2010 11:55:00 +0200 Subject: libtracker-miner, storage: improve logging --- src/libtracker-miner/tracker-storage.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index 9522bf2..20550bf 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -620,8 +620,12 @@ mount_add (TrackerStorage *storage, -1); g_debug (" No UUID, generated:'%s' (based on mount path)", uuid); } else { - g_debug (" Being ignored because mount is music/video/blank, content type is '%s'", - content_type); + g_debug (" Being ignored because mount is music/video/blank " + "(content type:%s, optical:%s, multimedia:%s, blank:%s)", + content_type, + is_optical ? "yes" : "no", + is_multimedia ? "yes" : "no", + is_blank ? "yes" : "no"); } g_free (content_type); -- cgit v1.2.1 From c5ba4bc5c2a558a9918cf3bb963eecc96b9f9683 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 8 Jul 2010 12:10:46 +0200 Subject: libtracker-miner, storage: if mount without volume, don't rely on is_blank --- src/libtracker-miner/tracker-storage.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index 20550bf..896ed40 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -576,8 +576,12 @@ mount_add (TrackerStorage *storage, "content type is '%s'", content_type); } else { - g_debug (" Being ignored because mount is music/video/blank, content type is '%s'", - content_type); + g_debug (" Being ignored because mount with volume is music/video/blank " + "(content type:%s, optical:%s, multimedia:%s, blank:%s)", + content_type, + is_optical ? "yes" : "no", + is_multimedia ? "yes" : "no", + is_blank ? "yes" : "no"); } g_free (content_type); @@ -614,18 +618,19 @@ mount_add (TrackerStorage *storage, content_type = mount_guess_content_type (root, volume, &is_optical, &is_multimedia, &is_blank); - if (!is_multimedia && !is_blank) { + /* Note: for GMounts without GVolume, is_blank should NOT be considered, + * as it may give unwanted results... */ + if (!is_multimedia) { uuid = g_compute_checksum_for_string (G_CHECKSUM_MD5, mount_path, -1); g_debug (" No UUID, generated:'%s' (based on mount path)", uuid); } else { - g_debug (" Being ignored because mount is music/video/blank " - "(content type:%s, optical:%s, multimedia:%s, blank:%s)", + g_debug (" Being ignored because mount is music/video " + "(content type:%s, optical:%s, multimedia:%s)", content_type, is_optical ? "yes" : "no", - is_multimedia ? "yes" : "no", - is_blank ? "yes" : "no"); + is_multimedia ? "yes" : "no"); } g_free (content_type); -- cgit v1.2.1 From 98d053513d5df8f7f61fc3a1c9df140c858a0ee0 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 16 Jul 2010 16:56:50 +0200 Subject: libtracker-miner, storage: Fix memleak, GUnixMountEntry was not being disposed --- src/libtracker-miner/tracker-storage.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index 896ed40..625b4ca 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -441,6 +441,7 @@ mount_guess_content_type (GFile *mount_root, g_free (device_path); g_free (mount_path); + g_unix_mount_free (entry); } else { g_debug (" No GUnixMountEntry found, needed for detecting if optical media... :("); g_free (mount_path); -- cgit v1.2.1 From 42554b39f05404f3239e68c9c643a26f9055aaf2 Mon Sep 17 00:00:00 2001 From: Martyn Russell Date: Wed, 8 Dec 2010 12:25:05 +0000 Subject: libtracker-miner: Cleaned up documentation Cleaned up several warnings during the build and missing documentation too --- src/libtracker-miner/tracker-storage.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/libtracker-miner/tracker-storage.h b/src/libtracker-miner/tracker-storage.h index 3ac584f..9970edf 100644 --- a/src/libtracker-miner/tracker-storage.h +++ b/src/libtracker-miner/tracker-storage.h @@ -72,10 +72,22 @@ typedef enum { typedef struct _TrackerStorage TrackerStorage; typedef struct _TrackerStorageClass TrackerStorageClass; +/** + * TrackerStorage: + * @parent: parent object + * + * A storage API for using mount points and devices + **/ struct _TrackerStorage { GObject parent; }; +/** + * TrackerStorageClass: + * @parent_class: parent object class + * + * A storage class for #TrackerStorage. + **/ struct _TrackerStorageClass { GObjectClass parent_class; }; -- cgit v1.2.1 From e7acfa5ace35b4c2c54df249a2709db298161a9e Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 8 Feb 2011 13:56:33 +0100 Subject: docs, libtracker-miner: Added missing 'Since:' tags --- src/libtracker-miner/tracker-storage.c | 12 ++++++++++++ src/libtracker-miner/tracker-storage.h | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index 625b4ca..edd316b 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -748,6 +748,8 @@ mount_removed_cb (GVolumeMonitor *monitor, * Creates a new instance of #TrackerStorage. * * Returns: The newly created #TrackerStorage. + * + * Since: 0.8 **/ TrackerStorage * tracker_storage_new (void) @@ -799,6 +801,8 @@ get_mount_point_by_uuid_foreach (gpointer key, * Returns: a #GSList of strings containing the root directories for * devices with @type based on @exact_match. Each element must be * freed using g_free() and the list itself through g_slist_free(). + * + * Since: 0.8 **/ GSList * tracker_storage_get_device_roots (TrackerStorage *storage, @@ -832,6 +836,8 @@ tracker_storage_get_device_roots (TrackerStorage *storage, * Returns: a #GSList of strings containing the UUID for devices with * @type based on @exact_match. Each element must be freed using * g_free() and the list itself through g_slist_free(). + * + * Since: 0.8 **/ GSList * tracker_storage_get_device_uuids (TrackerStorage *storage, @@ -879,6 +885,8 @@ tracker_storage_get_device_uuids (TrackerStorage *storage, * @uuid: A string pointer to the UUID for the %GVolume. * * Returns: The mount point for @uuid, this should not be freed. + * + * Since: 0.8 **/ const gchar * tracker_storage_get_mount_point_for_uuid (TrackerStorage *storage, @@ -910,6 +918,8 @@ tracker_storage_get_mount_point_for_uuid (TrackerStorage *storage, * @uuid: A string pointer to the UUID for the %GVolume. * * Returns: The type flags for @uuid. + * + * Since: 0.10 **/ TrackerStorageType tracker_storage_get_type_for_uuid (TrackerStorage *storage, @@ -951,6 +961,8 @@ tracker_storage_get_type_for_uuid (TrackerStorage *storage, * * Returns: Returns the UUID of the removable device for @file, this * should not be freed. + * + * Since: 0.8 **/ const gchar * tracker_storage_get_uuid_for_file (TrackerStorage *storage, diff --git a/src/libtracker-miner/tracker-storage.h b/src/libtracker-miner/tracker-storage.h index 9970edf..f3101c0 100644 --- a/src/libtracker-miner/tracker-storage.h +++ b/src/libtracker-miner/tracker-storage.h @@ -35,6 +35,8 @@ G_BEGIN_DECLS * @TRACKER_STORAGE_OPTICAL: Storage is an optical disc * * Flags specifying properties of the type of storage. + * + * Since: 0.8 */ typedef enum { TRACKER_STORAGE_REMOVABLE = 1 << 0, @@ -48,6 +50,8 @@ typedef enum { * Check if the given storage type is marked as being removable media. * * Returns: %TRUE if the storage is marked as removable media, %FALSE otherwise + * + * Since: 0.10 */ #define TRACKER_STORAGE_TYPE_IS_REMOVABLE(type) ((type & TRACKER_STORAGE_REMOVABLE) ? TRUE : FALSE) @@ -58,6 +62,8 @@ typedef enum { * Check if the given storage type is marked as being optical disc * * Returns: %TRUE if the storage is marked as optical disc, %FALSE otherwise + * + * Since: 0.10 */ #define TRACKER_STORAGE_TYPE_IS_OPTICAL(type) ((type & TRACKER_STORAGE_OPTICAL) ? TRUE : FALSE) -- cgit v1.2.1 From e9d14e0d0abf2f7a41c2aa2a1717c503ba56a971 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Mon, 14 Feb 2011 14:12:12 +0100 Subject: libtracker-miner,storage: Use g_mount_guess_content_type() to guess mountpoints' contents This function will detect content type properly for the different optical media types, ensuring a NULL content type just means it contains data. The is_optical check is still done aside, based on the content type, or the unix device. Fixes bug #642014 - Tracker cannot index optical data disc's data, reported by Simon Hong. --- src/libtracker-miner/tracker-storage.c | 198 +++++++++++++++++---------------- 1 file changed, 101 insertions(+), 97 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index edd316b..efc8f8f 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -347,114 +347,32 @@ mount_add_new (TrackerStorage *storage, } static gchar * -mount_guess_content_type (GFile *mount_root, - GVolume *volume, +mount_guess_content_type (GMount *mount, gboolean *is_optical, gboolean *is_multimedia, gboolean *is_blank) { - GUnixMountEntry *entry; gchar *content_type = NULL; - gchar *mount_path; gchar **guess_type; - /* This function has 2 purposes: - * - * 1. Detect if we are using optical media - * 2. Detect if we are video or music, we can't index those types - */ - - if (g_file_has_uri_scheme (mount_root, "cdda")) { - g_debug (" Scheme is CDDA, assuming this is a CD"); - - *is_optical = TRUE; - *is_multimedia = TRUE; - - return g_strdup ("x-content/audio-cdda"); - } - *is_optical = FALSE; *is_multimedia = FALSE; *is_blank = FALSE; - mount_path = g_file_get_path (mount_root); - - /* FIXME: Try to assume we have a unix mount :( - * EEK, once in a while, I have to write crack, oh well - */ - if (mount_path && - (entry = g_unix_mount_at (mount_path, NULL)) != NULL) { - const gchar *filesystem_type; - gchar *device_path = NULL; - - filesystem_type = g_unix_mount_get_fs_type (entry); - g_debug (" Using filesystem type:'%s'", - filesystem_type); - - /* Volume may be NULL */ - if (volume) { - device_path = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); - g_debug (" Using device path:'%s'", - device_path); - } - - /* NOTE: This code was taken from guess_mount_type() - * in GIO's gunixmounts.c and adapted purely for - * guessing optical media. We don't use the guessing - * code for other types such as MEMSTICKS, ZIPs, - * IPODs, etc. - * - * This code may need updating over time since it is - * very situational depending on how distributions - * mount their devices and how devices are named in - * /dev. - */ - if (strcmp (filesystem_type, "udf") == 0 || - strcmp (filesystem_type, "iso9660") == 0 || - strcmp (filesystem_type, "cd9660") == 0 || - (device_path && - (g_str_has_prefix (device_path, "/dev/cdrom") || - g_str_has_prefix (device_path, "/dev/acd") || - g_str_has_prefix (device_path, "/dev/cd")))) { - *is_optical = TRUE; - } else if (device_path && - g_str_has_prefix (device_path, "/vol/")) { - const gchar *name; - - name = mount_path + strlen ("/"); - - if (g_str_has_prefix (name, "cdrom")) { - *is_optical = TRUE; - } - } else { - gchar *basename = g_path_get_basename (mount_path); - - if (g_str_has_prefix (basename, "cdr") || - g_str_has_prefix (basename, "cdwriter") || - g_str_has_prefix (basename, "burn") || - g_str_has_prefix (basename, "dvdr")) { - *is_optical = TRUE; - } - - g_free (basename); - } - - g_free (device_path); - g_free (mount_path); - g_unix_mount_free (entry); - } else { - g_debug (" No GUnixMountEntry found, needed for detecting if optical media... :("); - g_free (mount_path); - } - - /* We try to determine the content type because we don't want + /* This function has 2 purposes: + * + * 1. Detect if we are using optical media + * 2. Detect if we are video or music, we can't index those types + * + * We try to determine the content type because we don't want * to store Volume information in Tracker about DVDs and media * which has no real data for us to mine. * * Generally, if is_multimedia is TRUE then we end up ignoring * the media. */ - guess_type = g_content_type_guess_for_tree (mount_root); + guess_type = g_mount_guess_content_type_sync (mount, TRUE, NULL, NULL); + if (guess_type) { gint i = 0; @@ -506,10 +424,96 @@ mount_guess_content_type (GFile *mount_root, g_strfreev (guess_type); } - /* If none of the previous methods worked, return NULL content type and - * set is_blank so that it's not indexed */ - if (!content_type) { - *is_blank = TRUE; + if (content_type) { + if (strstr (content_type, "vcd") || + strstr (content_type, "cdda") || + strstr (content_type, "dvd") || + strstr (content_type, "bluray")) { + *is_optical = TRUE; + } + } else { + GUnixMountEntry *entry; + gchar *mount_path; + GFile *mount_root; + + /* No content type was guessed, try to find out + * at least whether it's an optical media or not + */ + mount_root = g_mount_get_root (mount); + mount_path = g_file_get_path (mount_root); + + /* FIXME: Try to assume we have a unix mount :( + * EEK, once in a while, I have to write crack, oh well + */ + if (mount_path && + (entry = g_unix_mount_at (mount_path, NULL)) != NULL) { + const gchar *filesystem_type; + gchar *device_path = NULL; + GVolume *volume; + + volume = g_mount_get_volume (mount); + filesystem_type = g_unix_mount_get_fs_type (entry); + g_debug (" Using filesystem type:'%s'", + filesystem_type); + + /* Volume may be NULL */ + if (volume) { + device_path = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); + g_debug (" Using device path:'%s'", + device_path); + g_object_unref (volume); + } + + /* NOTE: This code was taken from guess_mount_type() + * in GIO's gunixmounts.c and adapted purely for + * guessing optical media. We don't use the guessing + * code for other types such as MEMSTICKS, ZIPs, + * IPODs, etc. + * + * This code may need updating over time since it is + * very situational depending on how distributions + * mount their devices and how devices are named in + * /dev. + */ + if (strcmp (filesystem_type, "udf") == 0 || + strcmp (filesystem_type, "iso9660") == 0 || + strcmp (filesystem_type, "cd9660") == 0 || + (device_path && + (g_str_has_prefix (device_path, "/dev/cdrom") || + g_str_has_prefix (device_path, "/dev/acd") || + g_str_has_prefix (device_path, "/dev/cd")))) { + *is_optical = TRUE; + } else if (device_path && + g_str_has_prefix (device_path, "/vol/")) { + const gchar *name; + + name = mount_path + strlen ("/"); + + if (g_str_has_prefix (name, "cdrom")) { + *is_optical = TRUE; + } + } else { + gchar *basename = g_path_get_basename (mount_path); + + if (g_str_has_prefix (basename, "cdr") || + g_str_has_prefix (basename, "cdwriter") || + g_str_has_prefix (basename, "burn") || + g_str_has_prefix (basename, "dvdr")) { + *is_optical = TRUE; + } + + g_free (basename); + } + + g_free (device_path); + g_free (mount_path); + g_unix_mount_free (entry); + } else { + g_debug (" No GUnixMountEntry found, needed for detecting if optical media... :("); + g_free (mount_path); + } + + g_object_unref (mount_root); } return content_type; @@ -564,7 +568,7 @@ mount_add (TrackerStorage *storage, gboolean is_blank; /* Optical discs usually won't have UUID in the GVolume */ - content_type = mount_guess_content_type (root, volume, &is_optical, &is_multimedia, &is_blank); + content_type = mount_guess_content_type (mount, &is_optical, &is_multimedia, &is_blank); is_removable = TRUE; /* We don't index content which is video, music or blank */ @@ -617,7 +621,7 @@ mount_add (TrackerStorage *storage, gboolean is_multimedia; gboolean is_blank; - content_type = mount_guess_content_type (root, volume, &is_optical, &is_multimedia, &is_blank); + content_type = mount_guess_content_type (mount, &is_optical, &is_multimedia, &is_blank); /* Note: for GMounts without GVolume, is_blank should NOT be considered, * as it may give unwanted results... */ -- cgit v1.2.1 From ff0903194befc5cf0f9fe7d4efa07237cf54fdeb Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 15 Feb 2011 10:32:18 +0100 Subject: libtracker-miner,storage: Fix indentation/alignment --- src/libtracker-miner/tracker-storage.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index efc8f8f..7a83692 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -454,13 +454,13 @@ mount_guess_content_type (GMount *mount, volume = g_mount_get_volume (mount); filesystem_type = g_unix_mount_get_fs_type (entry); g_debug (" Using filesystem type:'%s'", - filesystem_type); + filesystem_type); /* Volume may be NULL */ if (volume) { device_path = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); g_debug (" Using device path:'%s'", - device_path); + device_path); g_object_unref (volume); } @@ -484,7 +484,7 @@ mount_guess_content_type (GMount *mount, g_str_has_prefix (device_path, "/dev/cd")))) { *is_optical = TRUE; } else if (device_path && - g_str_has_prefix (device_path, "/vol/")) { + g_str_has_prefix (device_path, "/vol/")) { const gchar *name; name = mount_path + strlen ("/"); @@ -539,7 +539,7 @@ mount_add (TrackerStorage *storage, g_debug ("Found '%s' mounted on path '%s'", mount_name, - mount_path); + mount_path); /* Do not process shadowed mounts! */ if (g_mount_is_shadowed (mount)) { @@ -574,8 +574,8 @@ mount_add (TrackerStorage *storage, /* We don't index content which is video, music or blank */ if (!is_multimedia && !is_blank) { uuid = g_compute_checksum_for_string (G_CHECKSUM_MD5, - mount_name, - -1); + mount_name, + -1); g_debug (" No UUID, generated:'%s' (based on mount name)", uuid); g_debug (" Assuming GVolume has removable media, if wrong report a bug! " "content type is '%s'", @@ -627,8 +627,8 @@ mount_add (TrackerStorage *storage, * as it may give unwanted results... */ if (!is_multimedia) { uuid = g_compute_checksum_for_string (G_CHECKSUM_MD5, - mount_path, - -1); + mount_path, + -1); g_debug (" No UUID, generated:'%s' (based on mount path)", uuid); } else { g_debug (" Being ignored because mount is music/video " -- cgit v1.2.1 From 8841c7905a08eb5a7c3469f6d6ce3be3756b716d Mon Sep 17 00:00:00 2001 From: Lionel Landwerlin Date: Fri, 28 Jan 2011 16:33:12 +0000 Subject: libtracker-miner,storage: do not rely on g_drive_is_media_removable() Fixes GB#640845 We don't want to rely on the g_drive_is_media_removable() method because it does not tell us whether a device can be disconnected from the system but rather if a device contains a media that might be extracted from it. In fact, this method maps the removable flag from the kernel block device subsystem. If we rely on g_drive_is_media_removable(), most of the USB harddrives are considered as non removable, and are therefor won't be indexed. This patch proposes to check whether or not the mount point is part of the system, and if it's not, we use g_volume_can_mount() method to check whether the filesystem can be mounted which gives us a better clue about whether the related device is removable or not (in the way tracker considers a device from being removable). Signed-off-by: Lionel Landwerlin --- src/libtracker-miner/tracker-storage.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index 7a83692..3fc5c4c 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -591,21 +591,28 @@ mount_add (TrackerStorage *storage, g_free (content_type); } else { - /* Any other removable media will have UUID in the GVolume. - * Note that this also may include some partitions in the machine - * which have GVolumes associated to the GMounts. So, we need to - * explicitly check if the drive is media-removable (machine - * partitions won't be media-removable) */ + /* Any other removable media will have UUID in the + * GVolume. Note that this also may include some + * partitions in the machine which have GVolumes + * associated to the GMounts. We also check a drive + * exists to be sure the device is local. */ GDrive *drive; drive = g_volume_get_drive (volume); + if (drive) { - is_removable = g_drive_is_media_removable (drive); + /* We can't mount/unmount system volumes, so tag + * them as non removable. */ + if (g_volume_can_mount (volume)) { + is_removable = TRUE; + } else { + is_removable = FALSE; + } g_object_unref (drive); } else { /* Note: not sure when this can happen... */ g_debug (" Assuming GDrive has removable media, if wrong report a bug!"); - is_removable = TRUE; + is_removable = FALSE; } } -- cgit v1.2.1 From d1fa9c286442dca994eddfd73ca659976b8e19ae Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 17 Feb 2011 12:23:36 +0100 Subject: libtracker-miner,storage: Improve logging --- src/libtracker-miner/tracker-storage.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index 3fc5c4c..f97223e 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -603,15 +603,17 @@ mount_add (TrackerStorage *storage, if (drive) { /* We can't mount/unmount system volumes, so tag * them as non removable. */ - if (g_volume_can_mount (volume)) { - is_removable = TRUE; - } else { - is_removable = FALSE; - } + is_removable = g_volume_can_mount (volume); + g_debug (" Found mount with volume and drive which %s be mounted: " + "Assuming it's %s removable, if wrong report a bug!", + is_removable ? "can" : "cannot", + is_removable ? "" : "not"); g_object_unref (drive); } else { /* Note: not sure when this can happen... */ - g_debug (" Assuming GDrive has removable media, if wrong report a bug!"); + g_debug (" Mount with volume but no drive, " + "assuming not a removable device, " + "if wrong report a bug!"); is_removable = FALSE; } } -- cgit v1.2.1 From 1bc2af04441a5d64173b1d67be01268269f088d0 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 17 Feb 2011 16:58:57 +0100 Subject: libtracker-miner,storage: Skip mount points without mount path --- src/libtracker-miner/tracker-storage.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index f97223e..b80ccb6 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -650,19 +650,25 @@ mount_add (TrackerStorage *storage, g_free (content_type); } else { g_debug (" Being ignored because mount has no GVolume (i.e. not user mountable) " - "and has mount root path available"); + "and has no mount root path available"); } } } /* If we got something to be used as UUID, then add the mount * to the TrackerStorage */ - if (uuid && !g_hash_table_lookup (priv->mounts_by_uuid, uuid)) { - g_debug (" Adding mount point with UUID:'%s', removable: %s, optical: %s", + if (uuid && mount_path && !g_hash_table_lookup (priv->mounts_by_uuid, uuid)) { + g_debug (" Adding mount point with UUID: '%s', removable: %s, optical: %s, path: '%s'", uuid, is_removable ? "yes" : "no", - is_optical ? "yes" : "no"); + is_optical ? "yes" : "no", + mount_path); mount_add_new (storage, uuid, mount_path, is_removable, is_optical); + } else { + g_debug (" Skipping mount point with UUID: '%s', path: '%s', already managed: '%s'", + uuid ? uuid : "none", + mount_path ? mount_path : "none", + (uuid && g_hash_table_lookup (priv->mounts_by_uuid, uuid)) ? "yes" : "no"); } g_free (mount_name); -- cgit v1.2.1 From 6b0f350a99352908a7fd8387d845d08b1a1dfb12 Mon Sep 17 00:00:00 2001 From: Lionel Landwerling Date: Mon, 28 Feb 2011 17:00:13 +0200 Subject: libtracker-miner: Add mount-name to tracker:Volume as nie:title Author: Lionel Landwerling --- src/libtracker-miner/tracker-storage.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index b80ccb6..0630f2a 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -104,11 +104,12 @@ tracker_storage_class_init (TrackerStorageClass *klass) G_SIGNAL_RUN_LAST, 0, NULL, NULL, - tracker_marshal_VOID__STRING_STRING_BOOLEAN_BOOLEAN, + tracker_marshal_VOID__STRING_STRING_STRING_BOOLEAN_BOOLEAN, G_TYPE_NONE, - 4, + 5, G_TYPE_STRING, G_TYPE_STRING, + G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN); @@ -325,6 +326,7 @@ static void mount_add_new (TrackerStorage *storage, const gchar *uuid, const gchar *mount_point, + const gchar *mount_name, gboolean removable_device, gboolean optical_disc) { @@ -341,6 +343,7 @@ mount_add_new (TrackerStorage *storage, 0, uuid, mount_point, + mount_name, removable_device, optical_disc, NULL); @@ -663,7 +666,7 @@ mount_add (TrackerStorage *storage, is_removable ? "yes" : "no", is_optical ? "yes" : "no", mount_path); - mount_add_new (storage, uuid, mount_path, is_removable, is_optical); + mount_add_new (storage, 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", -- cgit v1.2.1 From 9eed9cff52b4b2f054659651aaee06dc3acc4f72 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Mon, 4 Apr 2011 15:17:04 +0200 Subject: libtracker-miner: Add introspection annotation to docs. --- src/libtracker-miner/tracker-storage.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index 0630f2a..f874aba 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -820,9 +820,10 @@ get_mount_point_by_uuid_foreach (gpointer key, * @type: A #TrackerStorageType * @exact_match: if all devices should exactly match the types * - * Returns: a #GSList of strings containing the root directories for - * devices with @type based on @exact_match. Each element must be - * freed using g_free() and the list itself through g_slist_free(). + * Returns: (transfer full) (element-type utf8): a #GSList of strings + * containing the root directories for devices with @type based on + * @exact_match. Each element must be freed using g_free() and the + * list itself through g_slist_free(). * * Since: 0.8 **/ @@ -855,9 +856,10 @@ tracker_storage_get_device_roots (TrackerStorage *storage, * @type: A #TrackerStorageType * @exact_match: if all devices should exactly match the types * - * Returns: a #GSList of strings containing the UUID for devices with - * @type based on @exact_match. Each element must be freed using - * g_free() and the list itself through g_slist_free(). + * Returns: (transfer full) (element-type utf8): a #GSList of + * strings containing the UUID for devices with @type based + * on @exact_match. Each element must be freed using g_free() + * and the list itself through g_slist_free(). * * Since: 0.8 **/ -- cgit v1.2.1 From 36b501bf4e4a430fb86e47535d048362f487b5e3 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Mon, 9 May 2011 14:47:41 +0200 Subject: libtracker-miner: Add watchdog for failed unmounts Fixes NB#248873. If, for whatever reason, an unmount operation fails or doesn't respond in a timely fashion, TrackerStorage will emit ::mount-point-added again so Tracker keeps monitoring any further change in there. --- src/libtracker-miner/tracker-storage.c | 89 +++++++++++++++++++++++++++++++--- 1 file changed, 83 insertions(+), 6 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index f874aba..d30dc0f 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -47,11 +47,13 @@ typedef struct { GNode *mounts; GHashTable *mounts_by_uuid; + GHashTable *unmount_watchdogs; } TrackerStoragePrivate; typedef struct { gchar *mount_point; gchar *uuid; + guint unmount_timer_id; guint removable : 1; guint optical : 1; } MountInfo; @@ -67,6 +69,11 @@ typedef struct { gboolean exact_match; } GetRoots; +typedef struct { + TrackerStorage *storage; + GMount *mount; +} UnmountCheckData; + static void tracker_storage_finalize (GObject *object); static gboolean mount_info_free (GNode *node, gpointer user_data); @@ -78,6 +85,9 @@ static void mount_added_cb (GVolumeMonitor *monitor, static void mount_removed_cb (GVolumeMonitor *monitor, GMount *mount, gpointer user_data); +static void mount_pre_removed_cb (GVolumeMonitor *monitor, + GMount *mount, + gpointer user_data); enum { MOUNT_POINT_ADDED, @@ -143,6 +153,8 @@ tracker_storage_init (TrackerStorage *storage) g_str_equal, (GDestroyNotify) g_free, NULL); + priv->unmount_watchdogs = g_hash_table_new_full (NULL, NULL, NULL, + (GDestroyNotify) g_source_remove); priv->volume_monitor = g_volume_monitor_get (); @@ -150,7 +162,7 @@ tracker_storage_init (TrackerStorage *storage) 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_CALLBACK (mount_pre_removed_cb), storage, 0); g_signal_connect_object (priv->volume_monitor, "mount-added", G_CALLBACK (mount_added_cb), storage, 0); @@ -169,6 +181,8 @@ tracker_storage_finalize (GObject *object) priv = TRACKER_STORAGE_GET_PRIVATE (object); + g_hash_table_destroy (priv->unmount_watchdogs); + if (priv->mounts_by_uuid) { g_hash_table_unref (priv->mounts_by_uuid); } @@ -717,11 +731,9 @@ mount_added_cb (GVolumeMonitor *monitor, } static void -mount_removed_cb (GVolumeMonitor *monitor, - GMount *mount, - gpointer user_data) +mount_remove (TrackerStorage *storage, + GMount *mount) { - TrackerStorage *storage; TrackerStoragePrivate *priv; MountInfo *info; GNode *node; @@ -730,7 +742,6 @@ mount_removed_cb (GVolumeMonitor *monitor, gchar *mount_point; gchar *mp; - storage = user_data; priv = TRACKER_STORAGE_GET_PRIVATE (storage); file = g_mount_get_root (mount); @@ -764,6 +775,72 @@ mount_removed_cb (GVolumeMonitor *monitor, g_object_unref (file); } +static void +mount_removed_cb (GVolumeMonitor *monitor, + GMount *mount, + gpointer user_data) +{ + TrackerStorage *storage; + TrackerStoragePrivate *priv; + + storage = user_data; + priv = TRACKER_STORAGE_GET_PRIVATE (storage); + + mount_remove (storage, mount); + + /* Unmount suceeded, remove the pending check */ + g_hash_table_remove (priv->unmount_watchdogs, mount); +} + +static gboolean +unmount_failed_cb (gpointer user_data) +{ + UnmountCheckData *data = user_data; + TrackerStoragePrivate *priv; + + /* If this timeout gets to be executed, this is due + * to a pre-unmount signal with no corresponding + * unmount in a timely fashion, we assume this is + * due to an error, and add back the still mounted + * path. + */ + priv = TRACKER_STORAGE_GET_PRIVATE (data->storage); + + g_warning ("Unmount operation failed, adding back mount point..."); + + mount_add (data->storage, data->mount); + + g_hash_table_remove (priv->unmount_watchdogs, data->mount); + return FALSE; +} + +static void +mount_pre_removed_cb (GVolumeMonitor *monitor, + GMount *mount, + gpointer user_data) +{ + TrackerStorage *storage; + TrackerStoragePrivate *priv; + UnmountCheckData *data; + guint id; + + storage = user_data; + priv = TRACKER_STORAGE_GET_PRIVATE (storage); + + mount_remove (storage, mount); + + /* Add check for failed unmounts */ + data = g_new (UnmountCheckData, 1); + data->storage = storage; + data->mount = mount; + + id = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, 1, + unmount_failed_cb, + data, (GDestroyNotify) g_free); + g_hash_table_insert (priv->unmount_watchdogs, data->mount, + GUINT_TO_POINTER (id)); +} + /** * tracker_storage_new: * -- cgit v1.2.1 From 37d0191f6143341518571421daa1698839291ff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Billeter?= Date: Thu, 12 May 2011 16:29:05 +0200 Subject: libtracker-miner: Fix C warnings --- src/libtracker-miner/tracker-storage.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index d30dc0f..319a5eb 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -862,13 +862,11 @@ get_mount_point_by_uuid_foreach (gpointer key, gpointer user_data) { GetRoots *gr; - const gchar *uuid; GNode *node; MountInfo *info; TrackerStorageType mount_type; gr = user_data; - uuid = key; node = value; info = node->data; mount_type = mount_info_get_type (info); -- cgit v1.2.1 From 6433b020c6d4a8e8d9f69ccb7666cb1a92a4622a Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Mon, 23 May 2011 17:20:42 +0200 Subject: libtracker-miner: Make the failed unmounts watchdog more relaxed The timeout priority is now lower so ::mount-unmount has a chance to be processed before the watchdog if the miner's main loop is busy (say removing monitors). Also, the timeout is longer so we aren't overzealous on slow unmounts. --- src/libtracker-miner/tracker-storage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c index 319a5eb..bbf771d 100644 --- a/src/libtracker-miner/tracker-storage.c +++ b/src/libtracker-miner/tracker-storage.c @@ -834,7 +834,7 @@ mount_pre_removed_cb (GVolumeMonitor *monitor, data->storage = storage; data->mount = mount; - id = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, 1, + id = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT_IDLE + 10, 3, unmount_failed_cb, data, (GDestroyNotify) g_free); g_hash_table_insert (priv->unmount_watchdogs, data->mount, -- cgit v1.2.1 From c2fcedd9d199ff27f68a6a9e303c519954712d99 Mon Sep 17 00:00:00 2001 From: "Arnel A. Borja" Date: Sat, 31 Aug 2013 00:57:00 +0800 Subject: build: Move tracker-storage to libmediaart --- libmediaart/Makefile.am | 5 +- libmediaart/tracker-storage.c | 1104 +++++++++++++++++++++++++++++++ libmediaart/tracker-storage.h | 114 ++++ src/libtracker-miner/tracker-storage.c | 1107 -------------------------------- src/libtracker-miner/tracker-storage.h | 118 ---- 5 files changed, 1222 insertions(+), 1226 deletions(-) create mode 100644 libmediaart/tracker-storage.c create mode 100644 libmediaart/tracker-storage.h delete mode 100644 src/libtracker-miner/tracker-storage.c delete mode 100644 src/libtracker-miner/tracker-storage.h diff --git a/libmediaart/Makefile.am b/libmediaart/Makefile.am index 00c8d0e..55931c1 100644 --- a/libmediaart/Makefile.am +++ b/libmediaart/Makefile.am @@ -25,7 +25,10 @@ libmediaartinclude_HEADERS = \ extract.h \ extractgeneric.h -libmediaart_@LIBMEDIAART_API_VERSION@_la_SOURCES = $(libmediaart_sources) +libmediaart_@LIBMEDIAART_API_VERSION@_la_SOURCES = \ + $(libmediaart_sources) \ + tracker-storage.c \ + tracker-storage.h if HAVE_GDKPIXBUF libmediaart_@LIBMEDIAART_API_VERSION@_la_SOURCES += extractpixbuf.c diff --git a/libmediaart/tracker-storage.c b/libmediaart/tracker-storage.c new file mode 100644 index 0000000..bd83940 --- /dev/null +++ b/libmediaart/tracker-storage.c @@ -0,0 +1,1104 @@ +/* + * Copyright (C) 2008, Nokia + * + * 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 + +#include +#include + +#include "tracker-storage.h" +#include "tracker-marshal.h" + +/** + * SECTION:tracker-storage + * @short_description: Removable storage and mount point convenience API + * @include: libtracker-miner/tracker-miner.h + * + * This API is a convenience to to be able to keep track of volumes + * which are mounted and also the type of removable media available. + * The API is built upon the top of GIO's #GMount, #GDrive and #GVolume API. + **/ + +#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; + GHashTable *unmount_watchdogs; +} TrackerStoragePrivate; + +typedef struct { + gchar *mount_point; + gchar *uuid; + guint unmount_timer_id; + guint removable : 1; + guint optical : 1; +} MountInfo; + +typedef struct { + const gchar *path; + GNode *node; +} TraverseData; + +typedef struct { + GSList *roots; + TrackerStorageType type; + gboolean exact_match; +} GetRoots; + +typedef struct { + TrackerStorage *storage; + GMount *mount; +} UnmountCheckData; + +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 mounts_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 mount_pre_removed_cb (GVolumeMonitor *monitor, + GMount *mount, + 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_STRING_BOOLEAN_BOOLEAN, + G_TYPE_NONE, + 5, + G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_BOOLEAN, + G_TYPE_BOOLEAN); + + 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->unmount_watchdogs = g_hash_table_new_full (NULL, NULL, NULL, + (GDestroyNotify) g_source_remove); + + 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_pre_removed_cb), storage, 0); + g_signal_connect_object (priv->volume_monitor, "mount-added", + G_CALLBACK (mount_added_cb), storage, 0); + + g_message ("Mount monitors set up for to watch for added, removed and pre-unmounts..."); + + /* Get all mounts and set them up */ + if (!mounts_setup (storage)) { + return; + } +} + +static void +tracker_storage_finalize (GObject *object) +{ + TrackerStoragePrivate *priv; + + priv = TRACKER_STORAGE_GET_PRIVATE (object); + + g_hash_table_destroy (priv->unmount_watchdogs); + + 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 TrackerStorageType +mount_info_get_type (MountInfo *info) +{ + TrackerStorageType mount_type = 0; + + if (info->removable) { + mount_type |= TRACKER_STORAGE_REMOVABLE; + } + + if (info->optical) { + mount_type |= TRACKER_STORAGE_OPTICAL; + } + + return mount_type; +} + +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, + gboolean optical) +{ + 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; + info->optical = optical; + + return g_node_append_data (node, info); +} + +static void +mount_add_new (TrackerStorage *storage, + const gchar *uuid, + const gchar *mount_point, + const gchar *mount_name, + gboolean removable_device, + gboolean optical_disc) +{ + TrackerStoragePrivate *priv; + GNode *node; + + priv = TRACKER_STORAGE_GET_PRIVATE (storage); + + node = mount_add_hierarchy (priv->mounts, uuid, mount_point, removable_device, optical_disc); + g_hash_table_insert (priv->mounts_by_uuid, g_strdup (uuid), node); + + g_signal_emit (storage, + signals[MOUNT_POINT_ADDED], + 0, + uuid, + mount_point, + mount_name, + removable_device, + optical_disc, + NULL); +} + +static gchar * +mount_guess_content_type (GMount *mount, + gboolean *is_optical, + gboolean *is_multimedia, + gboolean *is_blank) +{ + gchar *content_type = NULL; + gchar **guess_type; + + *is_optical = FALSE; + *is_multimedia = FALSE; + *is_blank = FALSE; + + /* This function has 2 purposes: + * + * 1. Detect if we are using optical media + * 2. Detect if we are video or music, we can't index those types + * + * We try to determine the content type because we don't want + * to store Volume information in Tracker about DVDs and media + * which has no real data for us to mine. + * + * Generally, if is_multimedia is TRUE then we end up ignoring + * the media. + */ + guess_type = g_mount_guess_content_type_sync (mount, TRUE, NULL, NULL); + + if (guess_type) { + gint i = 0; + + while (!content_type && guess_type[i]) { + if (!g_strcmp0 (guess_type[i], "x-content/image-picturecd")) { + /* Images */ + content_type = g_strdup (guess_type[i]); + } else if (!g_strcmp0 (guess_type[i], "x-content/video-bluray") || + !g_strcmp0 (guess_type[i], "x-content/video-dvd") || + !g_strcmp0 (guess_type[i], "x-content/video-hddvd") || + !g_strcmp0 (guess_type[i], "x-content/video-svcd") || + !g_strcmp0 (guess_type[i], "x-content/video-vcd")) { + /* Videos */ + *is_multimedia = TRUE; + content_type = g_strdup (guess_type[i]); + } else if (!g_strcmp0 (guess_type[i], "x-content/audio-cdda") || + !g_strcmp0 (guess_type[i], "x-content/audio-dvd") || + !g_strcmp0 (guess_type[i], "x-content/audio-player")) { + /* Audios */ + *is_multimedia = TRUE; + content_type = g_strdup (guess_type[i]); + } else if (!g_strcmp0 (guess_type[i], "x-content/blank-bd") || + !g_strcmp0 (guess_type[i], "x-content/blank-cd") || + !g_strcmp0 (guess_type[i], "x-content/blank-dvd") || + !g_strcmp0 (guess_type[i], "x-content/blank-hddvd")) { + /* Blank */ + *is_blank = TRUE; + content_type = g_strdup (guess_type[i]); + } else if (!g_strcmp0 (guess_type[i], "x-content/software") || + !g_strcmp0 (guess_type[i], "x-content/unix-software") || + !g_strcmp0 (guess_type[i], "x-content/win32-software")) { + /* NOTE: This one is a guess, can we + * have this content type on + * none-optical mount points? + */ + content_type = g_strdup (guess_type[i]); + } else { + /* else, keep on with the next guess, if any */ + i++; + } + } + + /* If we didn't have an exact match on possible guessed content types, + * then use the first one returned (best guess always first) if any */ + if (!content_type && guess_type[0]) { + content_type = g_strdup (guess_type[0]); + } + + g_strfreev (guess_type); + } + + if (content_type) { + if (strstr (content_type, "vcd") || + strstr (content_type, "cdda") || + strstr (content_type, "dvd") || + strstr (content_type, "bluray")) { + *is_optical = TRUE; + } + } else { + GUnixMountEntry *entry; + gchar *mount_path; + GFile *mount_root; + + /* No content type was guessed, try to find out + * at least whether it's an optical media or not + */ + mount_root = g_mount_get_root (mount); + mount_path = g_file_get_path (mount_root); + + /* FIXME: Try to assume we have a unix mount :( + * EEK, once in a while, I have to write crack, oh well + */ + if (mount_path && + (entry = g_unix_mount_at (mount_path, NULL)) != NULL) { + const gchar *filesystem_type; + gchar *device_path = NULL; + GVolume *volume; + + volume = g_mount_get_volume (mount); + filesystem_type = g_unix_mount_get_fs_type (entry); + g_debug (" Using filesystem type:'%s'", + filesystem_type); + + /* Volume may be NULL */ + if (volume) { + device_path = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); + g_debug (" Using device path:'%s'", + device_path); + g_object_unref (volume); + } + + /* NOTE: This code was taken from guess_mount_type() + * in GIO's gunixmounts.c and adapted purely for + * guessing optical media. We don't use the guessing + * code for other types such as MEMSTICKS, ZIPs, + * IPODs, etc. + * + * This code may need updating over time since it is + * very situational depending on how distributions + * mount their devices and how devices are named in + * /dev. + */ + if (strcmp (filesystem_type, "udf") == 0 || + strcmp (filesystem_type, "iso9660") == 0 || + strcmp (filesystem_type, "cd9660") == 0 || + (device_path && + (g_str_has_prefix (device_path, "/dev/cdrom") || + g_str_has_prefix (device_path, "/dev/acd") || + g_str_has_prefix (device_path, "/dev/cd")))) { + *is_optical = TRUE; + } else if (device_path && + g_str_has_prefix (device_path, "/vol/")) { + const gchar *name; + + name = mount_path + strlen ("/"); + + if (g_str_has_prefix (name, "cdrom")) { + *is_optical = TRUE; + } + } else { + gchar *basename = g_path_get_basename (mount_path); + + if (g_str_has_prefix (basename, "cdr") || + g_str_has_prefix (basename, "cdwriter") || + g_str_has_prefix (basename, "burn") || + g_str_has_prefix (basename, "dvdr")) { + *is_optical = TRUE; + } + + g_free (basename); + } + + g_free (device_path); + g_free (mount_path); + g_unix_mount_free (entry); + } else { + g_debug (" No GUnixMountEntry found, needed for detecting if optical media... :("); + g_free (mount_path); + } + + g_object_unref (mount_root); + } + + return content_type; +} + +static void +mount_add (TrackerStorage *storage, + GMount *mount) +{ + TrackerStoragePrivate *priv; + GFile *root; + GVolume *volume; + gchar *mount_name, *mount_path, *uuid; + gboolean is_optical = FALSE; + gboolean is_removable = FALSE; + + /* Get mount name */ + mount_name = g_mount_get_name (mount); + + /* Get root path of the mount */ + root = g_mount_get_root (mount); + mount_path = g_file_get_path (root); + + g_debug ("Found '%s' mounted on path '%s'", + mount_name, + mount_path); + + /* Do not process shadowed mounts! */ + if (g_mount_is_shadowed (mount)) { + g_debug (" Skipping shadowed mount '%s'", mount_name); + g_object_unref (root); + g_free (mount_path); + g_free (mount_name); + return; + } + + priv = TRACKER_STORAGE_GET_PRIVATE (storage); + + /* fstab partitions may not have corresponding + * GVolumes, so volume may be NULL */ + volume = g_mount_get_volume (mount); + if (volume) { + /* GMount with GVolume */ + + /* Try to get UUID from the Volume. + * Note that g_volume_get_uuid() is NOT equivalent */ + uuid = g_volume_get_identifier (volume, + G_VOLUME_IDENTIFIER_KIND_UUID); + if (!uuid) { + gchar *content_type; + gboolean is_multimedia; + gboolean is_blank; + + /* Optical discs usually won't have UUID in the GVolume */ + content_type = mount_guess_content_type (mount, &is_optical, &is_multimedia, &is_blank); + is_removable = TRUE; + + /* We don't index content which is video, music or blank */ + if (!is_multimedia && !is_blank) { + uuid = g_compute_checksum_for_string (G_CHECKSUM_MD5, + mount_name, + -1); + g_debug (" No UUID, generated:'%s' (based on mount name)", uuid); + g_debug (" Assuming GVolume has removable media, if wrong report a bug! " + "content type is '%s'", + content_type); + } else { + g_debug (" Being ignored because mount with volume is music/video/blank " + "(content type:%s, optical:%s, multimedia:%s, blank:%s)", + content_type, + is_optical ? "yes" : "no", + is_multimedia ? "yes" : "no", + is_blank ? "yes" : "no"); + } + + g_free (content_type); + } else { + /* Any other removable media will have UUID in the + * GVolume. Note that this also may include some + * partitions in the machine which have GVolumes + * associated to the GMounts. We also check a drive + * exists to be sure the device is local. */ + GDrive *drive; + + drive = g_volume_get_drive (volume); + + if (drive) { + /* We can't mount/unmount system volumes, so tag + * them as non removable. */ + is_removable = g_volume_can_mount (volume); + g_debug (" Found mount with volume and drive which %s be mounted: " + "Assuming it's %s removable, if wrong report a bug!", + is_removable ? "can" : "cannot", + is_removable ? "" : "not"); + g_object_unref (drive); + } else { + /* Note: not sure when this can happen... */ + g_debug (" Mount with volume but no drive, " + "assuming not a removable device, " + "if wrong report a bug!"); + is_removable = FALSE; + } + } + + g_object_unref (volume); + } else { + /* GMount without GVolume. + * Note: Never found a case where this g_mount_get_uuid() returns + * non-NULL... :-) */ + uuid = g_mount_get_uuid (mount); + if (!uuid) { + if (mount_path) { + gchar *content_type; + gboolean is_multimedia; + gboolean is_blank; + + content_type = mount_guess_content_type (mount, &is_optical, &is_multimedia, &is_blank); + + /* Note: for GMounts without GVolume, is_blank should NOT be considered, + * as it may give unwanted results... */ + if (!is_multimedia) { + uuid = g_compute_checksum_for_string (G_CHECKSUM_MD5, + mount_path, + -1); + g_debug (" No UUID, generated:'%s' (based on mount path)", uuid); + } else { + g_debug (" Being ignored because mount is music/video " + "(content type:%s, optical:%s, multimedia:%s)", + content_type, + is_optical ? "yes" : "no", + is_multimedia ? "yes" : "no"); + } + + g_free (content_type); + } else { + g_debug (" Being ignored because mount has no GVolume (i.e. not user mountable) " + "and has no mount root path available"); + } + } + } + + /* If we got something to be used as UUID, then add the mount + * to the TrackerStorage */ + if (uuid && mount_path && !g_hash_table_lookup (priv->mounts_by_uuid, uuid)) { + g_debug (" Adding mount point with UUID: '%s', removable: %s, optical: %s, path: '%s'", + uuid, + is_removable ? "yes" : "no", + is_optical ? "yes" : "no", + mount_path); + mount_add_new (storage, 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", + mount_path ? mount_path : "none", + (uuid && g_hash_table_lookup (priv->mounts_by_uuid, uuid)) ? "yes" : "no"); + } + + g_free (mount_name); + g_free (mount_path); + g_free (uuid); + g_object_unref (root); +} + +static gboolean +mounts_setup (TrackerStorage *storage) +{ + TrackerStoragePrivate *priv; + GList *mounts, *lm; + + priv = TRACKER_STORAGE_GET_PRIVATE (storage); + + mounts = g_volume_monitor_get_mounts (priv->volume_monitor); + + if (!mounts) { + g_message ("No mounts found to iterate"); + return TRUE; + } + + /* Iterate over all available mounts and add them. + * Note that GVolumeMonitor shows only those mounts which are + * actually mounted. */ + for (lm = mounts; lm; lm = g_list_next (lm)) { + mount_add (storage, lm->data); + g_object_unref (lm->data); + } + + g_list_free (mounts); + + return TRUE; +} + +static void +mount_added_cb (GVolumeMonitor *monitor, + GMount *mount, + gpointer user_data) +{ + mount_add (user_data, mount); +} + +static void +mount_remove (TrackerStorage *storage, + GMount *mount) +{ + TrackerStoragePrivate *priv; + MountInfo *info; + GNode *node; + GFile *file; + gchar *name; + gchar *mount_point; + gchar *mp; + + 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 +mount_removed_cb (GVolumeMonitor *monitor, + GMount *mount, + gpointer user_data) +{ + TrackerStorage *storage; + TrackerStoragePrivate *priv; + + storage = user_data; + priv = TRACKER_STORAGE_GET_PRIVATE (storage); + + mount_remove (storage, mount); + + /* Unmount suceeded, remove the pending check */ + g_hash_table_remove (priv->unmount_watchdogs, mount); +} + +static gboolean +unmount_failed_cb (gpointer user_data) +{ + UnmountCheckData *data = user_data; + TrackerStoragePrivate *priv; + + /* If this timeout gets to be executed, this is due + * to a pre-unmount signal with no corresponding + * unmount in a timely fashion, we assume this is + * due to an error, and add back the still mounted + * path. + */ + priv = TRACKER_STORAGE_GET_PRIVATE (data->storage); + + g_warning ("Unmount operation failed, adding back mount point..."); + + mount_add (data->storage, data->mount); + + g_hash_table_remove (priv->unmount_watchdogs, data->mount); + return FALSE; +} + +static void +mount_pre_removed_cb (GVolumeMonitor *monitor, + GMount *mount, + gpointer user_data) +{ + TrackerStorage *storage; + TrackerStoragePrivate *priv; + UnmountCheckData *data; + guint id; + + storage = user_data; + priv = TRACKER_STORAGE_GET_PRIVATE (storage); + + mount_remove (storage, mount); + + /* Add check for failed unmounts */ + data = g_new (UnmountCheckData, 1); + data->storage = storage; + data->mount = mount; + + id = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT_IDLE + 10, 3, + unmount_failed_cb, + data, (GDestroyNotify) g_free); + g_hash_table_insert (priv->unmount_watchdogs, data->mount, + GUINT_TO_POINTER (id)); +} + +/** + * tracker_storage_new: + * + * Creates a new instance of #TrackerStorage. + * + * Returns: The newly created #TrackerStorage. + * + * Since: 0.8 + **/ +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; + GNode *node; + MountInfo *info; + TrackerStorageType mount_type; + + gr = user_data; + node = value; + info = node->data; + mount_type = mount_info_get_type (info); + + /* is mount of the type we're looking for? */ + if ((gr->exact_match && mount_type == gr->type) || + (!gr->exact_match && (mount_type & gr->type))) { + 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_device_roots: + * @storage: A #TrackerStorage + * @type: A #TrackerStorageType + * @exact_match: if all devices should exactly match the types + * + * Returns: (transfer full) (element-type utf8): a #GSList of strings + * containing the root directories for devices with @type based on + * @exact_match. Each element must be freed using g_free() and the + * list itself through g_slist_free(). + * + * Since: 0.8 + **/ +GSList * +tracker_storage_get_device_roots (TrackerStorage *storage, + TrackerStorageType type, + gboolean exact_match) +{ + TrackerStoragePrivate *priv; + GetRoots gr; + + g_return_val_if_fail (TRACKER_IS_STORAGE (storage), NULL); + + priv = TRACKER_STORAGE_GET_PRIVATE (storage); + + gr.roots = NULL; + gr.type = type; + gr.exact_match = exact_match; + + g_hash_table_foreach (priv->mounts_by_uuid, + get_mount_point_by_uuid_foreach, + &gr); + + return gr.roots; +} + +/** + * tracker_storage_get_device_uuids: + * @storage: A #TrackerStorage + * @type: A #TrackerStorageType + * @exact_match: if all devices should exactly match the types + * + * Returns: (transfer full) (element-type utf8): a #GSList of + * strings containing the UUID for devices with @type based + * on @exact_match. Each element must be freed using g_free() + * and the list itself through g_slist_free(). + * + * Since: 0.8 + **/ +GSList * +tracker_storage_get_device_uuids (TrackerStorage *storage, + TrackerStorageType type, + gboolean exact_match) +{ + 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; + TrackerStorageType mount_type; + + uuid = key; + node = value; + info = node->data; + + mount_type = mount_info_get_type (info); + + /* is mount of the type we're looking for? */ + if ((exact_match && mount_type == type) || + (!exact_match && (mount_type & type))) { + 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. + * + * Since: 0.8 + **/ +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_type_for_uuid: + * @storage: A #TrackerStorage + * @uuid: A string pointer to the UUID for the %GVolume. + * + * Returns: The type flags for @uuid. + * + * Since: 0.10 + **/ +TrackerStorageType +tracker_storage_get_type_for_uuid (TrackerStorage *storage, + const gchar *uuid) +{ + TrackerStoragePrivate *priv; + GNode *node; + TrackerStorageType type = 0; + + g_return_val_if_fail (TRACKER_IS_STORAGE (storage), 0); + g_return_val_if_fail (uuid != NULL, 0); + + priv = TRACKER_STORAGE_GET_PRIVATE (storage); + + node = g_hash_table_lookup (priv->mounts_by_uuid, uuid); + + if (node) { + MountInfo *info; + + info = node->data; + + if (info->removable) { + type |= TRACKER_STORAGE_REMOVABLE; + } + if (info->optical) { + type |= TRACKER_STORAGE_OPTICAL; + } + } + + return type; +} + +/** + * 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. + * + * Since: 0.8 + **/ +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/libmediaart/tracker-storage.h b/libmediaart/tracker-storage.h new file mode 100644 index 0000000..2c28a5b --- /dev/null +++ b/libmediaart/tracker-storage.h @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2008, Nokia + * + * 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 __LIBTRACKER_MINER_STORAGE_H__ +#define __LIBTRACKER_MINER_STORAGE_H__ + +#include +#include + +G_BEGIN_DECLS + +/** + * TrackerStorageType: + * @TRACKER_STORAGE_REMOVABLE: Storage is a removable media + * @TRACKER_STORAGE_OPTICAL: Storage is an optical disc + * + * Flags specifying properties of the type of storage. + * + * Since: 0.8 + */ +typedef enum { + TRACKER_STORAGE_REMOVABLE = 1 << 0, + TRACKER_STORAGE_OPTICAL = 1 << 1 +} TrackerStorageType; + +/** + * TRACKER_STORAGE_TYPE_IS_REMOVABLE: + * @type: Mask of TrackerStorageType flags + * + * Check if the given storage type is marked as being removable media. + * + * Returns: %TRUE if the storage is marked as removable media, %FALSE otherwise + * + * Since: 0.10 + */ +#define TRACKER_STORAGE_TYPE_IS_REMOVABLE(type) ((type & TRACKER_STORAGE_REMOVABLE) ? TRUE : FALSE) + +/** + * TRACKER_STORAGE_TYPE_IS_OPTICAL: + * @type: Mask of TrackerStorageType flags + * + * Check if the given storage type is marked as being optical disc + * + * Returns: %TRUE if the storage is marked as optical disc, %FALSE otherwise + * + * Since: 0.10 + */ +#define TRACKER_STORAGE_TYPE_IS_OPTICAL(type) ((type & TRACKER_STORAGE_OPTICAL) ? TRUE : FALSE) + + +#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)) +#define TRACKER_IS_STORAGE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_STORAGE)) +#define TRACKER_IS_STORAGE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TRACKER_TYPE_STORAGE)) +#define TRACKER_STORAGE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_STORAGE, TrackerStorageClass)) + +typedef struct _TrackerStorage TrackerStorage; +typedef struct _TrackerStorageClass TrackerStorageClass; + +/** + * TrackerStorage: + * @parent: parent object + * + * A storage API for using mount points and devices + **/ +struct _TrackerStorage { + GObject parent; +}; + +/** + * TrackerStorageClass: + * @parent_class: parent object class + * + * A storage class for #TrackerStorage. + **/ +struct _TrackerStorageClass { + GObjectClass parent_class; +}; + +GType tracker_storage_get_type (void) G_GNUC_CONST; +TrackerStorage * tracker_storage_new (void); +GSList * tracker_storage_get_device_roots (TrackerStorage *storage, + TrackerStorageType type, + gboolean exact_match); +GSList * tracker_storage_get_device_uuids (TrackerStorage *storage, + TrackerStorageType type, + gboolean exact_match); +const gchar * tracker_storage_get_mount_point_for_uuid (TrackerStorage *storage, + const gchar *uuid); +TrackerStorageType tracker_storage_get_type_for_uuid (TrackerStorage *storage, + const gchar *uuid); +const gchar * tracker_storage_get_uuid_for_file (TrackerStorage *storage, + GFile *file); + +G_END_DECLS + +#endif /* __LIBTRACKER_MINER_STORAGE_H__ */ diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c deleted file mode 100644 index bbf771d..0000000 --- a/src/libtracker-miner/tracker-storage.c +++ /dev/null @@ -1,1107 +0,0 @@ -/* - * Copyright (C) 2008, Nokia - * - * 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 - -#include -#include - -#include - -#include "tracker-storage.h" -#include "tracker-utils.h" -#include "tracker-marshal.h" - -/** - * SECTION:tracker-storage - * @short_description: Removable storage and mount point convenience API - * @include: libtracker-miner/tracker-miner.h - * - * This API is a convenience to to be able to keep track of volumes - * which are mounted and also the type of removable media available. - * The API is built upon the top of GIO's #GMount, #GDrive and #GVolume API. - **/ - -#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; - GHashTable *unmount_watchdogs; -} TrackerStoragePrivate; - -typedef struct { - gchar *mount_point; - gchar *uuid; - guint unmount_timer_id; - guint removable : 1; - guint optical : 1; -} MountInfo; - -typedef struct { - const gchar *path; - GNode *node; -} TraverseData; - -typedef struct { - GSList *roots; - TrackerStorageType type; - gboolean exact_match; -} GetRoots; - -typedef struct { - TrackerStorage *storage; - GMount *mount; -} UnmountCheckData; - -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 mounts_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 mount_pre_removed_cb (GVolumeMonitor *monitor, - GMount *mount, - 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_STRING_BOOLEAN_BOOLEAN, - G_TYPE_NONE, - 5, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_BOOLEAN, - G_TYPE_BOOLEAN); - - 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->unmount_watchdogs = g_hash_table_new_full (NULL, NULL, NULL, - (GDestroyNotify) g_source_remove); - - 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_pre_removed_cb), storage, 0); - g_signal_connect_object (priv->volume_monitor, "mount-added", - G_CALLBACK (mount_added_cb), storage, 0); - - g_message ("Mount monitors set up for to watch for added, removed and pre-unmounts..."); - - /* Get all mounts and set them up */ - if (!mounts_setup (storage)) { - return; - } -} - -static void -tracker_storage_finalize (GObject *object) -{ - TrackerStoragePrivate *priv; - - priv = TRACKER_STORAGE_GET_PRIVATE (object); - - g_hash_table_destroy (priv->unmount_watchdogs); - - 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 TrackerStorageType -mount_info_get_type (MountInfo *info) -{ - TrackerStorageType mount_type = 0; - - if (info->removable) { - mount_type |= TRACKER_STORAGE_REMOVABLE; - } - - if (info->optical) { - mount_type |= TRACKER_STORAGE_OPTICAL; - } - - return mount_type; -} - -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, - gboolean optical) -{ - 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; - info->optical = optical; - - return g_node_append_data (node, info); -} - -static void -mount_add_new (TrackerStorage *storage, - const gchar *uuid, - const gchar *mount_point, - const gchar *mount_name, - gboolean removable_device, - gboolean optical_disc) -{ - TrackerStoragePrivate *priv; - GNode *node; - - priv = TRACKER_STORAGE_GET_PRIVATE (storage); - - node = mount_add_hierarchy (priv->mounts, uuid, mount_point, removable_device, optical_disc); - g_hash_table_insert (priv->mounts_by_uuid, g_strdup (uuid), node); - - g_signal_emit (storage, - signals[MOUNT_POINT_ADDED], - 0, - uuid, - mount_point, - mount_name, - removable_device, - optical_disc, - NULL); -} - -static gchar * -mount_guess_content_type (GMount *mount, - gboolean *is_optical, - gboolean *is_multimedia, - gboolean *is_blank) -{ - gchar *content_type = NULL; - gchar **guess_type; - - *is_optical = FALSE; - *is_multimedia = FALSE; - *is_blank = FALSE; - - /* This function has 2 purposes: - * - * 1. Detect if we are using optical media - * 2. Detect if we are video or music, we can't index those types - * - * We try to determine the content type because we don't want - * to store Volume information in Tracker about DVDs and media - * which has no real data for us to mine. - * - * Generally, if is_multimedia is TRUE then we end up ignoring - * the media. - */ - guess_type = g_mount_guess_content_type_sync (mount, TRUE, NULL, NULL); - - if (guess_type) { - gint i = 0; - - while (!content_type && guess_type[i]) { - if (!g_strcmp0 (guess_type[i], "x-content/image-picturecd")) { - /* Images */ - content_type = g_strdup (guess_type[i]); - } else if (!g_strcmp0 (guess_type[i], "x-content/video-bluray") || - !g_strcmp0 (guess_type[i], "x-content/video-dvd") || - !g_strcmp0 (guess_type[i], "x-content/video-hddvd") || - !g_strcmp0 (guess_type[i], "x-content/video-svcd") || - !g_strcmp0 (guess_type[i], "x-content/video-vcd")) { - /* Videos */ - *is_multimedia = TRUE; - content_type = g_strdup (guess_type[i]); - } else if (!g_strcmp0 (guess_type[i], "x-content/audio-cdda") || - !g_strcmp0 (guess_type[i], "x-content/audio-dvd") || - !g_strcmp0 (guess_type[i], "x-content/audio-player")) { - /* Audios */ - *is_multimedia = TRUE; - content_type = g_strdup (guess_type[i]); - } else if (!g_strcmp0 (guess_type[i], "x-content/blank-bd") || - !g_strcmp0 (guess_type[i], "x-content/blank-cd") || - !g_strcmp0 (guess_type[i], "x-content/blank-dvd") || - !g_strcmp0 (guess_type[i], "x-content/blank-hddvd")) { - /* Blank */ - *is_blank = TRUE; - content_type = g_strdup (guess_type[i]); - } else if (!g_strcmp0 (guess_type[i], "x-content/software") || - !g_strcmp0 (guess_type[i], "x-content/unix-software") || - !g_strcmp0 (guess_type[i], "x-content/win32-software")) { - /* NOTE: This one is a guess, can we - * have this content type on - * none-optical mount points? - */ - content_type = g_strdup (guess_type[i]); - } else { - /* else, keep on with the next guess, if any */ - i++; - } - } - - /* If we didn't have an exact match on possible guessed content types, - * then use the first one returned (best guess always first) if any */ - if (!content_type && guess_type[0]) { - content_type = g_strdup (guess_type[0]); - } - - g_strfreev (guess_type); - } - - if (content_type) { - if (strstr (content_type, "vcd") || - strstr (content_type, "cdda") || - strstr (content_type, "dvd") || - strstr (content_type, "bluray")) { - *is_optical = TRUE; - } - } else { - GUnixMountEntry *entry; - gchar *mount_path; - GFile *mount_root; - - /* No content type was guessed, try to find out - * at least whether it's an optical media or not - */ - mount_root = g_mount_get_root (mount); - mount_path = g_file_get_path (mount_root); - - /* FIXME: Try to assume we have a unix mount :( - * EEK, once in a while, I have to write crack, oh well - */ - if (mount_path && - (entry = g_unix_mount_at (mount_path, NULL)) != NULL) { - const gchar *filesystem_type; - gchar *device_path = NULL; - GVolume *volume; - - volume = g_mount_get_volume (mount); - filesystem_type = g_unix_mount_get_fs_type (entry); - g_debug (" Using filesystem type:'%s'", - filesystem_type); - - /* Volume may be NULL */ - if (volume) { - device_path = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); - g_debug (" Using device path:'%s'", - device_path); - g_object_unref (volume); - } - - /* NOTE: This code was taken from guess_mount_type() - * in GIO's gunixmounts.c and adapted purely for - * guessing optical media. We don't use the guessing - * code for other types such as MEMSTICKS, ZIPs, - * IPODs, etc. - * - * This code may need updating over time since it is - * very situational depending on how distributions - * mount their devices and how devices are named in - * /dev. - */ - if (strcmp (filesystem_type, "udf") == 0 || - strcmp (filesystem_type, "iso9660") == 0 || - strcmp (filesystem_type, "cd9660") == 0 || - (device_path && - (g_str_has_prefix (device_path, "/dev/cdrom") || - g_str_has_prefix (device_path, "/dev/acd") || - g_str_has_prefix (device_path, "/dev/cd")))) { - *is_optical = TRUE; - } else if (device_path && - g_str_has_prefix (device_path, "/vol/")) { - const gchar *name; - - name = mount_path + strlen ("/"); - - if (g_str_has_prefix (name, "cdrom")) { - *is_optical = TRUE; - } - } else { - gchar *basename = g_path_get_basename (mount_path); - - if (g_str_has_prefix (basename, "cdr") || - g_str_has_prefix (basename, "cdwriter") || - g_str_has_prefix (basename, "burn") || - g_str_has_prefix (basename, "dvdr")) { - *is_optical = TRUE; - } - - g_free (basename); - } - - g_free (device_path); - g_free (mount_path); - g_unix_mount_free (entry); - } else { - g_debug (" No GUnixMountEntry found, needed for detecting if optical media... :("); - g_free (mount_path); - } - - g_object_unref (mount_root); - } - - return content_type; -} - -static void -mount_add (TrackerStorage *storage, - GMount *mount) -{ - TrackerStoragePrivate *priv; - GFile *root; - GVolume *volume; - gchar *mount_name, *mount_path, *uuid; - gboolean is_optical = FALSE; - gboolean is_removable = FALSE; - - /* Get mount name */ - mount_name = g_mount_get_name (mount); - - /* Get root path of the mount */ - root = g_mount_get_root (mount); - mount_path = g_file_get_path (root); - - g_debug ("Found '%s' mounted on path '%s'", - mount_name, - mount_path); - - /* Do not process shadowed mounts! */ - if (g_mount_is_shadowed (mount)) { - g_debug (" Skipping shadowed mount '%s'", mount_name); - g_object_unref (root); - g_free (mount_path); - g_free (mount_name); - return; - } - - priv = TRACKER_STORAGE_GET_PRIVATE (storage); - - /* fstab partitions may not have corresponding - * GVolumes, so volume may be NULL */ - volume = g_mount_get_volume (mount); - if (volume) { - /* GMount with GVolume */ - - /* Try to get UUID from the Volume. - * Note that g_volume_get_uuid() is NOT equivalent */ - uuid = g_volume_get_identifier (volume, - G_VOLUME_IDENTIFIER_KIND_UUID); - if (!uuid) { - gchar *content_type; - gboolean is_multimedia; - gboolean is_blank; - - /* Optical discs usually won't have UUID in the GVolume */ - content_type = mount_guess_content_type (mount, &is_optical, &is_multimedia, &is_blank); - is_removable = TRUE; - - /* We don't index content which is video, music or blank */ - if (!is_multimedia && !is_blank) { - uuid = g_compute_checksum_for_string (G_CHECKSUM_MD5, - mount_name, - -1); - g_debug (" No UUID, generated:'%s' (based on mount name)", uuid); - g_debug (" Assuming GVolume has removable media, if wrong report a bug! " - "content type is '%s'", - content_type); - } else { - g_debug (" Being ignored because mount with volume is music/video/blank " - "(content type:%s, optical:%s, multimedia:%s, blank:%s)", - content_type, - is_optical ? "yes" : "no", - is_multimedia ? "yes" : "no", - is_blank ? "yes" : "no"); - } - - g_free (content_type); - } else { - /* Any other removable media will have UUID in the - * GVolume. Note that this also may include some - * partitions in the machine which have GVolumes - * associated to the GMounts. We also check a drive - * exists to be sure the device is local. */ - GDrive *drive; - - drive = g_volume_get_drive (volume); - - if (drive) { - /* We can't mount/unmount system volumes, so tag - * them as non removable. */ - is_removable = g_volume_can_mount (volume); - g_debug (" Found mount with volume and drive which %s be mounted: " - "Assuming it's %s removable, if wrong report a bug!", - is_removable ? "can" : "cannot", - is_removable ? "" : "not"); - g_object_unref (drive); - } else { - /* Note: not sure when this can happen... */ - g_debug (" Mount with volume but no drive, " - "assuming not a removable device, " - "if wrong report a bug!"); - is_removable = FALSE; - } - } - - g_object_unref (volume); - } else { - /* GMount without GVolume. - * Note: Never found a case where this g_mount_get_uuid() returns - * non-NULL... :-) */ - uuid = g_mount_get_uuid (mount); - if (!uuid) { - if (mount_path) { - gchar *content_type; - gboolean is_multimedia; - gboolean is_blank; - - content_type = mount_guess_content_type (mount, &is_optical, &is_multimedia, &is_blank); - - /* Note: for GMounts without GVolume, is_blank should NOT be considered, - * as it may give unwanted results... */ - if (!is_multimedia) { - uuid = g_compute_checksum_for_string (G_CHECKSUM_MD5, - mount_path, - -1); - g_debug (" No UUID, generated:'%s' (based on mount path)", uuid); - } else { - g_debug (" Being ignored because mount is music/video " - "(content type:%s, optical:%s, multimedia:%s)", - content_type, - is_optical ? "yes" : "no", - is_multimedia ? "yes" : "no"); - } - - g_free (content_type); - } else { - g_debug (" Being ignored because mount has no GVolume (i.e. not user mountable) " - "and has no mount root path available"); - } - } - } - - /* If we got something to be used as UUID, then add the mount - * to the TrackerStorage */ - if (uuid && mount_path && !g_hash_table_lookup (priv->mounts_by_uuid, uuid)) { - g_debug (" Adding mount point with UUID: '%s', removable: %s, optical: %s, path: '%s'", - uuid, - is_removable ? "yes" : "no", - is_optical ? "yes" : "no", - mount_path); - mount_add_new (storage, 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", - mount_path ? mount_path : "none", - (uuid && g_hash_table_lookup (priv->mounts_by_uuid, uuid)) ? "yes" : "no"); - } - - g_free (mount_name); - g_free (mount_path); - g_free (uuid); - g_object_unref (root); -} - -static gboolean -mounts_setup (TrackerStorage *storage) -{ - TrackerStoragePrivate *priv; - GList *mounts, *lm; - - priv = TRACKER_STORAGE_GET_PRIVATE (storage); - - mounts = g_volume_monitor_get_mounts (priv->volume_monitor); - - if (!mounts) { - g_message ("No mounts found to iterate"); - return TRUE; - } - - /* Iterate over all available mounts and add them. - * Note that GVolumeMonitor shows only those mounts which are - * actually mounted. */ - for (lm = mounts; lm; lm = g_list_next (lm)) { - mount_add (storage, lm->data); - g_object_unref (lm->data); - } - - g_list_free (mounts); - - return TRUE; -} - -static void -mount_added_cb (GVolumeMonitor *monitor, - GMount *mount, - gpointer user_data) -{ - mount_add (user_data, mount); -} - -static void -mount_remove (TrackerStorage *storage, - GMount *mount) -{ - TrackerStoragePrivate *priv; - MountInfo *info; - GNode *node; - GFile *file; - gchar *name; - gchar *mount_point; - gchar *mp; - - 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 -mount_removed_cb (GVolumeMonitor *monitor, - GMount *mount, - gpointer user_data) -{ - TrackerStorage *storage; - TrackerStoragePrivate *priv; - - storage = user_data; - priv = TRACKER_STORAGE_GET_PRIVATE (storage); - - mount_remove (storage, mount); - - /* Unmount suceeded, remove the pending check */ - g_hash_table_remove (priv->unmount_watchdogs, mount); -} - -static gboolean -unmount_failed_cb (gpointer user_data) -{ - UnmountCheckData *data = user_data; - TrackerStoragePrivate *priv; - - /* If this timeout gets to be executed, this is due - * to a pre-unmount signal with no corresponding - * unmount in a timely fashion, we assume this is - * due to an error, and add back the still mounted - * path. - */ - priv = TRACKER_STORAGE_GET_PRIVATE (data->storage); - - g_warning ("Unmount operation failed, adding back mount point..."); - - mount_add (data->storage, data->mount); - - g_hash_table_remove (priv->unmount_watchdogs, data->mount); - return FALSE; -} - -static void -mount_pre_removed_cb (GVolumeMonitor *monitor, - GMount *mount, - gpointer user_data) -{ - TrackerStorage *storage; - TrackerStoragePrivate *priv; - UnmountCheckData *data; - guint id; - - storage = user_data; - priv = TRACKER_STORAGE_GET_PRIVATE (storage); - - mount_remove (storage, mount); - - /* Add check for failed unmounts */ - data = g_new (UnmountCheckData, 1); - data->storage = storage; - data->mount = mount; - - id = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT_IDLE + 10, 3, - unmount_failed_cb, - data, (GDestroyNotify) g_free); - g_hash_table_insert (priv->unmount_watchdogs, data->mount, - GUINT_TO_POINTER (id)); -} - -/** - * tracker_storage_new: - * - * Creates a new instance of #TrackerStorage. - * - * Returns: The newly created #TrackerStorage. - * - * Since: 0.8 - **/ -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; - GNode *node; - MountInfo *info; - TrackerStorageType mount_type; - - gr = user_data; - node = value; - info = node->data; - mount_type = mount_info_get_type (info); - - /* is mount of the type we're looking for? */ - if ((gr->exact_match && mount_type == gr->type) || - (!gr->exact_match && (mount_type & gr->type))) { - 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_device_roots: - * @storage: A #TrackerStorage - * @type: A #TrackerStorageType - * @exact_match: if all devices should exactly match the types - * - * Returns: (transfer full) (element-type utf8): a #GSList of strings - * containing the root directories for devices with @type based on - * @exact_match. Each element must be freed using g_free() and the - * list itself through g_slist_free(). - * - * Since: 0.8 - **/ -GSList * -tracker_storage_get_device_roots (TrackerStorage *storage, - TrackerStorageType type, - gboolean exact_match) -{ - TrackerStoragePrivate *priv; - GetRoots gr; - - g_return_val_if_fail (TRACKER_IS_STORAGE (storage), NULL); - - priv = TRACKER_STORAGE_GET_PRIVATE (storage); - - gr.roots = NULL; - gr.type = type; - gr.exact_match = exact_match; - - g_hash_table_foreach (priv->mounts_by_uuid, - get_mount_point_by_uuid_foreach, - &gr); - - return gr.roots; -} - -/** - * tracker_storage_get_device_uuids: - * @storage: A #TrackerStorage - * @type: A #TrackerStorageType - * @exact_match: if all devices should exactly match the types - * - * Returns: (transfer full) (element-type utf8): a #GSList of - * strings containing the UUID for devices with @type based - * on @exact_match. Each element must be freed using g_free() - * and the list itself through g_slist_free(). - * - * Since: 0.8 - **/ -GSList * -tracker_storage_get_device_uuids (TrackerStorage *storage, - TrackerStorageType type, - gboolean exact_match) -{ - 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; - TrackerStorageType mount_type; - - uuid = key; - node = value; - info = node->data; - - mount_type = mount_info_get_type (info); - - /* is mount of the type we're looking for? */ - if ((exact_match && mount_type == type) || - (!exact_match && (mount_type & type))) { - 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. - * - * Since: 0.8 - **/ -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_type_for_uuid: - * @storage: A #TrackerStorage - * @uuid: A string pointer to the UUID for the %GVolume. - * - * Returns: The type flags for @uuid. - * - * Since: 0.10 - **/ -TrackerStorageType -tracker_storage_get_type_for_uuid (TrackerStorage *storage, - const gchar *uuid) -{ - TrackerStoragePrivate *priv; - GNode *node; - TrackerStorageType type = 0; - - g_return_val_if_fail (TRACKER_IS_STORAGE (storage), 0); - g_return_val_if_fail (uuid != NULL, 0); - - priv = TRACKER_STORAGE_GET_PRIVATE (storage); - - node = g_hash_table_lookup (priv->mounts_by_uuid, uuid); - - if (node) { - MountInfo *info; - - info = node->data; - - if (info->removable) { - type |= TRACKER_STORAGE_REMOVABLE; - } - if (info->optical) { - type |= TRACKER_STORAGE_OPTICAL; - } - } - - return type; -} - -/** - * 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. - * - * Since: 0.8 - **/ -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-miner/tracker-storage.h b/src/libtracker-miner/tracker-storage.h deleted file mode 100644 index f3101c0..0000000 --- a/src/libtracker-miner/tracker-storage.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (C) 2008, Nokia - * - * 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 __LIBTRACKER_MINER_STORAGE_H__ -#define __LIBTRACKER_MINER_STORAGE_H__ - -#if !defined (__LIBTRACKER_MINER_H_INSIDE__) && !defined (TRACKER_COMPILATION) -#error "Only can be included directly." -#endif - -#include -#include - -G_BEGIN_DECLS - -/** - * TrackerStorageType: - * @TRACKER_STORAGE_REMOVABLE: Storage is a removable media - * @TRACKER_STORAGE_OPTICAL: Storage is an optical disc - * - * Flags specifying properties of the type of storage. - * - * Since: 0.8 - */ -typedef enum { - TRACKER_STORAGE_REMOVABLE = 1 << 0, - TRACKER_STORAGE_OPTICAL = 1 << 1 -} TrackerStorageType; - -/** - * TRACKER_STORAGE_TYPE_IS_REMOVABLE: - * @type: Mask of TrackerStorageType flags - * - * Check if the given storage type is marked as being removable media. - * - * Returns: %TRUE if the storage is marked as removable media, %FALSE otherwise - * - * Since: 0.10 - */ -#define TRACKER_STORAGE_TYPE_IS_REMOVABLE(type) ((type & TRACKER_STORAGE_REMOVABLE) ? TRUE : FALSE) - -/** - * TRACKER_STORAGE_TYPE_IS_OPTICAL: - * @type: Mask of TrackerStorageType flags - * - * Check if the given storage type is marked as being optical disc - * - * Returns: %TRUE if the storage is marked as optical disc, %FALSE otherwise - * - * Since: 0.10 - */ -#define TRACKER_STORAGE_TYPE_IS_OPTICAL(type) ((type & TRACKER_STORAGE_OPTICAL) ? TRUE : FALSE) - - -#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)) -#define TRACKER_IS_STORAGE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_STORAGE)) -#define TRACKER_IS_STORAGE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TRACKER_TYPE_STORAGE)) -#define TRACKER_STORAGE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_STORAGE, TrackerStorageClass)) - -typedef struct _TrackerStorage TrackerStorage; -typedef struct _TrackerStorageClass TrackerStorageClass; - -/** - * TrackerStorage: - * @parent: parent object - * - * A storage API for using mount points and devices - **/ -struct _TrackerStorage { - GObject parent; -}; - -/** - * TrackerStorageClass: - * @parent_class: parent object class - * - * A storage class for #TrackerStorage. - **/ -struct _TrackerStorageClass { - GObjectClass parent_class; -}; - -GType tracker_storage_get_type (void) G_GNUC_CONST; -TrackerStorage * tracker_storage_new (void); -GSList * tracker_storage_get_device_roots (TrackerStorage *storage, - TrackerStorageType type, - gboolean exact_match); -GSList * tracker_storage_get_device_uuids (TrackerStorage *storage, - TrackerStorageType type, - gboolean exact_match); -const gchar * tracker_storage_get_mount_point_for_uuid (TrackerStorage *storage, - const gchar *uuid); -TrackerStorageType tracker_storage_get_type_for_uuid (TrackerStorage *storage, - const gchar *uuid); -const gchar * tracker_storage_get_uuid_for_file (TrackerStorage *storage, - GFile *file); - -G_END_DECLS - -#endif /* __LIBTRACKER_MINER_STORAGE_H__ */ -- cgit v1.2.1 From 8ee1bc3bc614a7ea19327650bd9fbd493b398688 Mon Sep 17 00:00:00 2001 From: "Arnel A. Borja" Date: Sat, 31 Aug 2013 01:24:55 +0800 Subject: libmediaart: Add marshaler --- configure.ac | 3 +++ libmediaart/Makefile.am | 22 +++++++++++++++++++++- libmediaart/marshal.list | 2 ++ libmediaart/tracker-storage.c | 6 +++--- 4 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 libmediaart/marshal.list diff --git a/configure.ac b/configure.ac index 9015d84..36cb95e 100644 --- a/configure.ac +++ b/configure.ac @@ -146,6 +146,9 @@ TRACKER_REQUIRED=0.16.0 LIBMEDIAART_REQUIRED="glib-2.0 >= $GLIB_REQUIRED tracker-sparql-0.16 >= $TRACKER_REQUIRED" PKG_CHECK_MODULES(LIBMEDIAART, [$LIBMEDIAART_REQUIRED]) +GLIB_GENMARSHAL=`$PKG_CONFIG glib-2.0 --variable=glib_genmarshal` +AC_SUBST(GLIB_GENMARSHAL) + LIBMEDIAART_LIBS="$LIBMEDIAART_LIBS -lz -lm" #################################################################### diff --git a/libmediaart/Makefile.am b/libmediaart/Makefile.am index 55931c1..908b01c 100644 --- a/libmediaart/Makefile.am +++ b/libmediaart/Makefile.am @@ -27,6 +27,8 @@ libmediaartinclude_HEADERS = \ libmediaart_@LIBMEDIAART_API_VERSION@_la_SOURCES = \ $(libmediaart_sources) \ + marshal.c \ + marshal.h \ tracker-storage.c \ tracker-storage.h @@ -49,6 +51,24 @@ libmediaart_@LIBMEDIAART_API_VERSION@_la_LIBADD = \ $(LIBMEDIAART_LIBS) +marshal.h: marshal.list + $(AM_V_GEN)$(GLIB_GENMARSHAL) $< --prefix=media_art_marshal --header > $@ + +marshal.c: marshal.list + $(AM_V_GEN)(echo "#include \"marshal.h\""; \ + $(GLIB_GENMARSHAL) $< --prefix=media_art_marshal --body) > $@ + + +BUILT_SOURCES = \ + marshal.c \ + marshal.h + +CLEANFILES = $(BUILT_SOURCES) + +EXTRA_DIST = \ + marshal.list + + -include $(INTROSPECTION_MAKEFILE) INTROSPECTION_GIRS = INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) --symbol-prefix=media_art @@ -71,7 +91,7 @@ gir_DATA = $(INTROSPECTION_GIRS) typelibdir = $(libdir)/girepository-1.0 typelib_DATA = $(INTROSPECTION_GIRS:.gir=.typelib) -CLEANFILES = $(gir_DATA) $(typelib_DATA) +BUILT_SOURCES += $(gir_DATA) $(typelib_DATA) endif if ENABLE_VAPIGEN diff --git a/libmediaart/marshal.list b/libmediaart/marshal.list new file mode 100644 index 0000000..f7cef75 --- /dev/null +++ b/libmediaart/marshal.list @@ -0,0 +1,2 @@ +VOID:STRING,STRING +VOID:STRING,STRING,STRING,BOOLEAN,BOOLEAN diff --git a/libmediaart/tracker-storage.c b/libmediaart/tracker-storage.c index bd83940..e13be7d 100644 --- a/libmediaart/tracker-storage.c +++ b/libmediaart/tracker-storage.c @@ -25,7 +25,7 @@ #include #include "tracker-storage.h" -#include "tracker-marshal.h" +#include "marshal.h" /** * SECTION:tracker-storage @@ -111,7 +111,7 @@ tracker_storage_class_init (TrackerStorageClass *klass) G_SIGNAL_RUN_LAST, 0, NULL, NULL, - tracker_marshal_VOID__STRING_STRING_STRING_BOOLEAN_BOOLEAN, + media_art_marshal_VOID__STRING_STRING_STRING_BOOLEAN_BOOLEAN, G_TYPE_NONE, 5, G_TYPE_STRING, @@ -126,7 +126,7 @@ tracker_storage_class_init (TrackerStorageClass *klass) G_SIGNAL_RUN_LAST, 0, NULL, NULL, - tracker_marshal_VOID__STRING_STRING, + media_art_marshal_VOID__STRING_STRING, G_TYPE_NONE, 2, G_TYPE_STRING, -- cgit v1.2.1 From 625d028f6889c5960b121687c5063b49144b186c Mon Sep 17 00:00:00 2001 From: "Arnel A. Borja" Date: Sun, 25 Aug 2013 10:15:08 +0800 Subject: build: Require gio-2.0 and gio-unix-2.0 too These libraries are needed by TrackerStorage. --- configure.ac | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 36cb95e..8c9ce90 100644 --- a/configure.ac +++ b/configure.ac @@ -143,7 +143,10 @@ QT_REQUIRED=4.7.1 TRACKER_REQUIRED=0.16.0 # Check requirements for libmediaart -LIBMEDIAART_REQUIRED="glib-2.0 >= $GLIB_REQUIRED tracker-sparql-0.16 >= $TRACKER_REQUIRED" +LIBMEDIAART_REQUIRED="glib-2.0 >= $GLIB_REQUIRED + gio-2.0 >= $GLIB_REQUIRED + gio-unix-2.0 >= $GLIB_REQUIRED + tracker-sparql-0.16 >= $TRACKER_REQUIRED" PKG_CHECK_MODULES(LIBMEDIAART, [$LIBMEDIAART_REQUIRED]) GLIB_GENMARSHAL=`$PKG_CONFIG glib-2.0 --variable=glib_genmarshal` -- cgit v1.2.1 From 5ddff2c76a6f676a6bab34dd7c277e5c8d1f12f2 Mon Sep 17 00:00:00 2001 From: "Arnel A. Borja" Date: Sun, 25 Aug 2013 10:22:51 +0800 Subject: extract: Use TrackerStorage to check if file is in a removable medium This will initialize a TrackerStorage on init and unrefs it on shutdown. Removed warnings for missing TrackerStorage. Uncommented media_art_copy_to_local which now works again. --- libmediaart/extract.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/libmediaart/extract.c b/libmediaart/extract.c index 8afc3f7..358c8d9 100644 --- a/libmediaart/extract.c +++ b/libmediaart/extract.c @@ -25,6 +25,8 @@ #include +#include "tracker-storage.h" + #include "extract.h" #include "cache.h" @@ -69,6 +71,7 @@ static gboolean disable_requests; static GHashTable *media_art_cache; static GDBusConnection *connection; +static TrackerStorage *storage; static void media_art_queue_cb (GObject *source_object, GAsyncResult *res, @@ -825,12 +828,9 @@ media_art_request_download (MediaArtType type, } } -#if 0 - static void -media_art_copy_to_local (TrackerStorage *storage, - const gchar *filename, - const gchar *local_uri) +media_art_copy_to_local (const gchar *filename, + const gchar *local_uri) { GSList *roots, *l; gboolean on_removable_device = FALSE; @@ -897,18 +897,6 @@ media_art_copy_to_local (TrackerStorage *storage, } } -#else -#warning "FIXME: WE don't have TrackerStorage, media_art_copy_to_local() does nothing." - -static void -media_art_copy_to_local (const gchar *filename, - const gchar *local_uri) -{ - g_warning ("FIXME: WE don't have TrackerStorage, media_art_copy_to_local() does nothing."); -} - -#endif - static void media_art_queue_cb (GObject *source_object, GAsyncResult *res, @@ -935,10 +923,7 @@ media_art_queue_cb (GObject *source_object, g_variant_unref (v); } - /* FIXME: was TrackerStorage ...*/ -#warning "FIXME: check for non-existant TrackerStorage" - - if (NULL && + if (storage && fi->art_path && g_file_test (fi->art_path, G_FILE_TEST_EXISTS)) { media_art_copy_to_local (fi->art_path, @@ -973,6 +958,8 @@ media_art_init (void) return FALSE; } + storage = tracker_storage_new (); + initialized = TRUE; return TRUE; @@ -983,6 +970,10 @@ media_art_shutdown (void) { g_return_if_fail (initialized == TRUE); + if (storage) { + g_object_unref (storage); + } + if (connection) { g_object_unref (connection); } -- cgit v1.2.1 From 277e6cec65c9898a7379e7ffbde79edcaf787b37 Mon Sep 17 00:00:00 2001 From: "Arnel A. Borja" Date: Sun, 25 Aug 2013 10:45:31 +0800 Subject: tests: Fix includes --- tests/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index 6d907fb..cb487dc 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -8,7 +8,7 @@ AM_CPPFLAGS = \ -DTOP_SRCDIR=\"$(abs_top_srcdir)\" \ -DTOP_BUILDDIR=\"$(abs_top_builddir)\" \ $(BUILD_CFLAGS) \ - -I$(top_srcdir)/libmediaart \ + -I$(top_srcdir) \ $(LIBMEDIAART_CFLAGS) LDADD = \ -- cgit v1.2.1 From 591ffeaf221dfecbe1a6d4f97fac431dec83c48e Mon Sep 17 00:00:00 2001 From: "Arnel A. Borja" Date: Sun, 25 Aug 2013 11:04:58 +0800 Subject: build: Fix distcheck --- Makefile.am | 3 ++- libmediaart/Makefile.am | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index 7692dd1..7a214c4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -21,5 +21,6 @@ CLEANFILES = \ DISTCHECK_CONFIGURE_FLAGS = \ --enable-unit-tests \ - --enable-introspection + --enable-introspection \ + --enable-gtk-doc diff --git a/libmediaart/Makefile.am b/libmediaart/Makefile.am index 908b01c..42c155f 100644 --- a/libmediaart/Makefile.am +++ b/libmediaart/Makefile.am @@ -77,7 +77,7 @@ INTROSPECTION_COMPILER_ARGS = --includedir=$(srcdir) if HAVE_INTROSPECTION introspection_sources = $(libmediaart_sources) extractdummy.c -MediaArt-@LIBMEDIAART_API_VERSION_U@.gir: libmediaart-@LIBMEDIAART_API_VERSION@.la +MediaArt-@LIBMEDIAART_API_VERSION@.gir: libmediaart-@LIBMEDIAART_API_VERSION@.la MediaArt_@LIBMEDIAART_API_VERSION_U@_gir_INCLUDES = GObject-2.0 MediaArt_@LIBMEDIAART_API_VERSION_U@_gir_CFLAGS = $(INCLUDES) -DLIBMEDIAART_COMPILATION MediaArt_@LIBMEDIAART_API_VERSION_U@_gir_LIBS = libmediaart-@LIBMEDIAART_API_VERSION@.la @@ -106,4 +106,6 @@ libmediaart_@LIBMEDIAART_API_VERSION_U@_vapi_FILES = MediaArt-@LIBMEDIAART_API_V vapidir = $(datadir)/vala/vapi vapi_DATA = $(VAPIGEN_VAPIS) + +BUILT_SOURCES += $(vapi_DATA) endif -- cgit v1.2.1 From 64e06dbeac3284b287a2b630bbe18c2494a11b37 Mon Sep 17 00:00:00 2001 From: "Arnel A. Borja" Date: Sun, 25 Aug 2013 18:34:28 +0800 Subject: Rename LICENSE to COPYING, and add COPYING.LESSER Autoconf adds COPYING which contains GPLv3, which is not what the sources are licensed with. Replace it with GPLv2 in a text file from GNU's website and add COPYING.LESSER for LGPLv2.1, so that the package would be under LGPLv2.1 license. --- COPYING | 339 ++++++++++++++++++++++++++++++++++++++ COPYING.LESSER | 502 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ LICENSE | 339 -------------------------------------- 3 files changed, 841 insertions(+), 339 deletions(-) create mode 100644 COPYING create mode 100644 COPYING.LESSER delete mode 100644 LICENSE diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..d159169 --- /dev/null +++ b/COPYING @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/COPYING.LESSER b/COPYING.LESSER new file mode 100644 index 0000000..4362b49 --- /dev/null +++ b/COPYING.LESSER @@ -0,0 +1,502 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + 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 + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 28b818a..0000000 --- a/LICENSE +++ /dev/null @@ -1,339 +0,0 @@ -GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - Library tasked with managing, extracting and handling media art caches - Copyright (C) 2013 Martyn Russell - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - {signature of Ty Coon}, 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. -- cgit v1.2.1