[tracker] tracker-miner-fs: Added --eligible cmdline option
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker] tracker-miner-fs: Added --eligible cmdline option
- Date: Wed, 3 Mar 2010 14:12:38 +0000 (UTC)
commit fb7293e0cc5ded91aac901bcdfe7a57b6233d9d1
Author: Martyn Russell <martyn lanedo com>
Date: Wed Mar 3 14:06:12 2010 +0000
tracker-miner-fs: Added --eligible cmdline option
This is used to let people know if the file specified with that option
is likely to be:
1. Indexed
2. Monitored for changes
This is based on the rules from the config, etc.
src/tracker-miner-fs/tracker-main.c | 281 ++++++++++++++++++-
src/tracker-miner-fs/tracker-miner-files.c | 418 ++++++++++++++++------------
src/tracker-miner-fs/tracker-miner-files.h | 20 ++-
3 files changed, 524 insertions(+), 195 deletions(-)
---
diff --git a/src/tracker-miner-fs/tracker-main.c b/src/tracker-miner-fs/tracker-main.c
index 7e8c82c..7142502 100644
--- a/src/tracker-miner-fs/tracker-main.c
+++ b/src/tracker-miner-fs/tracker-main.c
@@ -62,20 +62,17 @@
"\n" \
" http://www.gnu.org/licenses/gpl.txt\n"
-static GMainLoop *main_loop;
-static GSList *miners;
-static GSList *current_miner;
-static gboolean finished_miners;
+static GMainLoop *main_loop;
+static GSList *miners;
+static GSList *current_miner;
+static gboolean finished_miners;
-static gboolean version;
-static gint verbosity = -1;
-static gint initial_sleep = -1;
+static gint verbosity = -1;
+static gint initial_sleep = -1;
+static gchar *eligible;
+static gboolean version;
-static GOptionEntry entries[] = {
- { "version", 'V', 0,
- G_OPTION_ARG_NONE, &version,
- N_("Displays version information"),
- NULL },
+static GOptionEntry entries[] = {
{ "verbosity", 'v', 0,
G_OPTION_ARG_INT, &verbosity,
N_("Logging, 0 = errors only, "
@@ -86,6 +83,14 @@ static GOptionEntry entries[] = {
N_("Initial sleep time in seconds, "
"0->1000 (default=15)"),
NULL },
+ { "eligible", 'e', 0,
+ G_OPTION_ARG_FILENAME, &eligible,
+ N_("Checks if FILE is eligible for being mined based on configuration"),
+ N_("FILE") },
+ { "version", 'V', 0,
+ G_OPTION_ARG_NONE, &version,
+ N_("Displays version information"),
+ NULL },
{ NULL }
};
@@ -231,6 +236,253 @@ finalize_miner (TrackerMiner *miner)
g_object_unref (G_OBJECT (miner));
}
+static GList *
+get_dir_children_as_gfiles (const gchar *path)
+{
+ GList *children = NULL;
+ GDir *dir;
+
+ dir = g_dir_open (path, 0, NULL);
+
+ if (dir) {
+ const gchar *basename;
+
+ while ((basename = g_dir_read_name (dir)) != NULL) {
+ GFile *child;
+ gchar *str;
+
+ str = g_build_filename (path, basename, NULL);
+ child = g_file_new_for_path (str);
+ g_free (str);
+
+ children = g_list_prepend (children, child);
+ }
+
+ g_dir_close (dir);
+ }
+
+ return children;
+}
+
+static void
+dummy_log_handler (const gchar *domain,
+ GLogLevelFlags log_level,
+ const gchar *message,
+ gpointer user_data)
+{
+ return;
+}
+
+static void
+check_eligible (void)
+{
+ TrackerConfig *config;
+ GFile *file;
+ GFileInfo *info;
+ GError *error = NULL;
+ const gchar *format;
+ gchar *path;
+ guint log_handler_id;
+ gboolean exists = TRUE;
+ gboolean is_dir;
+ gboolean print_dir_check;
+ gboolean print_dir_check_with_content;
+ gboolean print_file_check;
+ gboolean print_monitor_check;
+ gboolean would_index = TRUE;
+ gboolean would_notice = TRUE;
+
+ /* Set log handler for library messages */
+ log_handler_id = g_log_set_handler (NULL,
+ G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL,
+ dummy_log_handler,
+ NULL);
+
+ g_log_set_default_handler (dummy_log_handler, NULL);
+
+ /* Start check */
+ file = g_file_new_for_commandline_arg (eligible);
+ info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_TYPE,
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ &error);
+
+ if (error) {
+ if (error->code == G_IO_ERROR_NOT_FOUND) {
+ exists = FALSE;
+ }
+
+ g_error_free (error);
+ }
+
+ if (info) {
+ is_dir = g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY;
+ g_object_unref (info);
+ } else {
+ /* Assume not a dir */
+ is_dir = FALSE;
+ }
+
+ config = tracker_config_new ();
+ path = g_file_get_path (file);
+
+ if (exists) {
+ if (is_dir) {
+ print_dir_check = TRUE;
+ print_dir_check_with_content = TRUE;
+ print_file_check = FALSE;
+ print_monitor_check = TRUE;
+ } else {
+ print_dir_check = FALSE;
+ print_dir_check_with_content = FALSE;
+ print_file_check = TRUE;
+ print_monitor_check = TRUE;
+ }
+ } else {
+ print_dir_check = TRUE;
+ print_dir_check_with_content = FALSE;
+ print_file_check = TRUE;
+ print_monitor_check = TRUE;
+ }
+
+ format = exists ?
+ _("Data object '%s' currently exists") :
+ _("Data object '%s' currently does not exist");
+
+ g_print (format, path);
+ g_print ("\n");
+
+ if (print_dir_check) {
+ gboolean check;
+
+ check = tracker_miner_files_check_directory (file,
+ tracker_config_get_index_recursive_directories (config),
+ tracker_config_get_index_single_directories (config),
+ tracker_config_get_ignored_directory_paths (config),
+ tracker_config_get_ignored_directory_patterns (config));
+ g_print (" %s\n",
+ check ?
+ _("Directory is eligible to be mined (based on rules)") :
+ _("Directory is NOT eligible to be mined (based on rules)"));
+
+ would_index &= check;
+ }
+
+ if (print_dir_check_with_content) {
+ GList *children;
+ gboolean check;
+
+ children = get_dir_children_as_gfiles (path);
+
+ check = tracker_miner_files_check_directory_contents (file,
+ children,
+ tracker_config_get_ignored_directories_with_content (config));
+
+ g_list_foreach (children, (GFunc) g_object_unref, NULL);
+ g_list_free (children);
+
+ g_print (" %s\n",
+ check ?
+ _("Directory is eligible to be mined (based on contents)") :
+ _("Directory is NOT eligible to be mined (based on contents)"));
+
+ would_index &= check;
+ }
+
+ if (print_monitor_check) {
+ gboolean check = TRUE;
+
+ check &= tracker_config_get_enable_monitors (config);
+
+ if (check) {
+ GSList *dirs_to_check, *l;
+ gboolean is_covered_single;
+ gboolean is_covered_recursive;
+
+ is_covered_single = FALSE;
+ dirs_to_check = tracker_config_get_index_single_directories (config);
+
+ for (l = dirs_to_check; l && !is_covered_single; l = l->next) {
+ GFile *dir;
+ GFile *parent;
+
+ parent = g_file_get_parent (file);
+ dir = g_file_new_for_path (l->data);
+ is_covered_single = g_file_equal (parent, dir) || g_file_equal (file, dir);
+
+ g_object_unref (dir);
+ g_object_unref (parent);
+ }
+
+ is_covered_recursive = FALSE;
+ dirs_to_check = tracker_config_get_index_recursive_directories (config);
+
+ for (l = dirs_to_check; l && !is_covered_recursive; l = l->next) {
+ GFile *dir;
+
+ dir = g_file_new_for_path (l->data);
+ is_covered_recursive = g_file_has_prefix (file, dir) || g_file_equal (file, dir);
+ g_object_unref (dir);
+ }
+
+ check &= is_covered_single || is_covered_recursive;
+ }
+
+ if (exists && is_dir) {
+ g_print (" %s\n",
+ check ?
+ _("Directory is eligible to be monitored (based on config)") :
+ _("Directory is NOT eligible to be monitored (based on config)"));
+ } else if (exists && !is_dir) {
+ g_print (" %s\n",
+ check ?
+ _("File is eligible to be monitored (based on config)") :
+ _("File is NOT eligible to be monitored (based on config)"));
+ } else {
+ g_print (" %s\n",
+ check ?
+ _("File or Directory is eligible to be monitored (based on config)") :
+ _("File or Directory is NOT eligible to be monitored (based on config)"));
+ }
+
+ would_notice &= check;
+ }
+
+ if (print_file_check) {
+ gboolean check;
+
+ check = tracker_miner_files_check_file (file,
+ tracker_config_get_ignored_file_paths (config),
+ tracker_config_get_ignored_file_patterns (config));
+
+ g_print (" %s\n",
+ check ?
+ _("File is eligible to be mined (based on rules)") :
+ _("File is NOT eligible to be mined (based on rules)"));
+
+ would_index &= check;
+ }
+
+ g_print ("\n"
+ "%s: %s\n"
+ "%s: %s\n"
+ "\n",
+ _("Would be indexed"),
+ would_index ? _("Yes") : _("No"),
+ _("Would be monitored"),
+ would_notice ? _("Yes") : _("No"));
+
+ if (log_handler_id != 0) {
+ /* Unset log handler */
+ g_log_remove_handler (NULL, log_handler_id);
+ }
+
+ g_free (path);
+ g_object_unref (config);
+ g_object_unref (file);
+}
+
int
main (gint argc, gchar *argv[])
{
@@ -270,6 +522,11 @@ main (gint argc, gchar *argv[])
return EXIT_SUCCESS;
}
+ if (eligible) {
+ check_eligible ();
+ return EXIT_SUCCESS;
+ }
+
g_print ("Initializing tracker-miner-fs...\n");
initialize_signal_handler ();
diff --git a/src/tracker-miner-fs/tracker-miner-files.c b/src/tracker-miner-fs/tracker-miner-files.c
index 9eb19d0..6993f6f 100644
--- a/src/tracker-miner-fs/tracker-miner-files.c
+++ b/src/tracker-miner-fs/tracker-miner-files.c
@@ -1149,57 +1149,13 @@ miner_files_check_file (TrackerMinerFS *fs,
GFile *file)
{
TrackerMinerFiles *mf;
- GFileInfo *file_info;
- GSList *l;
- gchar *basename;
- gchar *path;
- gboolean should_process;
-
- file_info = NULL;
- should_process = FALSE;
- basename = NULL;
- path = NULL;
-
- file_info = g_file_query_info (file,
- G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN,
- G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
- NULL, NULL);
-
- if (file_info && g_file_info_get_is_hidden (file_info)) {
- /* Ignore hidden files */
- goto done;
- }
/* Check module file ignore patterns */
mf = TRACKER_MINER_FILES (fs);
- path = g_file_get_path (file);
-
- for (l = tracker_config_get_ignored_file_paths (mf->private->config); l; l = l->next) {
- if (strcmp (l->data, path) == 0) {
- goto done;
- }
- }
-
- basename = g_file_get_basename (file);
-
- for (l = tracker_config_get_ignored_file_patterns (mf->private->config); l; l = l->next) {
- if (g_pattern_match_string (l->data, basename)) {
- goto done;
- }
- }
-
- should_process = TRUE;
-
-done:
- g_free (basename);
- g_free (path);
-
- if (file_info) {
- g_object_unref (file_info);
- }
-
- return should_process;
+ return tracker_miner_files_check_file (file,
+ tracker_config_get_ignored_file_paths (mf->private->config),
+ tracker_config_get_ignored_file_patterns (mf->private->config));
}
static gboolean
@@ -1207,105 +1163,17 @@ miner_files_check_directory (TrackerMinerFS *fs,
GFile *file)
{
TrackerMinerFiles *mf;
- GFileInfo *file_info;
- GSList *l;
- gchar *basename;
- gchar *path;
- gboolean should_process;
- gboolean is_hidden;
-
- should_process = FALSE;
- basename = NULL;
-
- /* Most common things to ignore */
- file_info = g_file_query_info (file,
- G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN,
- G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
- NULL, NULL);
-
- path = g_file_get_path (file);
-
- /* First we check the GIO hidden check. This does a number of
- * things for us which is good (like checking ".foo" dirs).
- */
- is_hidden = file_info && g_file_info_get_is_hidden (file_info);
-
- /* Second we check if the file is on FAT and if the hidden
- * attribute is set. GIO does this but ONLY on a Windows OS,
- * not for Windows files under a Linux OS, so we have to check
- * anyway.
- */
- if (!is_hidden) {
- int fd;
-
- fd = g_open (path, O_RDONLY, 0);
- if (fd != -1) {
- __u32 attrs;
-
- if (ioctl (fd, FAT_IOCTL_GET_ATTRIBUTES, &attrs) == 0) {
- is_hidden = attrs & ATTR_HIDDEN ? TRUE : FALSE;
- }
-
- close (fd);
- }
- }
-
- if (is_hidden) {
- TrackerMinerFiles *mf;
- GSList *allowed_directories;
-
- mf = TRACKER_MINER_FILES (fs);
-
- /* FIXME: We need to check if the file is actually a
- * config specified location before blanket ignoring
- * all hidden files.
- */
- allowed_directories =
- tracker_config_get_index_recursive_directories (mf->private->config);
-
- if (tracker_string_in_gslist (path, allowed_directories)) {
- should_process = TRUE;
- }
-
- allowed_directories =
- tracker_config_get_index_single_directories (mf->private->config);
-
- if (tracker_string_in_gslist (path, allowed_directories)) {
- should_process = TRUE;
- }
-
- /* Ignore hidden dirs */
- goto done;
- }
+ /* Check module file ignore patterns */
mf = TRACKER_MINER_FILES (fs);
- for (l = tracker_config_get_ignored_directory_paths (mf->private->config); l; l = l->next) {
- if (strcmp (l->data, path) == 0) {
- goto done;
- }
- }
+ return tracker_miner_files_check_directory (file,
+ tracker_config_get_index_recursive_directories (mf->private->config),
+ tracker_config_get_index_single_directories (mf->private->config),
+ tracker_config_get_ignored_directory_paths (mf->private->config),
+ tracker_config_get_ignored_directory_patterns (mf->private->config));
- basename = g_file_get_basename (file);
- for (l = tracker_config_get_ignored_directory_patterns (mf->private->config); l; l = l->next) {
- if (g_pattern_match_string (l->data, basename)) {
- goto done;
- }
- }
-
- /* Check module directory ignore patterns */
- should_process = TRUE;
-
- done:
- g_free (basename);
- g_free (path);
-
- if (file_info) {
- g_object_unref (file_info);
- }
-
- return should_process;
}
static gboolean
@@ -1314,40 +1182,12 @@ miner_files_check_directory_contents (TrackerMinerFS *fs,
GList *children)
{
TrackerMinerFiles *mf;
- GSList *ignored_content, *l;
mf = TRACKER_MINER_FILES (fs);
- ignored_content = tracker_config_get_ignored_directories_with_content (mf->private->config);
- if (!ignored_content) {
- return TRUE;
- }
-
- while (children) {
- gchar *basename;
-
- basename = g_file_get_basename (children->data);
-
- for (l = ignored_content; l; l = l->next) {
- if (g_strcmp0 (basename, l->data) == 0) {
- gchar *parent_uri;
-
- parent_uri = g_file_get_uri (parent);
- g_debug ("Directory '%s' ignored since it contains a file named '%s'",
- parent_uri, basename);
-
- g_free (parent_uri);
- g_free (basename);
-
- return FALSE;
- }
- }
-
- children = children->next;
- g_free (basename);
- }
-
- return TRUE;
+ return tracker_miner_files_check_directory_contents (parent,
+ children,
+ tracker_config_get_ignored_directories_with_content (mf->private->config));
}
static gboolean
@@ -1358,15 +1198,9 @@ miner_files_monitor_directory (TrackerMinerFS *fs,
mf = TRACKER_MINER_FILES (fs);
- if (!tracker_config_get_enable_monitors (mf->private->config)) {
- return FALSE;
- }
-
- /* We'll only get this signal for the directories where check_directory()
- * and check_directory_contents() returned TRUE, so by default we want
- * these directories to be indexed.
- */
- return TRUE;
+ return tracker_miner_files_monitor_directory (file,
+ tracker_config_get_enable_monitors (mf->private->config),
+ mf->private->index_single_directories);
}
static const gchar *
@@ -1805,3 +1639,225 @@ tracker_miner_files_new (TrackerConfig *config)
"process-pool-limit", 10,
NULL);
}
+
+gboolean
+tracker_miner_files_check_file (GFile *file,
+ GSList *ignored_file_paths,
+ GSList *ignored_file_patterns)
+{
+ GFileInfo *file_info;
+ GSList *l;
+ gchar *basename;
+ gchar *path;
+ gboolean should_process;
+
+ file_info = NULL;
+ should_process = FALSE;
+ basename = NULL;
+ path = NULL;
+
+ file_info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ NULL, NULL);
+
+ if (file_info && g_file_info_get_is_hidden (file_info)) {
+ /* Ignore hidden files */
+ goto done;
+ }
+
+
+ path = g_file_get_path (file);
+
+ for (l = ignored_file_paths; l; l = l->next) {
+ if (strcmp (l->data, path) == 0) {
+ goto done;
+ }
+ }
+
+ basename = g_file_get_basename (file);
+
+ for (l = ignored_file_patterns; l; l = l->next) {
+ if (g_pattern_match_string (l->data, basename)) {
+ goto done;
+ }
+ }
+
+ should_process = TRUE;
+
+done:
+ g_free (basename);
+ g_free (path);
+
+ if (file_info) {
+ g_object_unref (file_info);
+ }
+
+ return should_process;
+}
+
+gboolean
+tracker_miner_files_check_directory (GFile *file,
+ GSList *index_recursive_directories,
+ GSList *index_single_directories,
+ GSList *ignored_directory_paths,
+ GSList *ignored_directory_patterns)
+{
+ GFileInfo *file_info;
+ GSList *l;
+ gchar *basename;
+ gchar *path;
+ gboolean should_process;
+ gboolean is_hidden;
+
+ should_process = FALSE;
+ basename = NULL;
+
+ /* Most common things to ignore */
+ file_info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ NULL, NULL);
+
+ path = g_file_get_path (file);
+
+ /* First we check the GIO hidden check. This does a number of
+ * things for us which is good (like checking ".foo" dirs).
+ */
+ is_hidden = file_info && g_file_info_get_is_hidden (file_info);
+
+ /* Second we check if the file is on FAT and if the hidden
+ * attribute is set. GIO does this but ONLY on a Windows OS,
+ * not for Windows files under a Linux OS, so we have to check
+ * anyway.
+ */
+ if (!is_hidden) {
+ int fd;
+
+ fd = g_open (path, O_RDONLY, 0);
+ if (fd != -1) {
+ __u32 attrs;
+
+ if (ioctl (fd, FAT_IOCTL_GET_ATTRIBUTES, &attrs) == 0) {
+ is_hidden = attrs & ATTR_HIDDEN ? TRUE : FALSE;
+ }
+
+ close (fd);
+ }
+ }
+
+ if (is_hidden) {
+ /* FIXME: We need to check if the file is actually a
+ * config specified location before blanket ignoring
+ * all hidden files.
+ */
+ if (tracker_string_in_gslist (path, index_recursive_directories)) {
+ should_process = TRUE;
+ }
+
+ if (tracker_string_in_gslist (path, index_single_directories)) {
+ should_process = TRUE;
+ }
+
+ /* Ignore hidden dirs */
+ goto done;
+ }
+
+ for (l = ignored_directory_paths; l; l = l->next) {
+ if (strcmp (l->data, path) == 0) {
+ goto done;
+ }
+ }
+
+ basename = g_file_get_basename (file);
+
+ for (l = ignored_directory_patterns; l; l = l->next) {
+ if (g_pattern_match_string (l->data, basename)) {
+ goto done;
+ }
+ }
+
+ /* Check module directory ignore patterns */
+ should_process = TRUE;
+
+ done:
+ g_free (basename);
+ g_free (path);
+
+ if (file_info) {
+ g_object_unref (file_info);
+ }
+
+ return should_process;
+}
+
+gboolean
+tracker_miner_files_check_directory_contents (GFile *parent,
+ GList *children,
+ GSList *ignored_content)
+{
+ GSList *l;
+
+ if (!ignored_content) {
+ return TRUE;
+ }
+
+ while (children) {
+ gchar *basename;
+
+ basename = g_file_get_basename (children->data);
+
+ for (l = ignored_content; l; l = l->next) {
+ if (g_strcmp0 (basename, l->data) == 0) {
+ gchar *parent_uri;
+
+ parent_uri = g_file_get_uri (parent);
+ /* g_debug ("Directory '%s' ignored since it contains a file named '%s'", */
+ /* parent_uri, basename); */
+
+ g_free (parent_uri);
+ g_free (basename);
+
+ return FALSE;
+ }
+ }
+
+ children = children->next;
+ g_free (basename);
+ }
+
+ return TRUE;
+}
+
+gboolean
+tracker_miner_files_monitor_directory (GFile *file,
+ gboolean enable_monitors,
+ GSList *directories_to_check)
+{
+ GSList *l;
+
+ if (!enable_monitors) {
+ return FALSE;
+ }
+
+ /* We don't want child directories inside IndexSingleDirectories
+ * to have a monitor added.
+ */
+ for (l = directories_to_check; l; l = l->next) {
+ gboolean is_child = FALSE;
+ GFile *dir;
+
+ dir = g_file_new_for_path (l->data);
+ is_child = g_file_has_prefix (file, dir);
+ g_object_unref (dir);
+
+ if (is_child) {
+ return FALSE;
+ }
+ }
+
+ /* Fallback to the check directory routine, since we don't
+ * monitor anything we don't process.
+ */
+ return TRUE;
+}
diff --git a/src/tracker-miner-fs/tracker-miner-files.h b/src/tracker-miner-fs/tracker-miner-files.h
index b0d0150..32d370a 100644
--- a/src/tracker-miner-fs/tracker-miner-files.h
+++ b/src/tracker-miner-fs/tracker-miner-files.h
@@ -46,9 +46,25 @@ struct TrackerMinerFilesClass {
TrackerMinerFSClass parent_class;
};
-GType tracker_miner_files_get_type (void) G_GNUC_CONST;
+GType tracker_miner_files_get_type (void) G_GNUC_CONST;
-TrackerMiner * tracker_miner_files_new (TrackerConfig *config);
+TrackerMiner *tracker_miner_files_new (TrackerConfig *config);
+
+/* Convenience functions for --eligible tracker-miner-fs cmdline */
+gboolean tracker_miner_files_check_file (GFile *file,
+ GSList *ignored_file_paths,
+ GSList *ignored_file_patterns);
+gboolean tracker_miner_files_check_directory (GFile *file,
+ GSList *index_recursive_directories,
+ GSList *index_single_directories,
+ GSList *ignored_directory_paths,
+ GSList *ignored_directory_patterns);
+gboolean tracker_miner_files_check_directory_contents (GFile *parent,
+ GList *children,
+ GSList *ignored_content);
+gboolean tracker_miner_files_monitor_directory (GFile *file,
+ gboolean enable_monitors,
+ GSList *directories_to_check);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]