tracker r1267 - in trunk: . src/libtracker-common src/trackerd
- From: mr svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r1267 - in trunk: . src/libtracker-common src/trackerd
- Date: Fri, 11 Apr 2008 12:43:01 +0100 (BST)
Author: mr
Date: Fri Apr 11 12:43:01 2008
New Revision: 1267
URL: http://svn.gnome.org/viewvc/tracker?rev=1267&view=rev
Log:
Added module for HAL specific code and cleaned up process-files
module, fixes bug 503725
Added:
trunk/src/trackerd/tracker-hal.c
trunk/src/trackerd/tracker-hal.h
Modified:
trunk/ChangeLog
trunk/configure.ac
trunk/src/libtracker-common/tracker-config.c
trunk/src/libtracker-common/tracker-config.h
trunk/src/trackerd/Makefile.am
trunk/src/trackerd/tracker-db.c
trunk/src/trackerd/tracker-dbus-methods.c
trunk/src/trackerd/tracker-email-kmail.c
trunk/src/trackerd/tracker-fam.c
trunk/src/trackerd/tracker-indexer.c
trunk/src/trackerd/tracker-inotify.c
trunk/src/trackerd/tracker-process-files.c
trunk/src/trackerd/tracker-process-files.h
trunk/src/trackerd/tracker-utils.c
trunk/src/trackerd/tracker-utils.h
trunk/src/trackerd/trackerd.c
Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Fri Apr 11 12:43:01 2008
@@ -268,7 +268,7 @@
AC_ARG_ENABLE(hal, AS_HELP_STRING([--disable-hal],[Disable HAL support for ac power detection]),,[enable_hal=yes])
if test "x$enable_hal" = "xyes"; then
- PKG_CHECK_MODULES(HAL, [hal >= 0.5], [have_hal=yes] , [have_hal=no])
+ PKG_CHECK_MODULES(HAL, [hal >= 0.5 hal-storage], [have_hal=yes] , [have_hal=no])
AC_SUBST(HAL_CFLAGS)
AC_SUBST(HAL_LIBS)
else
@@ -279,6 +279,8 @@
AC_DEFINE(HAVE_HAL, [], [Define if we have HAL])
fi
+AM_CONDITIONAL(HAVE_HAL, test "x$have_hal" = "xyes")
+
####################################################################
# check for GStreamer or Xine. Otherwise, call an external video
# player (Totem or MPlayer).
@@ -845,7 +847,7 @@
inotify header location: $inotify_header
ioprio support: $ioprio_support
Win32: $native_win32
- HAL (battery detection) support: $have_hal
+ HAL support: $have_hal
unac accent stripper support: $enable_unac
deskbar-applet support: $enable_deskbar_applet
build search tool (GNOME): $have_gnome
Modified: trunk/src/libtracker-common/tracker-config.c
==============================================================================
--- trunk/src/libtracker-common/tracker-config.c (original)
+++ trunk/src/libtracker-common/tracker-config.c Fri Apr 11 12:43:01 2008
@@ -55,10 +55,11 @@
#define KEY_MAX_WORD_LENGTH "MaxWorldLength"
#define KEY_LANGUAGE "Language"
#define KEY_ENABLE_STEMMER "EnableStemmer"
-#define KEY_SKIP_MOUNT_POINTS "SkipMountPoints"
#define KEY_DISABLE_INDEXING_ON_BATTERY "BatteryIndex"
#define KEY_DISABLE_INDEXING_ON_BATTERY_INIT "BatteryIndexInitial"
#define KEY_LOW_DISK_SPACE_LIMIT "LowDiskSpaceLimit"
+#define KEY_INDEX_MOUNTED_DIRECTORIES "IndexMountedDirectories"
+#define KEY_INDEX_REMOVABLE_DEVICES "IndexRemovableMedia"
#define GROUP_EMAILS "Emails"
#define KEY_EMAIL_CLIENT "IndexEMailClient"
@@ -87,9 +88,10 @@
#define DEFAULT_MIN_WORD_LENGTH 3 /* 0->30 */
#define DEFAULT_MAX_WORD_LENGTH 30 /* 0->200 */
#define DEFAULT_ENABLE_STEMMER TRUE
-#define DEFAULT_SKIP_MOUNT_POINTS FALSE
#define DEFAULT_DISABLE_INDEXING_ON_BATTERY TRUE
#define DEFAULT_DISABLE_INDEXING_ON_BATTERY_INIT FALSE
+#define DEFAULT_INDEX_MOUNTED_DIRECTORIES TRUE
+#define DEFAULT_INDEX_REMOVABLE_DEVICES TRUE
#define DEFAULT_INDEX_EMAIL_CLIENT "evolution"
#define DEFAULT_LOW_DISK_SPACE_LIMIT 1 /* 0->100 / -1 */
#define DEFAULT_MAX_TEXT_TO_INDEX 1048576 /* Bytes */
@@ -128,10 +130,11 @@
gint max_word_length;
gchar *language;
gboolean enable_stemmer;
- gboolean skip_mount_points;
gboolean disable_indexing_on_battery;
gboolean disable_indexing_on_battery_init;
gint low_disk_space_limit;
+ gboolean index_mounted_directories;
+ gboolean index_removable_devices;
/* Emails */
gchar *email_client;
@@ -184,10 +187,11 @@
PROP_MAX_WORD_LENGTH,
PROP_LANGUAGE,
PROP_ENABLE_STEMMER,
- PROP_SKIP_MOUNT_POINTS,
PROP_DISABLE_INDEXING_ON_BATTERY,
PROP_DISABLE_INDEXING_ON_BATTERY_INIT,
PROP_LOW_DISK_SPACE_LIMIT,
+ PROP_INDEX_MOUNTED_DIRECTORIES,
+ PROP_INDEX_REMOVABLE_DEVICES,
/* Emails */
PROP_EMAIL_CLIENT,
@@ -358,14 +362,6 @@
DEFAULT_ENABLE_STEMMER,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class,
- PROP_SKIP_MOUNT_POINTS,
- g_param_spec_boolean ("skip-mount-points",
- "Skip mount points",
- "Don't traverse mount points "
- "when indexing",
- DEFAULT_SKIP_MOUNT_POINTS,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
- g_object_class_install_property (object_class,
PROP_DISABLE_INDEXING_ON_BATTERY,
g_param_spec_boolean ("disable-indexing-on-battery",
"Disable indexing on battery",
@@ -391,6 +387,22 @@
100,
DEFAULT_LOW_DISK_SPACE_LIMIT,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+ g_object_class_install_property (object_class,
+ PROP_INDEX_MOUNTED_DIRECTORIES,
+ g_param_spec_boolean ("index-mounted-directories",
+ "Index mounted directories",
+ "Don't traverse mounted directories "
+ "which are not on the same file system",
+ DEFAULT_INDEX_MOUNTED_DIRECTORIES,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+ g_object_class_install_property (object_class,
+ PROP_INDEX_REMOVABLE_DEVICES,
+ g_param_spec_boolean ("index-removable-devices",
+ "index removable devices",
+ "Don't traverse mounted directories "
+ "which are for removable devices",
+ DEFAULT_INDEX_REMOVABLE_DEVICES,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
/* Emails */
g_object_class_install_property (object_class,
@@ -578,9 +590,6 @@
case PROP_ENABLE_STEMMER:
g_value_set_boolean (value, priv->enable_stemmer);
break;
- case PROP_SKIP_MOUNT_POINTS:
- g_value_set_boolean (value, priv->skip_mount_points);
- break;
case PROP_DISABLE_INDEXING_ON_BATTERY:
g_value_set_boolean (value, priv->disable_indexing_on_battery);
break;
@@ -590,6 +599,12 @@
case PROP_LOW_DISK_SPACE_LIMIT:
g_value_set_int (value, priv->low_disk_space_limit);
break;
+ case PROP_INDEX_MOUNTED_DIRECTORIES:
+ g_value_set_boolean (value, priv->index_mounted_directories);
+ break;
+ case PROP_INDEX_REMOVABLE_DEVICES:
+ g_value_set_boolean (value, priv->index_removable_devices);
+ break;
/* Emails */
case PROP_EMAIL_CLIENT:
@@ -704,10 +719,6 @@
tracker_config_set_enable_stemmer (TRACKER_CONFIG (object),
g_value_get_boolean (value));
break;
- case PROP_SKIP_MOUNT_POINTS:
- tracker_config_set_skip_mount_points (TRACKER_CONFIG (object),
- g_value_get_boolean (value));
- break;
case PROP_DISABLE_INDEXING_ON_BATTERY:
tracker_config_set_disable_indexing_on_battery (TRACKER_CONFIG (object),
g_value_get_boolean (value));
@@ -720,6 +731,14 @@
tracker_config_set_low_disk_space_limit (TRACKER_CONFIG (object),
g_value_get_int (value));
break;
+ case PROP_INDEX_MOUNTED_DIRECTORIES:
+ tracker_config_set_index_mounted_directories (TRACKER_CONFIG (object),
+ g_value_get_boolean (value));
+ break;
+ case PROP_INDEX_REMOVABLE_DEVICES:
+ tracker_config_set_index_removable_devices (TRACKER_CONFIG (object),
+ g_value_get_boolean (value));
+ break;
/* Emails */
case PROP_EMAIL_CLIENT:
@@ -1013,10 +1032,6 @@
g_key_file_set_comment (key_file, GROUP_INDEXING, KEY_ENABLE_STEMMER,
" Set to false to disable language specific stemmer",
NULL);
- g_key_file_set_boolean (key_file, GROUP_INDEXING, KEY_SKIP_MOUNT_POINTS, DEFAULT_SKIP_MOUNT_POINTS);
- g_key_file_set_comment (key_file, GROUP_INDEXING, KEY_SKIP_MOUNT_POINTS,
- " Set to true to disable traversing directories on mount points",
- NULL);
g_key_file_set_boolean (key_file, GROUP_INDEXING, KEY_DISABLE_INDEXING_ON_BATTERY, DEFAULT_DISABLE_INDEXING_ON_BATTERY);
g_key_file_set_comment (key_file, GROUP_INDEXING, KEY_DISABLE_INDEXING_ON_BATTERY,
" Set to true to disable indexing when running on battery",
@@ -1030,6 +1045,15 @@
" Pause indexer when disk space is <= this value\n"
" (0->100, value is in % of $HOME file system, -1=disable pausing)",
NULL);
+ g_key_file_set_boolean (key_file, GROUP_INDEXING, KEY_INDEX_MOUNTED_DIRECTORIES, DEFAULT_INDEX_MOUNTED_DIRECTORIES);
+ g_key_file_set_comment (key_file, GROUP_INDEXING, KEY_INDEX_MOUNTED_DIRECTORIES,
+ " Set to true to enable traversing mounted directories on other file systems\n"
+ " (this excludes removable devices)",
+ NULL);
+ g_key_file_set_boolean (key_file, GROUP_INDEXING, KEY_INDEX_REMOVABLE_DEVICES, DEFAULT_INDEX_REMOVABLE_DEVICES);
+ g_key_file_set_comment (key_file, GROUP_INDEXING, KEY_INDEX_REMOVABLE_DEVICES,
+ " Set to true to enable traversing mounted directories for removable devices",
+ NULL);
/* Emails */
g_key_file_set_string (key_file, GROUP_EMAILS, KEY_EMAIL_CLIENT, DEFAULT_INDEX_EMAIL_CLIENT);
@@ -1290,10 +1314,11 @@
config_load_int (config, "max-word-length", key_file, GROUP_INDEXING, KEY_MAX_WORD_LENGTH);
config_load_string (config, "language", key_file, GROUP_INDEXING, KEY_LANGUAGE);
config_load_boolean (config, "enable-stemmer", key_file, GROUP_INDEXING, KEY_ENABLE_STEMMER);
- config_load_boolean (config, "skip-mount-points", key_file, GROUP_INDEXING, KEY_SKIP_MOUNT_POINTS);
config_load_boolean (config, "disable-indexing-on-battery", key_file, GROUP_INDEXING, KEY_DISABLE_INDEXING_ON_BATTERY);
config_load_boolean (config, "disable-indexing-on-battery-init", key_file, GROUP_INDEXING, KEY_DISABLE_INDEXING_ON_BATTERY_INIT);
config_load_int (config, "low-disk-space-limit", key_file, GROUP_INDEXING, KEY_LOW_DISK_SPACE_LIMIT);
+ config_load_boolean (config, "index-mounted-directories", key_file, GROUP_INDEXING, KEY_INDEX_MOUNTED_DIRECTORIES);
+ config_load_boolean (config, "index-removable-devices", key_file, GROUP_INDEXING, KEY_INDEX_REMOVABLE_DEVICES);
/* Emails */
config_load_string (config, "email-client", key_file, GROUP_EMAILS, KEY_EMAIL_CLIENT);
@@ -1552,18 +1577,6 @@
}
gboolean
-tracker_config_get_skip_mount_points (TrackerConfig *config)
-{
- TrackerConfigPriv *priv;
-
- g_return_val_if_fail (TRACKER_IS_CONFIG (config), DEFAULT_SKIP_MOUNT_POINTS);
-
- priv = GET_PRIV (config);
-
- return priv->skip_mount_points;
-}
-
-gboolean
tracker_config_get_disable_indexing_on_battery (TrackerConfig *config)
{
TrackerConfigPriv *priv;
@@ -1599,6 +1612,30 @@
return priv->low_disk_space_limit;
}
+gboolean
+tracker_config_get_index_mounted_directories (TrackerConfig *config)
+{
+ TrackerConfigPriv *priv;
+
+ g_return_val_if_fail (TRACKER_IS_CONFIG (config), DEFAULT_INDEX_MOUNTED_DIRECTORIES);
+
+ priv = GET_PRIV (config);
+
+ return priv->index_mounted_directories;
+}
+
+gboolean
+tracker_config_get_index_removable_devices (TrackerConfig *config)
+{
+ TrackerConfigPriv *priv;
+
+ g_return_val_if_fail (TRACKER_IS_CONFIG (config), DEFAULT_INDEX_REMOVABLE_DEVICES);
+
+ priv = GET_PRIV (config);
+
+ return priv->index_removable_devices;
+}
+
const gchar *
tracker_config_get_email_client (TrackerConfig *config)
{
@@ -1935,20 +1972,6 @@
}
void
-tracker_config_set_skip_mount_points (TrackerConfig *config,
- gboolean value)
-{
- TrackerConfigPriv *priv;
-
- g_return_if_fail (TRACKER_IS_CONFIG (config));
-
- priv = GET_PRIV (config);
-
- priv->skip_mount_points = value;
- g_object_notify (G_OBJECT (config), "skip-mount-points");
-}
-
-void
tracker_config_set_disable_indexing_on_battery (TrackerConfig *config,
gboolean value)
{
@@ -1995,23 +2018,51 @@
}
void
+tracker_config_set_index_mounted_directories (TrackerConfig *config,
+ gboolean value)
+{
+ TrackerConfigPriv *priv;
+
+ g_return_if_fail (TRACKER_IS_CONFIG (config));
+
+ priv = GET_PRIV (config);
+
+ priv->index_mounted_directories = value;
+ g_object_notify (G_OBJECT (config), "index-mounted-directories");
+}
+
+void
+tracker_config_set_index_removable_devices (TrackerConfig *config,
+ gboolean value)
+{
+ TrackerConfigPriv *priv;
+
+ g_return_if_fail (TRACKER_IS_CONFIG (config));
+
+ priv = GET_PRIV (config);
+
+ priv->index_removable_devices = value;
+ g_object_notify (G_OBJECT (config), "index-removable-devices");
+}
+
+void
tracker_config_set_email_client (TrackerConfig *config,
const gchar *value)
{
TrackerConfigPriv *priv;
- gchar *email_client;
g_return_if_fail (TRACKER_IS_CONFIG (config));
priv = GET_PRIV (config);
- email_client = g_strdup (value);
+ g_free (priv->email_client);
- if (priv->email_client) {
- g_free (priv->email_client);
+ if (value) {
+ priv->email_client = g_strdup (value);
+ } else {
+ priv->email_client = NULL;
}
- priv->email_client = email_client;
g_object_notify (G_OBJECT (config), "email-client");
}
Modified: trunk/src/libtracker-common/tracker-config.h
==============================================================================
--- trunk/src/libtracker-common/tracker-config.h (original)
+++ trunk/src/libtracker-common/tracker-config.h Fri Apr 11 12:43:01 2008
@@ -68,10 +68,11 @@
gint tracker_config_get_max_word_length (TrackerConfig *config);
const gchar * tracker_config_get_language (TrackerConfig *config);
gboolean tracker_config_get_enable_stemmer (TrackerConfig *config);
-gboolean tracker_config_get_skip_mount_points (TrackerConfig *config);
gboolean tracker_config_get_disable_indexing_on_battery (TrackerConfig *config);
gboolean tracker_config_get_disable_indexing_on_battery_init (TrackerConfig *config);
gint tracker_config_get_low_disk_space_limit (TrackerConfig *config);
+gboolean tracker_config_get_index_removable_devices (TrackerConfig *config);
+gboolean tracker_config_get_index_mounted_directories (TrackerConfig *config);
const gchar * tracker_config_get_email_client (TrackerConfig *config);
gint tracker_config_get_max_text_to_index (TrackerConfig *config);
gint tracker_config_get_max_words_to_index (TrackerConfig *config);
@@ -108,14 +109,16 @@
const gchar *value);
void tracker_config_set_enable_stemmer (TrackerConfig *config,
gboolean value);
-void tracker_config_set_skip_mount_points (TrackerConfig *config,
- gboolean value);
void tracker_config_set_disable_indexing_on_battery (TrackerConfig *config,
gboolean value);
void tracker_config_set_disable_indexing_on_battery_init (TrackerConfig *config,
gboolean value);
void tracker_config_set_low_disk_space_limit (TrackerConfig *config,
gint value);
+void tracker_config_set_index_removable_devices (TrackerConfig *config,
+ gboolean value);
+void tracker_config_set_index_mounted_directories (TrackerConfig *config,
+ gboolean value);
void tracker_config_set_email_client (TrackerConfig *config,
const gchar *value);
void tracker_config_set_max_text_to_index (TrackerConfig *config,
Modified: trunk/src/trackerd/Makefile.am
==============================================================================
--- trunk/src/trackerd/Makefile.am (original)
+++ trunk/src/trackerd/Makefile.am Fri Apr 11 12:43:01 2008
@@ -40,6 +40,12 @@
unix_sources = tracker-os-dependant-unix.c
endif
+if HAVE_HAL
+hal_sources = \
+ tracker-hal.c \
+ tracker-hal.h
+endif
+
db_sources = \
tracker-indexer.c \
tracker-indexer.h \
@@ -60,6 +66,7 @@
$(watch_sources) \
$(win_sources) \
$(unix_sources) \
+ $(hal_sources) \
$(db_sources) \
tracker-apps.c \
tracker-apps.h \
Modified: trunk/src/trackerd/tracker-db.c
==============================================================================
--- trunk/src/trackerd/tracker-db.c (original)
+++ trunk/src/trackerd/tracker-db.c Fri Apr 11 12:43:01 2008
@@ -33,6 +33,7 @@
#include "tracker-metadata.h"
#include "tracker-os-dependant.h"
#include "tracker-service-manager.h"
+#include "tracker-process-files.h"
extern Tracker *tracker;
@@ -172,8 +173,8 @@
g_return_val_if_fail (db_con, info);
g_return_val_if_fail (info, info);
- if (!tracker_file_info_is_valid (info)) {
- return info;
+ if (!tracker_process_files_is_file_info_valid (info)) {
+ return NULL;
}
name = g_path_get_basename (info->uri);
@@ -636,14 +637,15 @@
static gboolean
index_black_list ()
{
+ GSList *black_list;
- g_slist_foreach (tracker->tmp_black_list, (GFunc) index_blacklist_file, NULL);
-
- g_slist_foreach (tracker->tmp_black_list, (GFunc) g_free, NULL);
-
- g_slist_free (tracker->tmp_black_list);
-
- tracker->tmp_black_list = NULL;
+ black_list = tracker_process_files_get_temp_black_list ();
+ g_slist_foreach (black_list,
+ (GFunc) index_blacklist_file,
+ NULL);
+ g_slist_free (black_list);
+
+ tracker_process_files_set_temp_black_list (NULL);
tracker->black_list_timer_active = FALSE;
@@ -703,7 +705,7 @@
tracker_log ("blacklisting %s", change->uri);
- tracker->tmp_black_list = g_slist_prepend (tracker->tmp_black_list, g_strdup (change->uri));
+ tracker_process_files_append_temp_black_list (change->uri);
if (!tracker->black_list_timer_active) {
tracker->black_list_timer_active = TRUE;
Modified: trunk/src/trackerd/tracker-dbus-methods.c
==============================================================================
--- trunk/src/trackerd/tracker-dbus-methods.c (original)
+++ trunk/src/trackerd/tracker-dbus-methods.c Fri Apr 11 12:43:01 2008
@@ -503,9 +503,12 @@
} else if (strcasecmp (option, "GenerateThumbs") == 0) {
tracker_config_set_enable_thumbnails (tracker->config, value);
tracker_log ("Generate thumbnails set to %d", value);
- } else if (strcasecmp (option, "SkipMountPoints") == 0) {
- tracker_config_set_skip_mount_points (tracker->config, value);
- tracker_log ("Skip mounted directories set to %d", value);
+ } else if (strcasecmp (option, "IndexMountedDirectories") == 0) {
+ tracker_config_set_index_mounted_directories (tracker->config, value);
+ tracker_log ("Index mounted directories set to %d", value);
+ } else if (strcasecmp (option, "IndexRemovableDevices") == 0) {
+ tracker_config_set_index_removable_devices (tracker->config, value);
+ tracker_log ("Index removable media set to %d", value);
} else if (strcasecmp (option, "BatteryIndex") == 0) {
tracker_config_set_disable_indexing_on_battery (tracker->config, !value);
tracker_log ("Disable index on battery set to %d", !value);
Modified: trunk/src/trackerd/tracker-email-kmail.c
==============================================================================
--- trunk/src/trackerd/tracker-email-kmail.c (original)
+++ trunk/src/trackerd/tracker-email-kmail.c Fri Apr 11 12:43:01 2008
@@ -30,6 +30,7 @@
#include "tracker-email-utils.h"
#include "tracker-db-email.h"
#include "tracker-watch.h"
+#include "tracker-process-files.h"
typedef struct {
gchar *imap_path;
@@ -640,20 +641,20 @@
g_return_val_if_fail (db_con, NULL);
g_return_val_if_fail (dir_path, NULL);
- if (tracker_file_is_no_watched (dir_path)) {
+ if (!tracker_process_files_should_be_watched (tracker->config, dir_path)) {
return NULL;
}
dirs = NULL;
tmp_dirs = NULL;
- tracker_get_all_dirs (dir_path, &tmp_dirs);
+ tracker_process_files_get_all_dirs (tracker, dir_path, &tmp_dirs);
for (dir = tmp_dirs; dir; dir = dir->next) {
gchar *dir_path = g_unescape_uri_string (dir->data, "");
gchar *dir_name = g_path_get_basename (dir_path);
- if (!tracker_file_is_no_watched (dir_path) && !ignore_email (dir_path) &&
+ if (tracker_process_files_should_be_watched (tracker->config, dir_path) && !ignore_email (dir_path) &&
(( in_imap_dir && dir_name[0] == '.' && g_str_has_suffix (dir_name, ".directory")) ||
!in_imap_dir )
) {
Modified: trunk/src/trackerd/tracker-fam.c
==============================================================================
--- trunk/src/trackerd/tracker-fam.c (original)
+++ trunk/src/trackerd/tracker-fam.c Fri Apr 11 12:43:01 2008
@@ -199,7 +199,10 @@
continue;
}
- if (file_utf8_uri[0] != '/' || tracker_ignore_file (file_utf8_uri) || tracker_file_is_crawled (file_utf8_uri) || tracker_file_is_no_watched (file_utf8_uri)) {
+ if (file_utf8_uri[0] != '/' ||
+ tracker_process_files_should_be_ignored (tracker->config, file_utf8_uri) ||
+ tracker_process_files_should_be_crawled (tracker, file_utf8_uri) ||
+ tracker_process_files_should_be_watched (tracker->config, file_utf8_uri)) {
g_free (file_utf8_uri);
continue;
Added: trunk/src/trackerd/tracker-hal.c
==============================================================================
--- (empty file)
+++ trunk/src/trackerd/tracker-hal.c Fri Apr 11 12:43:01 2008
@@ -0,0 +1,906 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * 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 General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <config.h>
+
+#ifdef HAVE_HAL
+
+#include <string.h>
+
+#include <libhal.h>
+#include <libhal-storage.h>
+
+#include <dbus/dbus-glib-lowlevel.h>
+
+#include <libtracker-common/tracker-log.h>
+
+#include "tracker-db.h"
+#include "tracker-hal.h"
+#include "tracker-utils.h"
+
+#define DEVICE_AC_ADAPTER "ac_adapter"
+#define DEVICE_VOLUME "volume"
+
+#define PROP_AC_ADAPTER_ON "ac_adapter.present"
+#define PROP_IS_MOUNTED "volume.is_mounted"
+
+#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_HAL, TrackerHalPriv))
+
+typedef struct {
+ LibHalContext *context;
+
+ GHashTable *all_devices;
+ GHashTable *mounted_devices;
+ GHashTable *removable_devices;
+
+ gchar *battery_udi;
+ gboolean battery_in_use;
+} TrackerHalPriv;
+
+typedef struct {
+ LibHalContext *context;
+ GSList *roots;
+} GetRoots;
+
+static void tracker_hal_class_init (TrackerHalClass *klass);
+static void tracker_hal_init (TrackerHal *hal);
+static void tracker_hal_finalize (GObject *object);
+static void hal_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec);
+static gboolean hal_setup_devices (TrackerHal *hal);
+static gboolean hal_setup_batteries (TrackerHal *hal);
+static gboolean hal_device_add (TrackerHal *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,
+ PROP_BATTERY_IN_USE,
+ PROP_BATTERY_EXISTS,
+};
+
+enum {
+ SIG_MOUNT_POINT_ADDED,
+ SIG_MOUNT_POINT_REMOVED,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = {0};
+
+G_DEFINE_TYPE (TrackerHal, tracker_hal, G_TYPE_OBJECT);
+
+static void
+tracker_hal_class_init (TrackerHalClass *klass)
+{
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = tracker_hal_finalize;
+ object_class->get_property = hal_get_property;
+
+ signals[SIG_MOUNT_POINT_ADDED] =
+ g_signal_new ("mount-point-added",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__STRING,
+ G_TYPE_NONE,
+ 1, G_TYPE_STRING);
+
+ signals[SIG_MOUNT_POINT_REMOVED] =
+ g_signal_new ("mount-point-removed",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__STRING,
+ G_TYPE_NONE,
+ 1, G_TYPE_STRING);
+
+ g_object_class_install_property (object_class,
+ PROP_BATTERY_IN_USE,
+ g_param_spec_boolean ("battery-in-use",
+ "Battery exists",
+ "There is a battery on this machine",
+ FALSE,
+ G_PARAM_READABLE));
+
+ g_object_class_install_property (object_class,
+ PROP_BATTERY_EXISTS,
+ g_param_spec_boolean ("battery-exists",
+ "Battery exists",
+ "There is a battery on this machine",
+ FALSE,
+ G_PARAM_READABLE));
+
+ g_type_class_add_private (object_class, sizeof (TrackerHalPriv));
+}
+
+static void
+tracker_hal_init (TrackerHal *hal)
+{
+ TrackerHalPriv *priv;
+ DBusError error;
+ DBusConnection *connection;
+
+ priv = GET_PRIV (hal);
+
+ dbus_error_init (&error);
+
+ connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
+ if (dbus_error_is_set (&error)) {
+ tracker_error ("Could not get the system DBus connection, %s",
+ error.message);
+ dbus_error_free (&error);
+ return;
+ }
+
+ dbus_connection_setup_with_g_main (connection, NULL);
+
+ tracker_debug ("Initializing HAL...");
+ priv->context = libhal_ctx_new ();
+
+ if (!priv->context) {
+ tracker_error ("Could not create HAL context");
+ return;
+ }
+
+ libhal_ctx_set_user_data (priv->context, hal);
+ libhal_ctx_set_dbus_connection (priv->context, connection);
+
+ if (!libhal_ctx_init (priv->context, &error)) {
+ if (dbus_error_is_set (&error)) {
+ tracker_error ("Could not initialise the HAL context, %s",
+ error.message);
+ dbus_error_free (&error);
+ } else {
+ tracker_error ("Could not initialise the HAL context, "
+ "no error, is hald running?");
+ }
+
+ libhal_ctx_free (priv->context);
+ return;
+ }
+
+ priv->all_devices = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) g_free);
+
+ priv->mounted_devices = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) g_free);
+
+ priv->removable_devices = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) g_free);
+
+ /* Volume and property notification callbacks */
+ tracker_debug ("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 (hal)) {
+ return;
+ }
+
+ /* Get all battery devices and set them up */
+ if (!hal_setup_batteries (hal)) {
+ return;
+ }
+}
+
+static void
+tracker_hal_finalize (GObject *object)
+{
+ TrackerHalPriv *priv;
+
+ priv = GET_PRIV (object);
+
+ g_hash_table_destroy (priv->removable_devices);
+ g_hash_table_destroy (priv->mounted_devices);
+ g_hash_table_destroy (priv->all_devices);
+
+ g_free (priv->battery_udi);
+
+ libhal_ctx_set_user_data (priv->context, NULL);
+ libhal_ctx_free (priv->context);
+
+ (G_OBJECT_CLASS (tracker_hal_parent_class)->finalize) (object);
+}
+
+static void
+hal_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerHalPriv *priv;
+
+ priv = GET_PRIV (object);
+
+ switch (param_id) {
+ case PROP_BATTERY_IN_USE:
+ g_value_set_boolean (value, priv->battery_in_use);
+ break;
+ case PROP_BATTERY_EXISTS:
+ g_value_set_boolean (value, priv->battery_udi != NULL);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ };
+}
+
+static gboolean
+hal_setup_devices (TrackerHal *hal)
+{
+ TrackerHalPriv *priv;
+ DBusError error;
+ gchar **devices, **p;
+ gint num;
+
+ priv = GET_PRIV (hal);
+
+ dbus_error_init (&error);
+
+ devices = libhal_find_device_by_capability (priv->context,
+ DEVICE_VOLUME,
+ &num,
+ &error);
+
+ if (dbus_error_is_set (&error)) {
+ tracker_error ("Could not get devices with 'volume' capability, %s",
+ error.message);
+ dbus_error_free (&error);
+ return FALSE;
+ }
+
+ if (!devices || !devices[0]) {
+ tracker_log ("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;
+ }
+
+ tracker_debug ("HAL device found:\n"
+ " - udi : %s\n"
+ " - mount point: %s\n"
+ " - device file: %s\n"
+ " - uuid : %s\n"
+ " - mounted : %s\n"
+ " - file system: %s\n"
+ " - label : %s",
+ libhal_volume_get_udi (volume),
+ libhal_volume_get_mount_point (volume),
+ libhal_volume_get_device_file (volume),
+ libhal_volume_get_uuid (volume),
+ libhal_volume_is_mounted (volume) ? "yes" : "no",
+ libhal_volume_get_fstype (volume),
+ libhal_volume_get_label (volume));
+
+ hal_device_add (hal, volume);
+ libhal_volume_free (volume);
+ }
+
+ libhal_free_string_array (devices);
+
+ return TRUE;
+}
+
+static gboolean
+hal_setup_batteries (TrackerHal *hal)
+{
+ TrackerHalPriv *priv;
+ DBusError error;
+ gchar **devices, **p;
+ gint num;
+
+ priv = GET_PRIV (hal);
+
+ dbus_error_init (&error);
+
+ devices = libhal_find_device_by_capability (priv->context,
+ DEVICE_AC_ADAPTER,
+ &num,
+ &error);
+
+ if (dbus_error_is_set (&error)) {
+ tracker_error ("Could not get AC adapter capable devices, %s",
+ error.message);
+ dbus_error_free (&error);
+ return FALSE;
+ }
+
+ tracker_log ("HAL found %d AC adapter capable devices", num);
+
+ if (!devices || !devices[0]) {
+ libhal_free_string_array (devices);
+
+ priv->battery_in_use = FALSE;
+ priv->battery_udi = NULL;
+
+ return TRUE;
+ }
+
+ for (p = devices; *p; p++) {
+ if (!priv->battery_udi) {
+ /* For now just use the first one we find */
+ priv->battery_udi = g_strdup (*p);
+ tracker_log (" - Device '%s' (default)", *p);
+ } else {
+ tracker_log (" - Device '%s'", *p);
+ }
+ }
+
+ libhal_free_string_array (devices);
+
+ /* Make sure we watch changes to the battery use */
+ libhal_device_add_property_watch (priv->context,
+ priv->battery_udi,
+ &error);
+
+ if (dbus_error_is_set (&error)) {
+ tracker_error ("Could not add device:'%s' to property watch, %s",
+ priv->battery_udi, error.message);
+ dbus_error_free (&error);
+ return FALSE;
+ }
+
+ /* Get current state, are we using the battery now? */
+ priv->battery_in_use = !libhal_device_get_property_bool (priv->context,
+ priv->battery_udi,
+ PROP_AC_ADAPTER_ON,
+ NULL);
+
+ tracker_log ("HAL reports system is currently powered by %s",
+ priv->battery_in_use ? "battery" : "AC adapter");
+
+ return TRUE;
+}
+
+static void
+hal_mount_point_add (TrackerHal *hal,
+ const gchar *udi,
+ const gchar *mount_point,
+ gboolean removable_device)
+{
+ TrackerHalPriv *priv;
+
+ priv = GET_PRIV (hal);
+
+ tracker_log ("HAL device with mount point:'%s', removable:%s now being tracked",
+ mount_point,
+ removable_device ? "yes" : "no");
+
+ g_hash_table_insert (priv->mounted_devices,
+ g_strdup (udi),
+ g_strdup (mount_point));
+
+ if (removable_device) {
+ g_hash_table_insert (priv->removable_devices,
+ g_strdup (udi),
+ g_strdup (mount_point));
+ }
+
+ g_signal_emit (hal, signals[SIG_MOUNT_POINT_ADDED], 0, mount_point, NULL);
+}
+
+static void
+hal_mount_point_remove (TrackerHal *hal,
+ const gchar *udi)
+{
+ TrackerHalPriv *priv;
+ const gchar *mount_point;
+
+ priv = GET_PRIV (hal);
+
+ mount_point = g_hash_table_lookup (priv->mounted_devices, udi);
+ if (!mount_point) {
+ return;
+ }
+
+ tracker_log ("HAL device with mount point:'%s', removable:%s NO LONGER being tracked",
+ mount_point,
+ g_hash_table_remove (priv->removable_devices, udi) ? "yes" : "no");
+
+ g_signal_emit (hal, signals[SIG_MOUNT_POINT_REMOVED], 0, mount_point, NULL);
+
+ g_hash_table_remove (priv->mounted_devices, udi);
+ g_hash_table_remove (priv->removable_devices, udi);
+}
+
+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";
+ }
+
+ return "";
+}
+
+static gboolean
+hal_device_is_removable (TrackerHal *hal,
+ const gchar *device_file)
+{
+ TrackerHalPriv *priv;
+ LibHalDrive *drive;
+ gboolean removable;
+
+ if (!device_file) {
+ return FALSE;
+ }
+
+ priv = GET_PRIV (hal);
+
+ drive = libhal_drive_from_device_file (priv->context, device_file);
+ if (!drive) {
+ return FALSE;
+ }
+
+ removable = libhal_drive_uses_removable_media (drive);
+ libhal_drive_free (drive);
+
+ return removable;
+}
+
+static gboolean
+hal_device_should_be_tracked (TrackerHal *hal,
+ const gchar *device_file)
+{
+ TrackerHalPriv *priv;
+ LibHalDrive *drive;
+ LibHalDriveType drive_type;
+ gboolean eligible;
+
+ if (!device_file) {
+ return FALSE;
+ }
+
+ priv = GET_PRIV (hal);
+
+ 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) {
+ tracker_debug ("HAL device is not eligible, type is '%s'",
+ hal_drive_type_to_string (drive_type));
+ } else {
+ tracker_debug ("HAL device is eligible, type is '%s'",
+ hal_drive_type_to_string (drive_type));
+ }
+
+ return eligible;
+}
+
+static gboolean
+hal_device_add (TrackerHal *hal,
+ LibHalVolume *volume)
+{
+ TrackerHalPriv *priv;
+ DBusError error;
+ const gchar *udi;
+ const gchar *mount_point;
+ const gchar *device_file;
+
+ priv = GET_PRIV (hal);
+
+ 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 (hal, device_file)) {
+ tracker_log ("HAL device should not be tracked (not eligible)");
+ 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)) {
+ tracker_error ("Could not add device property watch for udi:'%s', %s",
+ 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 (hal,
+ udi,
+ mount_point,
+ hal_device_is_removable (hal, device_file));
+ }
+
+ return TRUE;
+}
+
+static void
+hal_device_added_cb (LibHalContext *context,
+ const gchar *udi)
+{
+ TrackerHal *hal;
+ DBusError error;
+ LibHalVolume *volume;
+
+ dbus_error_init (&error);
+
+ volume = libhal_volume_from_udi (context, udi);
+ if (!volume) {
+ /* Not a device with a volume */
+ return;
+ }
+
+ tracker_log ("HAL device added:\n"
+ " - udi : %s\n"
+ " - mount point: %s\n"
+ " - device file: %s\n"
+ " - uuid : %s\n"
+ " - mounted : %s\n"
+ " - file system: %s\n"
+ " - label : %s",
+ udi,
+ libhal_volume_get_mount_point (volume),
+ libhal_volume_get_device_file (volume),
+ libhal_volume_get_uuid (volume),
+ libhal_volume_is_mounted (volume) ? "yes" : "no",
+ libhal_volume_get_fstype (volume),
+ libhal_volume_get_label (volume));
+
+ hal = (TrackerHal*) libhal_ctx_get_user_data (context);
+ hal_device_add (hal, volume);
+ libhal_volume_free (volume);
+}
+
+static void
+hal_device_removed_cb (LibHalContext *context,
+ const gchar *udi)
+{
+ TrackerHal *hal;
+ TrackerHalPriv *priv;
+ const gchar *device_file;
+ const gchar *mount_point;
+
+ hal = (TrackerHal*) libhal_ctx_get_user_data (context);
+ priv = GET_PRIV (hal);
+
+ device_file = g_hash_table_lookup (priv->all_devices, udi);
+
+ if (!device_file) {
+ /* Don't report about unknown devices */
+ return;
+ }
+
+ mount_point = g_hash_table_lookup (priv->mounted_devices, udi);
+
+ tracker_log ("HAL device removed:\n"
+ " - udi : %s\n"
+ " - mount point: %s\n"
+ " - device_file: %s",
+ udi,
+ mount_point,
+ device_file);
+
+ g_hash_table_remove (priv->all_devices, udi);
+
+ hal_mount_point_remove (hal, 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)
+{
+ TrackerHal *hal;
+ TrackerHalPriv *priv;
+ DBusError error;
+ gboolean device_is_battery;
+ gboolean current_state;
+
+ hal = (TrackerHal*) libhal_ctx_get_user_data (context);
+ priv = GET_PRIV (hal);
+
+ current_state = priv->battery_in_use;
+ device_is_battery = priv->battery_udi && strcmp (priv->battery_udi, udi) == 0;
+
+ if (!device_is_battery &&
+ !g_hash_table_lookup (priv->all_devices, udi)) {
+ tracker_debug ("HAL device property change for another device, ignoring");
+ return;
+ }
+
+ dbus_error_init (&error);
+
+ /* We either get notifications about the battery state OR a
+ * device being mounted/umounted.
+ */
+ if (device_is_battery) {
+ priv->battery_in_use = !libhal_device_get_property_bool (priv->context,
+ priv->battery_udi,
+ PROP_AC_ADAPTER_ON,
+ &error);
+
+ if (dbus_error_is_set (&error)) {
+ tracker_error ("Could not device property:'%s' for udi:'%s', %s",
+ udi, PROP_AC_ADAPTER_ON, error.message);
+ dbus_error_free (&error);
+ return;
+ }
+
+ tracker_log ("HAL reports system is now powered by %s",
+ priv->battery_in_use ? "battery" : "AC adapter");
+
+ /* If we have come off battery power wakeup index thread */
+ if (current_state && !priv->battery_in_use) {
+ tracker_notify_file_data_available ();
+ }
+ } else {
+ gboolean is_mounted;
+
+ tracker_debug ("HAL device property change for udi:'%s' and key:'%s'",
+ 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)) {
+ tracker_error ("Could not get device property:'%s' for udi:'%s', %s",
+ udi, key, error.message);
+ dbus_error_free (&error);
+ return;
+ }
+
+ if (is_mounted) {
+ LibHalVolume *volume;
+ const gchar *mount_point;
+ const gchar *device_file;
+
+ volume = libhal_volume_from_udi (context, udi);
+ mount_point = libhal_volume_get_mount_point (volume);
+ device_file = libhal_volume_get_device_file (volume);
+
+ tracker_log ("HAL device with udi:'%s' is now mounted",
+ udi);
+
+ hal_mount_point_add (hal,
+ udi,
+ mount_point,
+ hal_device_is_removable (hal, device_file));
+
+ libhal_volume_free (volume);
+ } else {
+ tracker_log ("HAL device with udi:'%s' is now unmounted",
+ udi);
+
+ hal_mount_point_remove (hal, udi);
+ }
+ }
+}
+
+TrackerHal *
+tracker_hal_new (void)
+{
+ return g_object_new (TRACKER_TYPE_HAL, NULL);
+}
+
+gboolean
+tracker_hal_get_battery_in_use (TrackerHal *hal)
+{
+ TrackerHalPriv *priv;
+
+ g_return_val_if_fail (TRACKER_IS_HAL (hal), TRUE);
+
+ priv = GET_PRIV (hal);
+
+ return priv->battery_in_use;
+}
+
+gboolean
+tracker_hal_get_battery_exists (TrackerHal *hal)
+{
+ TrackerHalPriv *priv;
+
+ g_return_val_if_fail (TRACKER_IS_HAL (hal), TRUE);
+
+ priv = GET_PRIV (hal);
+
+ return priv->battery_udi != NULL;
+}
+
+static void
+hal_get_mount_point_by_udi_foreach (gpointer key,
+ gpointer value,
+ gpointer user_data)
+{
+ LibHalVolume *volume;
+ GetRoots *gr;
+ const gchar *udi;
+ const gchar *mount_point;
+ gboolean is_mounted;
+
+ gr = (GetRoots*) user_data;
+ udi = (const gchar*) key;
+
+ volume = libhal_volume_from_udi (gr->context, udi);
+ if (!volume) {
+ tracker_debug ("HAL device with udi:'%s' has no volume, "
+ "should we delete?",
+ udi);
+ return;
+ }
+
+ mount_point = libhal_volume_get_mount_point (volume);
+ is_mounted = libhal_volume_is_mounted (volume);
+
+ if (is_mounted && mount_point) {
+ gr->roots = g_slist_prepend (gr->roots, g_strdup (mount_point));
+ }
+
+ libhal_volume_free (volume);
+}
+
+GSList *
+tracker_hal_get_mounted_directory_roots (TrackerHal *hal)
+{
+ TrackerHalPriv *priv;
+ GetRoots gr;
+
+ g_return_val_if_fail (TRACKER_IS_HAL (hal), NULL);
+
+ priv = GET_PRIV (hal);
+
+ gr.context = priv->context;
+ gr.roots = NULL;
+
+ g_hash_table_foreach (priv->mounted_devices,
+ hal_get_mount_point_by_udi_foreach,
+ &gr);
+
+ return gr.roots;
+}
+
+GSList *
+tracker_hal_get_removable_device_roots (TrackerHal *hal)
+{
+ TrackerHalPriv *priv;
+ GetRoots gr;
+
+ g_return_val_if_fail (TRACKER_IS_HAL (hal), NULL);
+
+ priv = GET_PRIV (hal);
+
+ gr.context = priv->context;
+ gr.roots = NULL;
+
+ g_hash_table_foreach (priv->removable_devices,
+ hal_get_mount_point_by_udi_foreach,
+ &gr);
+
+ return gr.roots;
+}
+
+#endif /* HAVE_HAL */
Added: trunk/src/trackerd/tracker-hal.h
==============================================================================
--- (empty file)
+++ trunk/src/trackerd/tracker-hal.h Fri Apr 11 12:43:01 2008
@@ -0,0 +1,61 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * 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 General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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.
+ */
+
+#ifdef HAVE_HAL
+
+#ifndef __TRACKER_HAL_H__
+#define __TRACKER_HAL_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define TRACKER_TYPE_HAL (tracker_hal_get_type ())
+#define TRACKER_HAL(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_HAL, TrackerHal))
+#define TRACKER_HAL_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), TRACKER_TYPE_HAL, TrackerHalClass))
+#define TRACKER_IS_HAL(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_HAL))
+#define TRACKER_IS_HAL_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TRACKER_TYPE_HAL))
+#define TRACKER_HAL_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_HAL, TrackerHalClass))
+
+typedef struct _TrackerHal TrackerHal;
+typedef struct _TrackerHalClass TrackerHalClass;
+
+struct _TrackerHal {
+ GObject parent;
+};
+
+struct _TrackerHalClass {
+ GObjectClass parent_class;
+};
+
+GType tracker_hal_get_type (void) G_GNUC_CONST;
+
+TrackerHal *tracker_hal_new (void);
+gboolean tracker_hal_get_battery_in_use (TrackerHal *hal);
+gboolean tracker_hal_get_battery_exists (TrackerHal *hal);
+GSList * tracker_hal_get_mounted_directory_roots (TrackerHal *hal);
+GSList * tracker_hal_get_removable_device_roots (TrackerHal *hal);
+
+G_END_DECLS
+
+#endif /* __TRACKER_HAL_H__ */
+
+#endif /* HAVE_HAL */
Modified: trunk/src/trackerd/tracker-indexer.c
==============================================================================
--- trunk/src/trackerd/tracker-indexer.c (original)
+++ trunk/src/trackerd/tracker-indexer.c Fri Apr 11 12:43:01 2008
@@ -56,6 +56,8 @@
#include "tracker-dbus.h"
#include "tracker-service-manager.h"
#include "tracker-query-tree.h"
+#include "tracker-hal.h"
+#include "tracker-process-files.h"
extern Tracker *tracker;
@@ -387,8 +389,12 @@
interval = 2000;
}
+#ifdef HAVE_HAL
/* halve the interval value as notebook hard drives are smaller */
- if (tracker->battery_udi) interval = interval / 2;
+ if (tracker_hal_get_battery_exists (tracker->hal)) {
+ interval /= 2;
+ }
+#endif
dpiterinit (src->word_index);
@@ -459,9 +465,9 @@
if (type == INDEX_TYPE_FILES) {
- files = tracker_get_files_with_prefix (tracker->data_dir, "file-index.tmp.");
+ files = tracker_process_files_get_files_with_prefix (tracker, tracker->data_dir, "file-index.tmp.");
} else {
- files = tracker_get_files_with_prefix (tracker->data_dir, "email-index.tmp.");
+ files = tracker_process_files_get_files_with_prefix (tracker, tracker->data_dir, "email-index.tmp.");
}
result = (files != NULL);
@@ -485,10 +491,10 @@
char *final;
if (type == INDEX_TYPE_FILES) {
- files = tracker_get_files_with_prefix (tracker->data_dir, "file-index.tmp.");
+ files = tracker_process_files_get_files_with_prefix (tracker, tracker->data_dir, "file-index.tmp.");
final = g_build_filename(tracker->data_dir, "file-index-final", NULL);
} else {
- files = tracker_get_files_with_prefix (tracker->data_dir, "email-index.tmp.");
+ files = tracker_process_files_get_files_with_prefix (tracker, tracker->data_dir, "email-index.tmp.");
final = g_build_filename (tracker->data_dir, "email-index-final", NULL);
}
@@ -586,7 +592,7 @@
g_free (tmp);
}
- file_list = tracker_get_files_with_prefix (tracker->data_dir, prefix);
+ file_list = tracker_process_files_get_files_with_prefix (tracker, tracker->data_dir, prefix);
if (!file_list || !file_list->data) {
@@ -710,8 +716,12 @@
interval = 3000;
}
+#ifdef HAVE_HAL
/* halve the interval value as notebook hard drives are smaller */
- if (tracker->battery_udi) interval = interval / 2;
+ if (tracker_hal_get_battery_exists (tracker->hal)) {
+ interval /= 2;
+ }
+#endif
}
}
Modified: trunk/src/trackerd/tracker-inotify.c
==============================================================================
--- trunk/src/trackerd/tracker-inotify.c (original)
+++ trunk/src/trackerd/tracker-inotify.c Fri Apr 11 12:43:01 2008
@@ -36,6 +36,7 @@
#include <libtracker-common/tracker-log.h>
#include "tracker-watch.h"
+#include "tracker-process-files.h"
#define INOTIFY_WATCH_LIMIT "/proc/sys/fs/inotify/max_user_watches"
@@ -106,7 +107,7 @@
info = tracker_create_file_info (uri, action, 1, WATCH_OTHER);
- if (!tracker_file_info_is_valid (info)) {
+ if (!tracker_process_files_is_file_info_valid (info)) {
return;
}
@@ -414,9 +415,11 @@
str = g_build_filename(dir_utf8_uri, file_utf8_uri, NULL);
}
-
-
- if (str && str[0] == '/' && (!tracker_ignore_file (str) || action_type == TRACKER_ACTION_DIRECTORY_MOVED_FROM) && !tracker_file_is_crawled (str) && !tracker_file_is_no_watched (str)) {
+ if (str && str[0] == '/' &&
+ (!tracker_process_files_should_be_ignored (str) ||
+ action_type == TRACKER_ACTION_DIRECTORY_MOVED_FROM) &&
+ tracker_process_files_should_be_crawled (tracker, str) &&
+ tracker_process_files_should_be_watched (tracker->config, str)) {
process_event (str, tracker_is_directory (str), action_type, cookie);
} else {
tracker_debug ("ignoring action %d on file %s", action_type, str);
Modified: trunk/src/trackerd/tracker-process-files.c
==============================================================================
--- trunk/src/trackerd/tracker-process-files.c (original)
+++ trunk/src/trackerd/tracker-process-files.c Fri Apr 11 12:43:01 2008
@@ -40,11 +40,38 @@
#include "tracker-dbus-methods.h"
#include "tracker-cache.h"
#include "tracker-email.h"
+#include "tracker-hal.h"
#include "tracker-indexer.h"
#include "tracker-os-dependant.h"
#include "tracker-utils.h"
#include "tracker-watch.h"
#include "tracker-service.h"
+#include "tracker-process-files.h"
+
+static GSList *ignore_pattern_list;
+static GSList *temp_black_list;
+static GSList *crawl_directories;
+
+static gchar **ignore_pattern;
+
+static const gchar *ignore_suffix[] = {
+ "~", ".o", ".la", ".lo", ".loT", ".in",
+ ".csproj", ".m4", ".rej", ".gmo", ".orig",
+ ".pc", ".omf", ".aux", ".tmp", ".po",
+ ".vmdk",".vmx",".vmxf",".vmsd",".nvram",
+ ".part", NULL
+};
+
+static const gchar *ignore_prefix[] = {
+ "autom4te", "conftest.", "confstat",
+ "config.", NULL
+};
+
+static const gchar *ignore_name[] = {
+ "po", "CVS", "aclocal", "Makefile", "CVS",
+ "SCCS", "ltmain.sh","libtool", "config.status",
+ "conftest", "confdefs.h", NULL
+};
static void
process_my_yield (void)
@@ -56,151 +83,208 @@
#endif
}
-static void
-process_watch_list_add_dirs (Tracker *tracker,
- GSList *dir_list,
- gboolean check_dirs)
+static GSList *
+process_get_files (Tracker *tracker,
+ const char *dir,
+ gboolean dir_only,
+ gboolean skip_ignored_files,
+ const char *filter_prefix)
{
- if (!tracker->is_running) {
- return;
+ GDir *dirp;
+ GSList *files;
+ char *dir_in_locale;
+
+ dir_in_locale = g_filename_from_utf8 (dir, -1, NULL, NULL, NULL);
+
+ if (!dir_in_locale) {
+ tracker_error ("ERROR: dir could not be converted to utf8 format");
+ g_free (dir_in_locale);
+ return NULL;
}
-
- /* Add sub directories breadth first recursively to avoid
- * running out of file handles.
- */
- while (dir_list) {
- GSList *file_list = NULL;
- GSList *tmp;
- for (tmp = dir_list; tmp; tmp = tmp->next) {
- gchar *str;
+ files = NULL;
- str = tmp->data;
+ if ((dirp = g_dir_open (dir_in_locale, 0, NULL))) {
+ const gchar *name;
- if (str && !tracker_file_is_no_watched (str)) {
- tracker->dir_list = g_slist_prepend (tracker->dir_list, g_strdup (str));
+ while ((name = g_dir_read_name (dirp))) {
+ gchar *filename;
+ gchar *built_filename;
- if (!tracker_config_get_enable_watches (tracker->config) ||
- tracker_file_is_crawled (str)) {
- continue;
- }
+ if (!tracker->is_running) {
+ g_free (dir_in_locale);
+ g_dir_close (dirp);
+ return NULL;
+ }
- if ((tracker_count_watch_dirs () + g_slist_length (dir_list)) < tracker->watch_limit) {
- if (!tracker_add_watch_dir (str, tracker->index_db) && tracker_is_directory (str)) {
- tracker_debug ("Watch failed for %s", str);
- }
- }
+ filename = g_filename_to_utf8 (name, -1, NULL, NULL, NULL);
+
+ if (!filename) {
+ continue;
}
- }
- g_slist_foreach (dir_list, (GFunc) tracker_get_dirs, &file_list);
- g_slist_foreach (dir_list, (GFunc) g_free, NULL);
- g_slist_free (dir_list);
+ if (filter_prefix && !g_str_has_prefix (filename, filter_prefix)) {
+ g_free (filename);
+ continue;
+ }
- dir_list = file_list;
- }
-}
+ if (skip_ignored_files &&
+ tracker_process_files_should_be_ignored (filename)) {
+ g_free (filename);
+ continue;
+ }
-static gboolean
-process_watch_dir (Tracker *tracker,
- const gchar *dir)
-{
- gchar *dir_utf8;
+ built_filename = g_build_filename (dir, filename, NULL);
+ g_free (filename);
- if (!tracker->is_running) {
- return TRUE;
- }
+ if (!tracker_file_is_valid (built_filename)) {
+ g_free (built_filename);
+ continue;
+ }
- if (!dir) {
- return FALSE;
- }
+ if (!tracker_process_files_should_be_crawled (tracker, built_filename)) {
+ g_free (built_filename);
+ continue;
+ }
- if (!g_utf8_validate (dir, -1, NULL)) {
- dir_utf8 = g_filename_to_utf8 (dir, -1, NULL,NULL,NULL);
- if (!dir_utf8) {
- tracker_error ("ERROR: watch_dir could not be converted to utf8 format");
- return FALSE;
+ if (!dir_only || tracker_is_directory (built_filename)) {
+ if (tracker_process_files_should_be_watched (tracker->config, built_filename)) {
+ files = g_slist_prepend (files, built_filename);
+ } else {
+ g_free (built_filename);
+ }
+ } else {
+ g_free (built_filename);
+ }
}
- } else {
- dir_utf8 = g_strdup (dir);
- }
-
- if (!tracker_file_is_valid (dir_utf8)) {
- g_free (dir_utf8);
- return FALSE;
- }
- if (!tracker_is_directory (dir_utf8)) {
- g_free (dir_utf8);
- return FALSE;
+ g_dir_close (dirp);
}
- if (tracker_file_is_crawled (dir_utf8)) {
- g_free (dir_utf8);
- return FALSE;
- }
+ g_free (dir_in_locale);
- if (!tracker_file_is_no_watched (dir_utf8)) {
- GSList *mylist = NULL;
+ if (!tracker->is_running) {
+ if (files) {
+ g_slist_foreach (files, (GFunc) g_free, NULL);
+ g_slist_free (files);
+ }
- mylist = g_slist_prepend (mylist, dir_utf8);
- process_watch_list_add_dirs (tracker, mylist, TRUE);
+ return NULL;
}
- return TRUE;
+ return files;
}
static void
-process_watch_dir_foreach (const gchar *dir,
- Tracker *tracker)
+process_get_directories (Tracker *tracker,
+ const char *dir,
+ GSList **files)
{
- process_watch_dir (tracker, dir);
+ GSList *l;
+
+ l = process_get_files (tracker, dir, TRUE, TRUE, NULL);
+
+ if (*files) {
+ *files = g_slist_concat (*files, l);
+ } else {
+ *files = l;
+ }
}
static void
-process_schedule_dir_check_foreach (const gchar *uri,
- Tracker *tracker)
+process_watch_directories (Tracker *tracker,
+ GSList *dirs)
{
- if (!tracker->is_running) {
+ GSList *list;
+
+ if (!tracker->is_running) {
return;
}
+
+ /* Add sub directories breadth first recursively to avoid
+ * running out of file handles.
+ */
+ list = dirs;
+
+ while (list) {
+ GSList *files = NULL;
+ GSList *l;
- g_return_if_fail (tracker_check_uri (uri));
- g_return_if_fail (tracker->index_db);
+ for (l = list; l; l = l->next) {
+ gchar *dir;
+ guint watches;
- tracker_db_insert_pending_file (tracker->index_db, 0, uri, NULL, "unknown", 0,
- TRACKER_ACTION_DIRECTORY_REFRESH, TRUE, FALSE, -1);
-}
+ if (!l->data) {
+ continue;
+ }
-static inline void
-process_directory_list (Tracker *tracker,
- GSList *list,
- gboolean recurse)
-{
- tracker->dir_list = NULL;
+ if (!g_utf8_validate (l->data, -1, NULL)) {
+ dir = g_filename_to_utf8 (l->data, -1, NULL,NULL,NULL);
+ if (!dir) {
+ tracker_error ("Directory to watch was not valid UTF-8 and couldn't be converted either");
+ continue;
+ }
+ } else {
+ dir = g_strdup (l->data);
+ }
- if (!list) {
- return;
- }
+ if (!tracker_file_is_valid (dir)) {
+ g_free (dir);
+ continue;
+ }
+
+ if (!tracker_is_directory (dir)) {
+ g_free (dir);
+ continue;
+ }
+
+ if (!tracker_process_files_should_be_watched (tracker->config, dir) ||
+ !tracker_process_files_should_be_watched (tracker->config, dir)) {
+ continue;
+ }
- g_slist_foreach (list,
- (GFunc) process_watch_dir_foreach,
- tracker);
- g_slist_foreach (list,
- (GFunc) process_schedule_dir_check_foreach,
- tracker);
+ crawl_directories = g_slist_prepend (crawl_directories, dir);
+
+ if (!tracker_config_get_enable_watches (tracker->config)) {
+ continue;
+ }
+
+ watches = tracker_count_watch_dirs () + g_slist_length (list);
+
+ if (watches < tracker->watch_limit) {
+ if (!tracker_add_watch_dir (dir, tracker->index_db)) {
+ tracker_debug ("Watch failed for %s", dir);
+ }
+ }
+ }
- if (recurse && tracker->dir_list) {
- g_slist_foreach (tracker->dir_list,
- (GFunc) process_schedule_dir_check_foreach,
- tracker);
+ for (l = list; l; l = l->next) {
+ process_get_directories (tracker, l->data, &files);
+ }
+
+ /* Don't free original list */
+ if (list != dirs) {
+ g_slist_foreach (list, (GFunc) g_free, NULL);
+ g_slist_free (list);
+ }
+
+ list = files;
}
+}
- if (tracker->dir_list) {
- g_slist_foreach (tracker->dir_list, (GFunc) g_free, NULL);
- g_slist_free (tracker->dir_list);
- tracker->dir_list = NULL;
+static void
+process_schedule_directory_check_foreach (const gchar *uri,
+ Tracker *tracker)
+{
+ if (!tracker->is_running) {
+ return;
}
+
+ g_return_if_fail (tracker_check_uri (uri));
+ g_return_if_fail (tracker->index_db);
+
+ tracker_db_insert_pending_file (tracker->index_db, 0, uri, NULL, "unknown", 0,
+ TRACKER_ACTION_DIRECTORY_REFRESH, TRUE, FALSE, -1);
}
static void
@@ -218,9 +302,40 @@
process_my_yield ();
if (!tracker_is_directory (uri)) {
- tracker_db_insert_pending_file (tracker->index_db, 0, uri, NULL, "unknown", 0, TRACKER_ACTION_CHECK, 0, FALSE, -1);
+ tracker_db_insert_pending_file (tracker->index_db, 0, uri, NULL, "unknown", 0,
+ TRACKER_ACTION_CHECK, 0, FALSE, -1);
} else {
- process_schedule_dir_check_foreach (uri, tracker);
+ process_schedule_directory_check_foreach (uri, tracker);
+ }
+}
+
+static inline void
+process_directory_list (Tracker *tracker,
+ GSList *list,
+ gboolean recurse)
+{
+ crawl_directories = NULL;
+
+ if (!list) {
+ return;
+ }
+
+ process_watch_directories (tracker, list);
+
+ g_slist_foreach (list,
+ (GFunc) process_schedule_directory_check_foreach,
+ tracker);
+
+ if (recurse && crawl_directories) {
+ g_slist_foreach (crawl_directories,
+ (GFunc) process_schedule_directory_check_foreach,
+ tracker);
+ }
+
+ if (crawl_directories) {
+ g_slist_foreach (crawl_directories, (GFunc) g_free, NULL);
+ g_slist_free (crawl_directories);
+ crawl_directories = NULL;
}
}
@@ -228,7 +343,7 @@
process_scan_directory (Tracker *tracker,
const gchar *uri)
{
- GSList *file_list;
+ GSList *files;
if (!tracker->is_running) {
return;
@@ -241,21 +356,22 @@
/* Keep mainloop responsive */
process_my_yield ();
- file_list = tracker_get_files (uri, FALSE);
- tracker_debug ("Scanning %s for %d files", uri, g_slist_length(file_list));
+ files = process_get_files (tracker, uri, FALSE, TRUE, NULL);
+
+ tracker_debug ("Scanning %s for %d files", uri, g_slist_length (files));
- g_slist_foreach (file_list,
+ g_slist_foreach (files,
(GFunc) process_schedule_file_check_foreach,
tracker);
- g_slist_foreach (file_list,
+ g_slist_foreach (files,
(GFunc) g_free,
NULL);
- g_slist_free (file_list);
+ g_slist_free (files);
/* Recheck directory to update its mtime if its changed whilst
* scanning.
*/
- process_schedule_dir_check_foreach (uri, tracker);
+ process_schedule_directory_check_foreach (uri, tracker);
tracker_debug ("Finished scanning");
}
@@ -394,13 +510,13 @@
}
static void
-process_delete_file (Tracker *tracker,
- FileInfo *info)
+process_index_delete_file (Tracker *tracker,
+ FileInfo *info)
{
/* Info struct may have been deleted in transit here so check
* if still valid and intact.
*/
- g_return_if_fail (tracker_file_info_is_valid (info));
+ g_return_if_fail (tracker_process_files_is_file_info_valid (info));
/* If we dont have an entry in the db for the deleted file, we
* ignore it.
@@ -415,13 +531,13 @@
}
static void
-process_delete_dir (Tracker *tracker,
- FileInfo *info)
+process_index_delete_directory (Tracker *tracker,
+ FileInfo *info)
{
/* Info struct may have been deleted in transit here so check
* if still valid and intact.
*/
- g_return_if_fail (tracker_file_info_is_valid (info));
+ g_return_if_fail (tracker_process_files_is_file_info_valid (info));
/* If we dont have an entry in the db for the deleted
* directory, we ignore it.
@@ -438,8 +554,8 @@
}
static void
-process_delete_dir_check (Tracker *tracker,
- const gchar *uri)
+process_index_delete_directory_check (Tracker *tracker,
+ const gchar *uri)
{
gchar **files;
gchar **p;
@@ -447,6 +563,10 @@
/* Check for any deletions*/
files = tracker_db_get_files_in_folder (tracker->index_db, uri);
+ if (!files) {
+ return;
+ }
+
for (p = files; *p; p++) {
gchar *str = *p;
@@ -457,9 +577,9 @@
info = tracker_db_get_file_info (tracker->index_db, info);
if (!info->is_directory) {
- process_delete_file (tracker, info);
+ process_index_delete_file (tracker, info);
} else {
- process_delete_dir (tracker, info);
+ process_index_delete_directory (tracker, info);
}
tracker_free_file_info (info);
}
@@ -468,45 +588,6 @@
g_strfreev (files);
}
-static void
-process_add_dirs_to_list (Tracker *tracker,
- GSList *dir_list)
-{
- GSList *new_dir_list = NULL;
- GSList *l;
-
- if (!tracker->is_running) {
- return;
- }
-
- for (l = dir_list; l; l = l->next) {
- if (l) {
- new_dir_list = g_slist_prepend (new_dir_list,
- g_strdup (l->data));
- }
- }
-
- /* Add sub directories breadth first recursively to avoid
- * running out of file handles.
- */
- while (new_dir_list) {
- GSList *file_list = NULL;
-
- for (l = new_dir_list; l; l = l->next) {
- gchar *str = l->data;
-
- if (str && !tracker_file_is_no_watched (str)) {
- tracker->dir_list = g_slist_prepend (tracker->dir_list, g_strdup (str));
- }
- }
-
- g_slist_foreach (new_dir_list, (GFunc) tracker_get_dirs, &file_list);
- g_slist_foreach (new_dir_list, (GFunc) g_free, NULL);
- g_slist_free (new_dir_list);
- new_dir_list = file_list;
- }
-}
-
static inline void
process_queue_files_foreach (const gchar *uri,
gpointer user_data)
@@ -523,7 +604,7 @@
process_check_directory (Tracker *tracker,
const gchar *uri)
{
- GSList *file_list = NULL;
+ GSList *files;
if (!tracker->is_running) {
return;
@@ -532,12 +613,12 @@
g_return_if_fail (tracker_check_uri (uri));
g_return_if_fail (tracker_is_directory (uri));
- file_list = tracker_get_files (uri, FALSE);
- tracker_debug ("Checking %s for %d files", uri, g_slist_length (file_list));
+ files = process_get_files (tracker, uri, FALSE, TRUE, NULL);
+ tracker_debug ("Checking %s for %d files", uri, g_slist_length (files));
- g_slist_foreach (file_list, (GFunc) process_queue_files_foreach, tracker);
- g_slist_foreach (file_list, (GFunc) g_free, NULL);
- g_slist_free (file_list);
+ g_slist_foreach (files, (GFunc) process_queue_files_foreach, tracker);
+ g_slist_foreach (files, (GFunc) g_free, NULL);
+ g_slist_free (files);
process_queue_files_foreach (uri, tracker);
@@ -571,8 +652,6 @@
tracker_applications_add_service_directories ();
list = tracker_get_service_dirs ("Applications");
-
- tracker_add_root_directories (list);
process_directory_list (tracker, list, FALSE);
tracker_db_end_transaction (db_con->cache);
@@ -581,11 +660,96 @@
}
static void
+process_index_get_remote_roots (Tracker *tracker,
+ GSList **mounted_directory_roots,
+ GSList **removable_device_roots)
+{
+ GSList *l1 = NULL;
+ GSList *l2 = NULL;
+
+#ifdef HAVE_HAL
+ l1 = tracker_hal_get_mounted_directory_roots (tracker->hal);
+ l2 = tracker_hal_get_removable_device_roots (tracker->hal);
+#endif
+
+ /* The options to index removable media and the index mounted
+ * directories are both mutually exclusive even though
+ * removable media is mounted on a directory.
+ *
+ * Since we get ALL mounted directories from HAL, we need to
+ * remove those which are removable device roots.
+ */
+ if (l2) {
+ GSList *l;
+ GSList *list = NULL;
+
+ for (l = l1; l; l = l->next) {
+ if (g_slist_find_custom (l2, l->data, (GCompareFunc) strcmp)) {
+ continue;
+ }
+
+ list = g_slist_prepend (list, l->data);
+ }
+
+ *mounted_directory_roots = g_slist_reverse (list);
+ } else {
+ *mounted_directory_roots = NULL;
+ }
+
+ *removable_device_roots = g_slist_copy (l2);
+}
+
+static void
+process_index_get_roots (Tracker *tracker,
+ GSList **included,
+ GSList **excluded)
+{
+ GSList *watch_directory_roots;
+ GSList *no_watch_directory_roots;
+ GSList *mounted_directory_roots;
+ GSList *removable_device_roots;
+
+ *included = NULL;
+ *excluded = NULL;
+
+ process_index_get_remote_roots (tracker,
+ &mounted_directory_roots,
+ &removable_device_roots);
+
+ /* Delete all stuff in the no watch dirs */
+ watch_directory_roots =
+ tracker_config_get_watch_directory_roots (tracker->config);
+
+ no_watch_directory_roots =
+ tracker_config_get_no_watch_directory_roots (tracker->config);
+
+ /* Create list for enabled roots based on config */
+ *included = g_slist_concat (*included, g_slist_copy (watch_directory_roots));
+
+ /* Create list for disabled roots based on config */
+ *excluded = g_slist_concat (*excluded, g_slist_copy (no_watch_directory_roots));
+
+ /* Add or remove roots which pertain to removable media */
+ if (tracker_config_get_index_removable_devices (tracker->config)) {
+ *included = g_slist_concat (*included, g_slist_copy (removable_device_roots));
+ } else {
+ *excluded = g_slist_concat (*excluded, g_slist_copy (removable_device_roots));
+ }
+
+ /* Add or remove roots which pertain to mounted directories */
+ if (tracker_config_get_index_mounted_directories (tracker->config)) {
+ *included = g_slist_concat (*included, g_slist_copy (mounted_directory_roots));
+ } else {
+ *excluded = g_slist_concat (*excluded, g_slist_copy (mounted_directory_roots));
+ }
+}
+
+static void
process_index_files (Tracker *tracker)
{
DBConnection *db_con;
- GSList *watch_directory_roots;
- GSList *no_watch_directory_roots;
+ GSList *index_include;
+ GSList *index_exclude;
gint initial_sleep;
tracker_log ("Starting file indexing...");
@@ -614,70 +778,118 @@
tracker->pause_io = FALSE;
tracker_dbus_send_index_status_change_signal ();
-
- tracker->dir_list = NULL;
+
+ /* FIXME: Is this safe? shouldn't we free first? */
+ crawl_directories = NULL;
tracker_db_start_index_transaction (db_con);
- /* Delete all stuff in the no watch dirs */
- watch_directory_roots =
- tracker_config_get_watch_directory_roots (tracker->config);
-
- no_watch_directory_roots =
- tracker_config_get_no_watch_directory_roots (tracker->config);
-
- if (no_watch_directory_roots) {
+ process_index_get_roots (tracker, &index_include, &index_exclude);
+
+ if (index_exclude) {
GSList *l;
- tracker_log ("Deleting entities in no watch directories...");
+ tracker_log ("Deleting entities where indexing is disabled or are not watched:");
- for (l = no_watch_directory_roots; l; l = l->next) {
- guint32 f_id = tracker_db_get_file_id (db_con, l->data);
+ for (l = index_exclude; l; l = l->next) {
+ guint32 id;
+
+ tracker_log (" %s", l->data);
+
+ id = tracker_db_get_file_id (db_con, l->data);
- if (f_id > 0) {
- tracker_db_delete_directory (db_con, f_id, l->data);
+ if (id > 0) {
+ tracker_db_delete_directory (db_con, id, l->data);
}
}
+
+ g_slist_free (index_exclude);
}
- if (!watch_directory_roots) {
+ if (!index_include) {
+ tracker_log ("No directory roots to index!");
return;
}
tracker_db_start_transaction (db_con->cache);
- tracker_add_root_directories (watch_directory_roots);
- /* index watched dirs first */
- g_slist_foreach (watch_directory_roots,
- (GFunc) process_watch_dir_foreach,
- tracker);
-
- g_slist_foreach (tracker->dir_list,
- (GFunc) process_schedule_dir_check_foreach,
+ /* Index watched dirs first */
+ process_watch_directories (tracker, index_include);
+
+ g_slist_foreach (crawl_directories,
+ (GFunc) process_schedule_directory_check_foreach,
tracker);
- if (tracker->dir_list) {
- g_slist_foreach (tracker->dir_list,
+ if (crawl_directories) {
+ g_slist_foreach (crawl_directories,
(GFunc) g_free,
NULL);
- g_slist_free (tracker->dir_list);
- tracker->dir_list = NULL;
+ g_slist_free (crawl_directories);
+ crawl_directories = NULL;
}
- g_slist_foreach (watch_directory_roots,
- (GFunc) process_schedule_dir_check_foreach,
+ g_slist_foreach (index_include,
+ (GFunc) process_schedule_directory_check_foreach,
tracker);
- if (tracker->dir_list) {
- g_slist_foreach (tracker->dir_list,
+ if (crawl_directories) {
+ g_slist_foreach (crawl_directories,
(GFunc) g_free,
NULL);
- g_slist_free (tracker->dir_list);
- tracker->dir_list = NULL;
+ g_slist_free (crawl_directories);
+ crawl_directories = NULL;
}
tracker_db_end_transaction (db_con->cache);
tracker_dbus_send_index_progress_signal ("Files", "");
+
+ g_slist_free (index_include);
+}
+
+static void
+process_index_crawl_add_directories (Tracker *tracker,
+ GSList *dirs)
+{
+ GSList *new_dirs = NULL;
+ GSList *l;
+
+ if (!tracker->is_running) {
+ return;
+ }
+
+ for (l = dirs; l; l = l->next) {
+ if (!l->data) {
+ continue;
+ }
+
+ new_dirs = g_slist_prepend (new_dirs, g_strdup (l->data));
+ }
+
+ /* Add sub directories breadth first recursively to avoid
+ * running out of file handles.
+ */
+ while (new_dirs) {
+ GSList *files = NULL;
+
+ for (l = new_dirs; l; l = l->next) {
+ if (!l->data) {
+ continue;
+ }
+
+ if (tracker_process_files_should_be_watched (tracker->config, l->data)) {
+ crawl_directories = g_slist_prepend (crawl_directories, g_strdup (l->data));
+ }
+ }
+
+ for (l = new_dirs; l; l = l->next) {
+ process_get_directories (tracker, l->data, &files);
+ }
+
+ g_slist_foreach (new_dirs, (GFunc) g_free, NULL);
+ g_slist_free (new_dirs);
+
+ new_dirs = files;
+ }
}
static void
@@ -689,8 +901,8 @@
db_con = tracker->index_db;
tracker_log ("Starting directory crawling...");
- tracker->dir_list = NULL;
-
+
+ crawl_directories = NULL;
crawl_directory_roots =
tracker_config_get_crawl_directory_roots (tracker->config);
@@ -699,28 +911,27 @@
}
tracker_db_start_transaction (db_con->cache);
- tracker_add_root_directories (crawl_directory_roots);
- process_add_dirs_to_list (tracker, crawl_directory_roots);
+ process_index_crawl_add_directories (tracker, crawl_directory_roots);
- g_slist_foreach (tracker->dir_list,
- (GFunc) process_schedule_dir_check_foreach,
+ g_slist_foreach (crawl_directories,
+ (GFunc) process_schedule_directory_check_foreach,
tracker);
- if (tracker->dir_list) {
- g_slist_foreach (tracker->dir_list, (GFunc) g_free, NULL);
- g_slist_free (tracker->dir_list);
- tracker->dir_list = NULL;
+ if (crawl_directories) {
+ g_slist_foreach (crawl_directories, (GFunc) g_free, NULL);
+ g_slist_free (crawl_directories);
+ crawl_directories = NULL;
}
g_slist_foreach (crawl_directory_roots,
- (GFunc) process_schedule_dir_check_foreach,
+ (GFunc) process_schedule_directory_check_foreach,
tracker);
- if (tracker->dir_list) {
- g_slist_foreach (tracker->dir_list, (GFunc) g_free, NULL);
- g_slist_free (tracker->dir_list);
- tracker->dir_list = NULL;
+ if (crawl_directories) {
+ g_slist_foreach (crawl_directories, (GFunc) g_free, NULL);
+ g_slist_free (crawl_directories);
+ crawl_directories = NULL;
}
tracker_db_end_transaction (db_con->cache);
@@ -755,7 +966,6 @@
tracker_log ("Starting chat log indexing...");
tracker_db_start_transaction (db_con->cache);
- tracker_add_root_directories (list);
process_directory_list (tracker, list, TRUE);
tracker_db_end_transaction (db_con->cache);
g_slist_free (list);
@@ -784,7 +994,6 @@
tracker_add_service_path ("WebHistory", firefox_dir);
tracker_db_start_transaction (db_con->cache);
- tracker_add_root_directories (list);
process_directory_list (tracker, list, TRUE);
tracker_db_end_transaction (db_con->cache);
g_slist_free (list);
@@ -835,7 +1044,6 @@
GSList *list;
list = tracker_get_service_dirs (name);
- tracker_add_root_directories (list);
process_directory_list (tracker, list, TRUE);
g_slist_free (list);
}
@@ -1008,7 +1216,8 @@
break;
case TRACKER_ACTION_DIRECTORY_REFRESH:
- if (need_index && !tracker_file_is_no_watched (info->uri)) {
+ if (need_index &&
+ tracker_process_files_should_be_watched (tracker->config, info->uri)) {
g_async_queue_push (tracker->dir_queue, g_strdup (info->uri));
if (tracker->index_status != INDEX_EMAILS) {
@@ -1020,11 +1229,12 @@
break;
case TRACKER_ACTION_DIRECTORY_CHECK:
- if (need_index && !tracker_file_is_no_watched (info->uri)) {
+ if (need_index &&
+ tracker_process_files_should_be_watched (tracker->config, info->uri)) {
g_async_queue_push (tracker->dir_queue, g_strdup (info->uri));
if (info->indextime > 0) {
- process_delete_dir_check (tracker, info->uri);
+ process_index_delete_directory_check (tracker, info->uri);
}
}
@@ -1042,12 +1252,18 @@
/* Schedule a rescan for all files in folder
* to avoid race conditions.
*/
- if (!tracker_file_is_no_watched (info->uri)) {
+ if (tracker_process_files_should_be_watched (tracker->config, info->uri)) {
+ GSList *list;
+
/* Add to watch folders (including
* subfolders).
*/
- process_watch_dir (tracker, info->uri);
+ list = g_slist_prepend (NULL, info->uri);
+
+ process_watch_directories (tracker, list);
process_scan_directory (tracker, info->uri);
+
+ g_slist_free (list);
} else {
tracker_debug ("Blocked scan of directory %s as its in the no watch list",
info->uri);
@@ -1071,7 +1287,7 @@
/* Info struct may have been deleted in transit here
* so check if still valid and intact.
*/
- if (!tracker_file_info_is_valid (info)) {
+ if (!tracker_process_files_is_file_info_valid (info)) {
return TRUE;
}
@@ -1107,6 +1323,7 @@
if (info->action != TRACKER_ACTION_DELETE &&
info->action != TRACKER_ACTION_DIRECTORY_DELETED &&
+ info->action != TRACKER_ACTION_DIRECTORY_UNMOUNTED &&
info->action != TRACKER_ACTION_FILE_DELETED) {
if (!tracker_file_is_valid (info->uri) ) {
gboolean invalid = TRUE;
@@ -1127,13 +1344,14 @@
*/
} else {
if (info->action == TRACKER_ACTION_FILE_DELETED) {
- process_delete_file (tracker, info);
+ process_index_delete_file (tracker, info);
info = tracker_dec_info_ref (info);
return TRUE;
} else {
- if (info->action == TRACKER_ACTION_DIRECTORY_DELETED) {
- process_delete_file (tracker, info);
- process_delete_dir (tracker, info);
+ if (info->action == TRACKER_ACTION_DIRECTORY_DELETED ||
+ info->action == TRACKER_ACTION_DIRECTORY_UNMOUNTED) {
+ process_index_delete_file (tracker, info);
+ process_index_delete_directory (tracker, info);
info = tracker_dec_info_ref (info);
return TRUE;
}
@@ -1161,6 +1379,48 @@
#endif
}
+#ifdef HAVE_HAL
+
+static void
+process_mount_point_added_cb (TrackerHal *hal,
+ const gchar *mount_point,
+ Tracker *tracker)
+{
+ GSList *list;
+
+ tracker_log ("** TRAWLING THROUGH NEW MOUNT POINT '%s'", mount_point);
+
+ list = g_slist_prepend (NULL, (gchar*) mount_point);
+ process_directory_list (tracker, list, TRUE);
+ g_slist_free (list);
+}
+
+static void
+process_mount_point_removed_cb (TrackerHal *hal,
+ const gchar *mount_point,
+ Tracker *tracker)
+{
+ tracker_log ("** CLEANING UP OLD MOUNT POINT '%s'", mount_point);
+
+ process_index_delete_directory_check (tracker, mount_point);
+}
+
+#endif /* HAVE_HAL */
+
+static inline gboolean
+process_is_in_path (const gchar *uri,
+ const gchar *path)
+{
+ gchar *str;
+ gboolean result;
+
+ str = g_strconcat (path, G_DIR_SEPARATOR_S, NULL);
+ result = g_str_has_prefix (uri, str);
+ g_free (str);
+
+ return result;
+}
+
/* This is the thread entry point for the indexer to start processing
* files and all other categories for processing.
*/
@@ -1180,6 +1440,35 @@
process_block_signals ();
+ /* When initially run, we set up variables */
+ if (!ignore_pattern_list) {
+ GSList *no_index_file_types;
+
+ no_index_file_types = tracker_config_get_no_index_file_types (tracker->config);
+
+ if (no_index_file_types) {
+ GPatternSpec *spec;
+ gchar **p;
+
+ ignore_pattern = tracker_gslist_to_string_list (no_index_file_types);
+
+ for (p = ignore_pattern; *p; p++) {
+ spec = g_pattern_spec_new (*p);
+ ignore_pattern_list = g_slist_prepend (ignore_pattern_list, spec);
+ }
+
+ ignore_pattern_list = g_slist_reverse (ignore_pattern_list);
+ }
+ }
+
+ g_signal_connect (tracker->hal, "mount-point-added",
+ G_CALLBACK (process_mount_point_added_cb),
+ tracker);
+ g_signal_connect (tracker->hal, "mount-point-removed",
+ G_CALLBACK (process_mount_point_removed_cb),
+ tracker);
+
+ /* Start processing */
g_mutex_lock (tracker->files_signal_mutex);
g_mutex_lock (tracker->files_stopped_mutex);
@@ -1312,6 +1601,13 @@
tracker_dec_info_ref (info);
}
+ g_signal_handlers_disconnect_by_func (tracker->hal,
+ process_mount_point_added_cb,
+ tracker);
+ g_signal_handlers_disconnect_by_func (tracker->hal,
+ process_mount_point_removed_cb,
+ tracker);
+
xdg_mime_shutdown ();
tracker_db_close_all (tracker->index_db);
@@ -1321,3 +1617,268 @@
return NULL;
}
+
+gboolean
+tracker_process_files_should_be_watched (TrackerConfig *config,
+ const gchar *uri)
+{
+ GSList *no_watch_directory_roots;
+ GSList *l;
+
+ g_return_val_if_fail (TRACKER_IS_CONFIG (config), FALSE);
+ g_return_val_if_fail (uri != NULL, FALSE);
+
+ if (!tracker_check_uri (uri)) {
+ return FALSE;
+ }
+
+ if (process_is_in_path (uri, g_get_tmp_dir ())) {
+ return FALSE;
+ }
+
+ if (process_is_in_path (uri, "/proc")) {
+ return FALSE;
+ }
+
+ if (process_is_in_path (uri, "/dev")) {
+ return FALSE;
+ }
+
+ if (process_is_in_path (uri, "/tmp")) {
+ return FALSE;
+ }
+
+ no_watch_directory_roots = tracker_config_get_no_watch_directory_roots (config);
+
+ for (l = no_watch_directory_roots; l; l = l->next) {
+ if (!l->data) {
+ continue;
+ }
+
+ /* Check if equal or a prefix with an appended '/' */
+ if (strcmp (uri, l->data) == 0) {
+ tracker_log ("Blocking watch of %s (already being watched)", uri);
+ return FALSE;
+ }
+
+ if (process_is_in_path (uri, l->data)) {
+ tracker_log ("Blocking watch of %s (already a watch in parent path)", uri);
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+gboolean
+tracker_process_files_should_be_crawled (Tracker *tracker,
+ const gchar *uri)
+{
+ GSList *crawl_directory_roots;
+ GSList *mounted_directory_roots = NULL;
+ GSList *removable_device_roots = NULL;
+ GSList *l;
+ gboolean index_mounted_directories;
+ gboolean index_removable_devices;
+ gboolean should_be_crawled = TRUE;
+
+ g_return_val_if_fail (tracker != NULL, FALSE);
+ g_return_val_if_fail (uri != NULL, FALSE);
+ g_return_val_if_fail (uri[0] == G_DIR_SEPARATOR, FALSE);
+
+ index_mounted_directories = tracker_config_get_index_mounted_directories (tracker->config);
+ index_removable_devices = tracker_config_get_index_removable_devices (tracker->config);
+
+ if (!index_mounted_directories || !index_removable_devices) {
+ process_index_get_remote_roots (tracker,
+ &mounted_directory_roots,
+ &removable_device_roots);
+ }
+
+ l = tracker_config_get_crawl_directory_roots (tracker->config);
+
+ crawl_directory_roots = g_slist_copy (l);
+
+ if (!index_mounted_directories) {
+ crawl_directory_roots = g_slist_concat (crawl_directory_roots,
+ mounted_directory_roots);
+ }
+
+ if (!index_removable_devices) {
+ crawl_directory_roots = g_slist_concat (crawl_directory_roots,
+ removable_device_roots);
+ }
+
+ for (l = crawl_directory_roots; l && should_be_crawled; l = l->next) {
+ /* Check if equal or a prefix with an appended '/' */
+ if (strcmp (uri, l->data) == 0) {
+ should_be_crawled = FALSE;
+ }
+
+ if (process_is_in_path (uri, l->data)) {
+ should_be_crawled = FALSE;
+ }
+ }
+
+ g_slist_free (crawl_directory_roots);
+
+ tracker_log ("Indexer %s %s",
+ should_be_crawled ? "crawling" : "blocking",
+ uri);
+
+ return should_be_crawled;
+}
+
+gboolean
+tracker_process_files_should_be_ignored (const char *uri)
+{
+ GSList *l;
+ gchar *name = NULL;
+ const gchar **p;
+ gboolean should_be_ignored = TRUE;
+
+ if (tracker_is_empty_string (uri)) {
+ goto done;
+ }
+
+ name = g_path_get_basename (uri);
+
+ if (!name || name[0] == '.') {
+ goto done;
+ }
+
+ if (process_is_in_path (uri, g_get_tmp_dir ())) {
+ goto done;
+ }
+
+ if (process_is_in_path (uri, "/proc")) {
+ goto done;
+ }
+
+ if (process_is_in_path (uri, "/dev")) {
+ goto done;
+ }
+
+ if (process_is_in_path (uri, "/tmp")) {
+ goto done;
+ }
+
+ /* Test suffixes */
+ for (p = ignore_suffix; *p; p++) {
+ if (g_str_has_suffix (name, *p)) {
+ goto done;
+ }
+ }
+
+ /* Test prefixes */
+ for (p = ignore_prefix; *p; p++) {
+ if (g_str_has_prefix (name, *p)) {
+ goto done;
+ }
+ }
+
+ /* Test exact names */
+ for (p = ignore_name; *p; p++) {
+ if (strcmp (name, *p) == 0) {
+ goto done;
+ }
+ }
+
+ /* Test ignore types */
+ if (ignore_pattern_list) {
+ for (l = ignore_pattern_list; l; l = l->next) {
+ if (g_pattern_match_string (l->data, name)) {
+ goto done;
+ }
+ }
+ }
+
+ /* Test tmp black list */
+ for (l = temp_black_list; l; l = l->next) {
+ if (!l->data) {
+ continue;
+ }
+
+ if (strcmp (uri, l->data) == 0) {
+ goto done;
+ }
+ }
+
+ should_be_ignored = FALSE;
+
+done:
+ g_free (name);
+
+ return should_be_ignored;
+}
+
+GSList *
+tracker_process_files_get_temp_black_list (void)
+{
+ GSList *l;
+
+ l = g_slist_copy (temp_black_list);
+
+ return temp_black_list;
+}
+
+void
+tracker_process_files_set_temp_black_list (GSList *black_list)
+{
+ g_slist_foreach (temp_black_list,
+ (GFunc) g_free,
+ NULL);
+ g_slist_free (temp_black_list);
+
+ temp_black_list = black_list;
+}
+
+void
+tracker_process_files_append_temp_black_list (const gchar *str)
+{
+ g_return_if_fail (str != NULL);
+
+ temp_black_list = g_slist_append (temp_black_list, g_strdup (str));
+}
+
+void
+tracker_process_files_get_all_dirs (Tracker *tracker,
+ const char *dir,
+ GSList **files)
+{
+ GSList *l;
+
+ l = process_get_files (tracker, dir, TRUE, FALSE, NULL);
+
+ if (*files) {
+ *files = g_slist_concat (*files, l);
+ } else {
+ *files = l;
+ }
+}
+
+GSList *
+tracker_process_files_get_files_with_prefix (Tracker *tracker,
+ const char *dir,
+ const char *prefix)
+{
+ return process_get_files (tracker, dir, FALSE, FALSE, prefix);
+}
+
+gboolean
+tracker_process_files_is_file_info_valid (FileInfo *info)
+{
+ g_return_val_if_fail (info != NULL, FALSE);
+ g_return_val_if_fail (info->uri != NULL, FALSE);
+
+ if (!g_utf8_validate (info->uri, -1, NULL)) {
+ tracker_log ("Expected UTF-8 validation of FileInfo URI");
+ return FALSE;
+ }
+
+ if (info->action == TRACKER_ACTION_IGNORE) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
Modified: trunk/src/trackerd/tracker-process-files.h
==============================================================================
--- trunk/src/trackerd/tracker-process-files.h (original)
+++ trunk/src/trackerd/tracker-process-files.h Fri Apr 11 12:43:01 2008
@@ -20,6 +20,31 @@
#ifndef __TRACKER_PROCESS_FILES_H__
#define __TRACKER_PROCESS_FILES_H__
-gpointer tracker_process_files (gpointer data);
+#include <libtracker-common/tracker-config.h>
+
+#include "tracker-utils.h"
+
+/* Thread entry point */
+gpointer tracker_process_files (gpointer data);
+
+gboolean tracker_process_files_should_be_watched (TrackerConfig *config,
+ const gchar *uri);
+gboolean tracker_process_files_should_be_crawled (Tracker *tracker,
+ const gchar *uri);
+gboolean tracker_process_files_should_be_ignored (const char *uri);
+
+/* Black list API */
+GSList *tracker_process_files_get_temp_black_list (void);
+void tracker_process_files_set_temp_black_list (GSList *black_list);
+void tracker_process_files_append_temp_black_list (const gchar *str);
+
+/* File/Directory API */
+void tracker_process_files_get_all_dirs (Tracker *tracker,
+ const char *dir,
+ GSList **files);
+GSList * tracker_process_files_get_files_with_prefix (Tracker *tracker,
+ const char *dir,
+ const char *prefix);
+gboolean tracker_process_files_is_file_info_valid (FileInfo *info);
#endif /* __TRACKER_PROCESS_FILES_H__ */
Modified: trunk/src/trackerd/tracker-utils.c
==============================================================================
--- trunk/src/trackerd/tracker-utils.c (original)
+++ trunk/src/trackerd/tracker-utils.c Fri Apr 11 12:43:01 2008
@@ -57,7 +57,7 @@
#include "tracker-dbus.h"
#include "tracker-utils.h"
#include "tracker-indexer.h"
-
+#include "tracker-process-files.h"
#include "tracker-os-dependant.h"
extern Tracker *tracker;
@@ -66,13 +66,10 @@
"TRACKER_ACTION_IGNORE", "TRACKER_ACTION_CHECK", "TRACKER_ACTION_DELETE", "TRACKER_ACTION_DELETE_SELF", "TRACKER_ACTION_CREATE","TRACKER_ACTION_MOVED_FROM",
"TRACKER_ACTION_MOVED_TO","TRACKER_ACTION_FILE_CHECK", "TRACKER_ACTION_FILE_CHANGED","TRACKER_ACTION_FILE_DELETED", "TRACKER_ACTION_FILE_CREATED",
"TRACKER_ACTION_FILE_MOVED_FROM", "TRACKER_ACTION_FILE_MOVED_TO", "TRACKER_ACTION_WRITABLE_FILE_CLOSED","TRACKER_ACTION_DIRECTORY_CHECK",
- "TRACKER_ACTION_DIRECTORY_CREATED","TRACKER_ACTION_DIRECTORY_DELETED","TRACKER_ACTION_DIRECTORY_MOVED_FROM","TRACKER_ACTION_DIRECTORY_MOVED_TO",
- "TRACKER_ACTION_DIRECTORY_REFRESH", "TRACKER_ACTION_EXTRACT_METADATA",
+ "TRACKER_ACTION_DIRECTORY_CREATED","TRACKER_ACTION_DIRECTORY_DELETED","TRACKER_ACTION_DIRECTORY_UNMOUNTED", "TRACKER_ACTION_DIRECTORY_MOVED_FROM",
+ "TRACKER_ACTION_DIRECTORY_MOVED_TO", "TRACKER_ACTION_DIRECTORY_REFRESH", "TRACKER_ACTION_EXTRACT_METADATA",
NULL};
-char *ignore_suffix[] = {"~", ".o", ".la", ".lo", ".loT", ".in", ".csproj", ".m4", ".rej", ".gmo", ".orig", ".pc", ".omf", ".aux", ".tmp", ".po", ".vmdk",".vmx",".vmxf",".vmsd",".nvram", ".part", NULL};
-char *ignore_prefix[] = {"autom4te", "conftest.", "confstat", "config.", NULL};
-char *ignore_name[] = {"po", "CVS", "aclocal", "Makefile", "CVS", "SCCS", "ltmain.sh","libtool", "config.status", "conftest", "confdefs.h", NULL};
#define ZLIBBUFSIZ 8192
#define TEXT_SNIFF_SIZE 4096
@@ -900,211 +897,6 @@
tracker_log ("Total allocations = %d, total deallocations = %d", info_allocated, info_deallocated);
}
-
-static inline gboolean
-is_in_path (const char *uri, const char *path)
-{
- char *tmp = g_strconcat (path, G_DIR_SEPARATOR_S, NULL);
-
- gboolean result = g_str_has_prefix (uri, tmp);
-
- g_free (tmp);
-
- return result;
-}
-
-
-gboolean
-tracker_file_is_no_watched (const char* uri)
-{
- GSList *no_watch_directory_roots;
- GSList *l;
-
- if (!tracker_check_uri (uri)) {
- return TRUE;
- }
-
- if (is_in_path (uri, g_get_tmp_dir ())) {
- return TRUE;
- }
-
- if (is_in_path (uri, "/proc")) {
- return TRUE;
- }
-
- if (is_in_path (uri, "/dev")) {
- return TRUE;
- }
-
- if (is_in_path (uri, "/tmp")) {
- return TRUE;
- }
-
- no_watch_directory_roots = tracker_config_get_no_watch_directory_roots (tracker->config);
-
- for (l = no_watch_directory_roots; l; l = l->next) {
- if (!l->data) {
- continue;
- }
-
- /* Check if equal or a prefix with an appended '/' */
- if (strcmp (uri, l->data) == 0) {
- tracker_log ("Blocking watch of %s", uri);
- return TRUE;
- }
-
- if (is_in_path (uri, l->data)) {
- tracker_log ("Blocking watch of %s", uri);
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-gboolean
-tracker_file_is_crawled (const char *uri)
-{
- GSList *crawl_directory_roots;
- GSList *l;
-
- g_return_val_if_fail (uri != NULL, FALSE);
- g_return_val_if_fail (uri[0] == G_DIR_SEPARATOR, FALSE);
-
- crawl_directory_roots = tracker_config_get_crawl_directory_roots (tracker->config);
-
- for (l = crawl_directory_roots; l; l = l->next) {
- /* Check if equal or a prefix with an appended '/' */
- if (strcmp (uri, l->data) == 0) {
- tracker_log ("Blocking watch of %s", uri);
- return TRUE;
- }
-
- if (is_in_path (uri, l->data)) {
- tracker_log ("Blocking watch of %s", uri);
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-
-void
-tracker_add_root_dir (const char *uri)
-{
- struct stat st;
-
- if (!tracker_config_get_skip_mount_points (tracker->config)) {
- return;
- }
-
- if (!uri || uri[0] != '/') {
- return;
- }
-
- if (g_stat (uri, &st) == 0) {
- GSList * cur = NULL;
- dev_t * elem = NULL;
-
- if (! S_ISDIR (st.st_mode)) {
- return;
- }
-
- /* FIXME: too costly? */
- for (cur = tracker->root_directory_devices; cur; cur = g_slist_next (cur)) {
- if (cur->data && *((dev_t *) cur->data) == st.st_dev) {
- return;
- }
- }
-
- elem = g_new (dev_t, 1);
- * elem = st.st_dev;
- tracker->root_directory_devices = g_slist_prepend (tracker->root_directory_devices, elem);
- } else {
- tracker_log ("Could not stat `%s'", uri);
- }
-}
-
-
-void
-tracker_add_root_directories (GSList * uri_list)
-{
- GSList * cur = NULL;
-
- if (!tracker_config_get_skip_mount_points (tracker->config)) {
- return;
- }
-
- for (cur = uri_list; cur; cur = g_slist_next (cur)) {
- tracker_add_root_dir ((const char *) cur->data);
- }
-}
-
-
-gboolean
-tracker_file_is_in_root_dir (const char *uri)
-{
- struct stat st;
- GSList * cur = NULL;
- dev_t uri_dev = 0;
-
- if (!tracker_config_get_skip_mount_points (tracker->config)) {
- return TRUE;
- }
-
- if (!uri || uri[0] != '/') {
- return FALSE;
- }
-
- if (g_stat (uri, &st) == 0) {
- uri_dev = st.st_dev;
- } else {
- tracker_log ("Could not stat `%s'", uri);
- return TRUE; /* the caller should take care of skipping this one */
- }
-
- if (! S_ISDIR (st.st_mode)) { /* only directories are mount points and therefore checked */
- return TRUE;
- }
-
- for (cur = tracker->root_directory_devices; cur; cur = g_slist_next (cur)) {
- if (cur->data && *((dev_t *) cur->data) == uri_dev) {
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-
-gboolean
-tracker_file_info_is_valid (FileInfo *info)
-{
- if (!info || !info->uri) {
-
- tracker_log ("************** Warning Invalid Info struct detected *****************");
-
- return FALSE;
-
- } else {
-
- if ( !g_utf8_validate (info->uri, -1, NULL) || info->action == TRACKER_ACTION_IGNORE) {
-
- if (info->action != TRACKER_ACTION_IGNORE) {
- tracker_log ("************** Warning UTF8 Validation of FileInfo URI has failed (possible corruption) *****************");
- }
-
- tracker_free_file_info (info);
-
- return FALSE;
- }
- }
-
- return TRUE;
-}
-
-
void
tracker_free_array (char **array, int row_count)
{
@@ -1773,151 +1565,6 @@
*/
-static GSList *
-get_files (const char *dir, gboolean dir_only, gboolean skip_ignored_files, const char *filter_prefix)
-{
- GDir *dirp;
- GSList *file_list;
- char *dir_in_locale;
-
- dir_in_locale = g_filename_from_utf8 (dir, -1, NULL, NULL, NULL);
-
- if (!dir_in_locale) {
- tracker_error ("ERROR: dir could not be converted to utf8 format");
- g_free (dir_in_locale);
- return NULL;
- }
-
- file_list = NULL;
-
- if ((dirp = g_dir_open (dir_in_locale, 0, NULL))) {
- const char *name;
-
- while ((name = g_dir_read_name (dirp))) {
- char *mystr, *str;
-
- if (!tracker->is_running) {
- g_free (dir_in_locale);
- g_dir_close (dirp);
- return NULL;
- }
-
- str = g_filename_to_utf8 (name, -1, NULL, NULL, NULL);
-
- if (!str) {
- continue;
- }
-
- if (filter_prefix && !g_str_has_prefix (str, filter_prefix)) {
- g_free (str);
- continue;
- }
-
- if (skip_ignored_files && tracker_ignore_file (str)) {
- g_free (str);
- continue;
- }
-
- mystr = g_build_filename (dir, str, NULL);
- g_free (str);
-
- if (!tracker_file_is_valid (mystr)) {
- g_free (mystr);
- continue;
- }
-
-
-
- if (!tracker_file_is_in_root_dir (mystr)) {
- tracker_log ("Skipping mount point %s", mystr);
- g_free (mystr);
- continue;
- }
-
- if (!dir_only || tracker_is_directory (mystr)) {
-
- if (!tracker_file_is_no_watched (mystr)) {
- file_list = g_slist_prepend (file_list, g_strdup (mystr));
- }
- }
-
- g_free (mystr);
- }
-
- g_dir_close (dirp);
- }
-
- g_free (dir_in_locale);
-
- if (!tracker->is_running) {
- if (file_list) {
- g_slist_foreach (file_list, (GFunc) g_free, NULL);
- g_slist_free (file_list);
- }
-
- return NULL;
- }
-
- return file_list;
-}
-
-
-GSList *
-tracker_get_all_files (const char *dir, gboolean dir_only)
-{
- return get_files (dir, dir_only, FALSE, NULL);
-}
-
-
-GSList *
-tracker_get_files_with_prefix (const char *dir, const char *prefix)
-{
- return get_files (dir, FALSE, FALSE, prefix);
-}
-
-
-
-GSList *
-tracker_get_files (const char *dir, gboolean dir_only)
-{
- return get_files (dir, dir_only, TRUE, NULL);
-}
-
-
-static void
-get_dirs (const char *dir, GSList **file_list, gboolean skip_ignored_files)
-{
- GSList *tmp_list;
-
- g_return_if_fail (dir);
-
- tmp_list = (skip_ignored_files ?
- tracker_get_files (dir, TRUE) :
- tracker_get_all_files (dir, TRUE));
-
- if (tmp_list) { /* check list is not empty */
- if (*file_list) { /* check this list too */
- *file_list = g_slist_concat (*file_list, tmp_list);
- } else {
- *file_list = tmp_list;
- }
- }
-}
-
-
-void
-tracker_get_dirs (const char *dir, GSList **file_list)
-{
- get_dirs (dir, file_list, TRUE);
-}
-
-
-void
-tracker_get_all_dirs (const char *dir, GSList **file_list)
-{
- get_dirs (dir, file_list, FALSE);
-}
-
GSList *
tracker_string_list_to_gslist (const gchar **array)
{
@@ -1957,95 +1604,6 @@
return string_list;
}
-
-gboolean
-tracker_ignore_file (const char *uri)
-{
- char *name;
- char **st;
- GSList *tmp = NULL;
-
- if (tracker_is_empty_string (uri)) {
- return TRUE;
- }
-
- name = g_path_get_basename (uri);
-
- if (!name || name[0] == '.') {
- g_free (name);
- return TRUE;
- }
-
- if (is_in_path (uri, g_get_tmp_dir ())) {
- return TRUE;
- }
-
- if (is_in_path (uri, "/proc")) {
- return TRUE;
- }
-
- if (is_in_path (uri, "/dev")) {
- return TRUE;
- }
-
- if (is_in_path (uri, "/tmp")) {
- return TRUE;
- }
-
- /* test suffixes */
- for (st = ignore_suffix; *st; st++) {
- if (g_str_has_suffix (name, *st)) {
- g_free (name);
- return TRUE;
- }
- }
-
- /* test prefixes */
- for (st = ignore_prefix; *st; st++) {
- if (g_str_has_prefix (name, *st)) {
- g_free (name);
- return TRUE;
- }
- }
-
- /* test exact names */
- for (st = ignore_name; *st; st++) {
- if (strcmp (name, *st) == 0) {
- g_free (name);
- return TRUE;
- }
- }
-
- /* test ignore types */
- if (tracker->ignore_pattern_list) {
- for (tmp = tracker->ignore_pattern_list; tmp; tmp = tmp->next) {
- if (g_pattern_match_string (tmp->data, name)) {
- g_free (name);
- return TRUE;
- }
- }
- }
-
- /* test tmp black list */
- GSList *lst;
- for (lst = tracker->tmp_black_list; lst; lst = lst->next) {
-
-
- char *compare_uri = lst->data;
-
- if (!compare_uri) continue;
-
- if (strcmp (uri, compare_uri) == 0) {
- g_free (name);
- return TRUE;
- }
- }
-
-
- g_free (name);
- return FALSE;
-}
-
char *
tracker_array_to_str (char **array, int length, char sep)
{
Modified: trunk/src/trackerd/tracker-utils.h
==============================================================================
--- trunk/src/trackerd/tracker-utils.h (original)
+++ trunk/src/trackerd/tracker-utils.h Fri Apr 11 12:43:01 2008
@@ -168,7 +168,7 @@
int pid;
gpointer dbus_con;
- gpointer hal_con;
+ gpointer hal;
gboolean reindex;
@@ -176,8 +176,6 @@
gpointer language;
/* config options */
- GSList *ignore_pattern_list;
-
guint32 watch_limit;
gboolean fatal_errors;
@@ -237,8 +235,6 @@
const char *current_uri;
- GSList * root_directory_devices;
-
IndexStatus index_status;
int grace_period;
@@ -264,7 +260,6 @@
/* Queue for recorad file changes */
GQueue *file_change_queue;
- GSList *tmp_black_list;
gboolean black_list_timer_active;
/* progress info for merges */
@@ -311,7 +306,6 @@
GAsyncQueue *user_request_queue;
GAsyncQueue *dir_queue;
- GSList *dir_list;
GMutex *files_check_mutex;
GMutex *metadata_check_mutex;
@@ -360,6 +354,7 @@
TRACKER_ACTION_DIRECTORY_CHECK,
TRACKER_ACTION_DIRECTORY_CREATED,
TRACKER_ACTION_DIRECTORY_DELETED,
+ TRACKER_ACTION_DIRECTORY_UNMOUNTED,
TRACKER_ACTION_DIRECTORY_MOVED_FROM,
TRACKER_ACTION_DIRECTORY_MOVED_TO,
TRACKER_ACTION_DIRECTORY_REFRESH, /* re checks all files in folder */
@@ -483,8 +478,6 @@
FileInfo * tracker_free_file_info (FileInfo *info);
-gboolean tracker_file_info_is_valid (FileInfo *info);
-
char * tracker_get_vfs_path (const char *uri);
char * tracker_get_vfs_name (const char *uri);
@@ -494,28 +487,13 @@
gboolean tracker_file_is_indexable (const char *uri);
+gboolean tracker_is_mounted (const char *dir);
gboolean tracker_is_directory (const char *dir);
-gboolean tracker_file_is_no_watched (const char *uri);
-gboolean tracker_file_is_crawled (const char *uri);
-
-void tracker_add_root_dir (const char *uri); /* add a directory to the list of watch/crawl/service roots */
-void tracker_add_root_directories (GSList *uri_list); /* adds a bunch of directories to the list of watch/crawl/service roots */
-gboolean tracker_file_is_in_root_dir (const char *uri); /* test if a given file resides in the watch/crawl/service roots */
-
-GSList * tracker_get_all_files (const char *dir, gboolean dir_only);
-GSList * tracker_get_files (const char *dir, gboolean dir_only);
-GSList * tracker_get_files_with_prefix (const char *dir, const char *prefix);
-
-void tracker_get_all_dirs (const char *dir, GSList **file_list);
-void tracker_get_dirs (const char *dir, GSList **file_list);
-
void tracker_load_config_file (void);
GSList * tracker_get_watch_root_dirs (void);
-gboolean tracker_ignore_file (const char *uri);
-
void tracker_print_object_allocations (void);
void tracker_throttle (int multiplier);
@@ -554,6 +532,8 @@
void free_file_change (FileChange **user_data);
gboolean tracker_do_cleanup (const gchar *sig_msg);
+gboolean tracker_watch_dir (const gchar *uri);
+void tracker_scan_directory (const gchar *uri);
gboolean tracker_pause_on_battery (void);
gboolean tracker_low_diskspace (void);
Modified: trunk/src/trackerd/trackerd.c
==============================================================================
--- trunk/src/trackerd/trackerd.c (original)
+++ trunk/src/trackerd/trackerd.c Fri Apr 11 12:43:01 2008
@@ -40,15 +40,6 @@
#include "tracker-ioprio.h"
#endif
-
-#ifdef HAVE_HAL
-#include <dbus/dbus-glib-lowlevel.h>
-#include <libhal.h>
-#endif
-
-#define BATTERY_OFF "ac_adapter.present"
-#define AC_ADAPTER "ac_adapter"
-
#include <libtracker-common/tracker-config.h>
#include <libtracker-common/tracker-language.h>
#include <libtracker-common/tracker-log.h>
@@ -59,6 +50,7 @@
#include "tracker-process-files.h"
#include "tracker-process-requests.h"
#include "tracker-watch.h"
+#include "tracker-hal.h"
#include "tracker-service-manager.h"
@@ -112,7 +104,6 @@
gchar *type_array[] = {"index", "string", "numeric", "date", NULL};
-static gchar **ignore_pattern = NULL;
static gchar **no_watch_dirs = NULL;
static gchar **watch_dirs = NULL;
static gchar **crawl_dirs = NULL;
@@ -158,135 +149,6 @@
return count;
}
-#ifdef HAVE_HAL
-
-static void
-property_callback (LibHalContext *ctx, const char *udi, const char *key,
- dbus_bool_t is_removed, dbus_bool_t is_added)
-{
-
- tracker_log ("HAL property change detected for udi %s and key %s", udi, key);
-
- gboolean current_state = tracker->pause_battery;
-
- if (strcmp (udi, tracker->battery_udi) == 0) {
-
- tracker->pause_battery = !libhal_device_get_property_bool (ctx, tracker->battery_udi, BATTERY_OFF, NULL);
-
- char *bat_state[2] = {"off","on"};
- tracker_log ("Battery power is now %s", bat_state[tracker->pause_battery]);
-
- } else {
- return;
- }
-
- /* if we have come off battery power wakeup index thread */
- if (current_state && !tracker->pause_battery) {
- tracker_notify_file_data_available ();
- }
-
-}
-
-
-LibHalContext *
-tracker_hal_init ()
-{
- LibHalContext *ctx;
- char **devices;
- int num;
- DBusError error;
- DBusConnection *connection;
-
- dbus_error_init (&error);
-
- connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
-
- g_print ("starting HAL detection for ac adaptors...");
-
- if (!connection) {
- if (dbus_error_is_set (&error)) {
- tracker_error ("Could not connect to system bus due to %s", error.message);
- dbus_error_free (&error);
- } else {
- tracker_error ("Could not connect to system bus");
- }
-
- return NULL;
- }
-
- dbus_connection_setup_with_g_main (connection, NULL);
-
- ctx = libhal_ctx_new ();
-
- if (!ctx) {
- tracker_error ("Could not create HAL context");
- return NULL;
- }
-
-
-
- libhal_ctx_set_dbus_connection (ctx, connection);
-
- if (!libhal_ctx_init (ctx, &error)) {
-
- if (dbus_error_is_set (&error)) {
- tracker_error ("Could not initialise HAL connection due to %s", error.message);
- dbus_error_free (&error);
- } else {
- tracker_error ("Could not initialise HAL connection -is hald running?");
- }
-
- libhal_ctx_free (ctx);
-
- return NULL;
- }
-
- devices = libhal_find_device_by_capability (ctx, AC_ADAPTER, &num, &error);
-
- if (dbus_error_is_set (&error)) {
- tracker_error ("Could not get HAL devices due to %s", error.message);
- dbus_error_free (&error);
- return NULL;
- }
-
- if (!devices || !devices[0]) {
- tracker->pause_battery = FALSE;
- tracker->battery_udi = NULL;
- g_print ("none found\n");
- return ctx;
- }
-
- /* there should only be one ac-adaptor so use first one */
- tracker->battery_udi = g_strdup (devices[0]);
- g_print ("found %s\n", devices[0]);
-
- libhal_ctx_set_device_property_modified (ctx, property_callback);
-
- libhal_device_add_property_watch (ctx, devices[0], &error);
- if (dbus_error_is_set (&error)) {
- tracker_error ("Could not set watch on HAL device %s due to %s", devices[0], error.message);
- dbus_error_free (&error);
- return NULL;
- }
-
-
- tracker->pause_battery = !libhal_device_get_property_bool (ctx, tracker->battery_udi, BATTERY_OFF, NULL);
-
- if (tracker->pause_battery) {
- tracker_log ("system is on battery");
- } else {
- tracker_log ("system is on AC power");
- }
-
- dbus_free_string_array (devices);
-
- return ctx;
-
-}
-
-#endif /* HAVE_HAL */
-
-
gboolean
tracker_die ()
{
@@ -340,6 +202,8 @@
gboolean
tracker_do_cleanup (const gchar *sig_msg)
{
+ GSList *black_list;
+
tracker->status = STATUS_SHUTDOWN;
if (sig_msg) {
@@ -420,7 +284,11 @@
/* reset black list files */
- g_slist_foreach (tracker->tmp_black_list, (GFunc) reset_blacklist_file, NULL);
+ black_list = tracker_process_files_get_temp_black_list ();
+ g_slist_foreach (black_list,
+ (GFunc) reset_blacklist_file,
+ NULL);
+ g_slist_free (black_list);
tracker_db_close (main_thread_db_con);
@@ -433,6 +301,11 @@
g_mkdir_with_parents (tracker->data_dir, 00755);
}
+ if (tracker->hal) {
+ g_object_unref (tracker->hal);
+ tracker->hal = NULL;
+ }
+
tracker_debug ("Shutting down main thread");
tracker_log_term ();
@@ -603,8 +476,6 @@
tracker->services_dir = g_build_filename (SHAREDIR, "tracker", "services", NULL);
- tracker->root_directory_devices = NULL;
-
tracker->folders_count = 0;
tracker->folders_processed = 0;
tracker->mbox_count = 0;
@@ -768,8 +639,6 @@
gchar *example;
gboolean need_index, need_data;
DBConnection *db_con;
- gchar **st;
- GPatternSpec *spec;
gchar *tmp_dir;
gchar *old_tracker_dir;
gchar *log_filename;
@@ -1002,10 +871,6 @@
tracker->battery_udi = NULL;
-#ifdef HAVE_HAL
- tracker->hal_con = tracker_hal_init ();
-#endif
-
if (error) {
g_printerr ("invalid arguments: %s\n", error->message);
return 1;
@@ -1116,21 +981,6 @@
tracker_db_set_option_int (db_con, "InitialIndex", 1);
}
- GSList *no_index_file_types;
-
- no_index_file_types = tracker_config_get_no_index_file_types (tracker->config);
-
- if (no_index_file_types) {
- ignore_pattern = tracker_gslist_to_string_list (no_index_file_types);
-
- for (st = ignore_pattern; *st; st++) {
- spec = g_pattern_spec_new (*st);
- tracker->ignore_pattern_list = g_slist_prepend (tracker->ignore_pattern_list, spec);
- }
-
- tracker->ignore_pattern_list = g_slist_reverse (tracker->ignore_pattern_list);
- }
-
db_con->cache = tracker_db_connect_cache ();
db_con->common = tracker_db_connect_common ();
db_con->index = db_con;
@@ -1197,6 +1047,11 @@
tracker->loop = g_main_loop_new (NULL, TRUE);
+#ifdef HAVE_HAL
+ /* Create tracker HAL object */
+ tracker->hal = tracker_hal_new ();
+#endif
+
/* this var is used to tell the threads when to quit */
tracker->is_running = TRUE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]