tracker r2073 - in branches/indexer-split: . src/libtracker-common src/tracker-indexer src/tracker-indexer/modules src/tracker-utils
- From: mr svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r2073 - in branches/indexer-split: . src/libtracker-common src/tracker-indexer src/tracker-indexer/modules src/tracker-utils
- Date: Thu, 14 Aug 2008 12:38:58 +0000 (UTC)
Author: mr
Date: Thu Aug 14 12:38:58 2008
New Revision: 2073
URL: http://svn.gnome.org/viewvc/tracker?rev=2073&view=rev
Log:
* src/libtracker-common/Makefile.am:
* src/tracker-indexer/Makefile.am:
* src/tracker-indexer/modules/Makefile.am: Include -g so we get
debugging symbols to use in gdb.
* src/libtracker-common/tracker-ontology.c:
(tracker_ontology_shutdown): Use g_hash_table_unref() instead of
_destroy() in case the table is referenced somewhere else.
* src/libtracker-common/tracker-parser.c: Use const strings from
tracker_language_get_stem_word() instead of dups and modularise
the code a bit more to make it clearer what is going.
* src/tracker-indexer/modules/files.c:
(tracker_module_file_get_text): Dont't use
g_mapped_file_get_contents() with g_strdup() since the first call
can return a NON-NULL-terminated string. Instead use
g_file_get_contents(). We might want to improve this by using GIO
functions later.
* src/tracker-indexer/tracker-dbus.c: Fix compiler warning.
* src/tracker-indexer/tracker-indexer-db.c:
* src/tracker-indexer/tracker-indexer.c: Cleaned up the code,
removed unnecessary parenthesis and casting.
* src/tracker-indexer/tracker-indexer-module.c:
(tracker_indexer_module_file_get_uri): If either basename or
dirname pointers are NULL, make sure we free either one when they
are.
* src/tracker-indexer/tracker-indexer.c: Fixed a nasty memory leak
in create_update_item() when calling tracker_db_get_text() and
tracker_indexer_module_file_get_text() we now free the return
values. Other memory improvements made here, like using the
GHashTableIter instead of getting all keys and going through the
list for after parsing text in send_text_to_index().
* src/tracker-indexer/tracker-main.c: (main): Actually call the
shutdown functions for dbus, log and db_index_manager. Now objects
should all finalize properly.
* src/tracker-utils/tracker-meta-folder.c: Refactored and made to
use GOption now.
* src/tracker-utils/tracker-files.c:
* src/tracker-utils/tracker-search.c:
* src/tracker-utils/tracker-tag.c:
* src/tracker-utils/tracker-unique.c: Improved print formatting
and don't use warnings for errors reported to us from DBus about
the Tracker service.
Modified:
branches/indexer-split/ChangeLog
branches/indexer-split/src/libtracker-common/Makefile.am
branches/indexer-split/src/libtracker-common/tracker-language.c
branches/indexer-split/src/libtracker-common/tracker-language.h
branches/indexer-split/src/libtracker-common/tracker-ontology.c
branches/indexer-split/src/libtracker-common/tracker-parser.c
branches/indexer-split/src/tracker-indexer/Makefile.am
branches/indexer-split/src/tracker-indexer/modules/Makefile.am
branches/indexer-split/src/tracker-indexer/modules/files.c
branches/indexer-split/src/tracker-indexer/tracker-dbus.c
branches/indexer-split/src/tracker-indexer/tracker-indexer-db.c
branches/indexer-split/src/tracker-indexer/tracker-indexer-module.c
branches/indexer-split/src/tracker-indexer/tracker-indexer.c
branches/indexer-split/src/tracker-indexer/tracker-main.c
branches/indexer-split/src/tracker-utils/tracker-files.c
branches/indexer-split/src/tracker-utils/tracker-meta-folder.c
branches/indexer-split/src/tracker-utils/tracker-search.c
branches/indexer-split/src/tracker-utils/tracker-tag.c
branches/indexer-split/src/tracker-utils/tracker-unique.c
Modified: branches/indexer-split/src/libtracker-common/Makefile.am
==============================================================================
--- branches/indexer-split/src/libtracker-common/Makefile.am (original)
+++ branches/indexer-split/src/libtracker-common/Makefile.am Thu Aug 14 12:38:58 2008
@@ -1,4 +1,5 @@
INCLUDES = \
+ -g \
-DSHAREDIR=\""$(datadir)"\" \
-DG_LOG_DOMAIN=\"Tracker\" \
-I$(top_srcdir)/src \
Modified: branches/indexer-split/src/libtracker-common/tracker-language.c
==============================================================================
--- branches/indexer-split/src/libtracker-common/tracker-language.c (original)
+++ branches/indexer-split/src/libtracker-common/tracker-language.c Thu Aug 14 12:38:58 2008
@@ -412,7 +412,7 @@
g_object_notify (G_OBJECT (language), "config");
}
-gchar *
+const gchar *
tracker_language_stem_word (TrackerLanguage *language,
const gchar *word,
gint word_length)
@@ -436,7 +436,7 @@
g_mutex_unlock (priv->stemmer_mutex);
- return g_strdup (stem_word);
+ return stem_word;
}
gboolean
Modified: branches/indexer-split/src/libtracker-common/tracker-language.h
==============================================================================
--- branches/indexer-split/src/libtracker-common/tracker-language.h (original)
+++ branches/indexer-split/src/libtracker-common/tracker-language.h Thu Aug 14 12:38:58 2008
@@ -53,7 +53,7 @@
GHashTable * tracker_language_get_stop_words (TrackerLanguage *language);
void tracker_language_set_config (TrackerLanguage *language,
TrackerConfig *config);
-gchar * tracker_language_stem_word (TrackerLanguage *language,
+const gchar * tracker_language_stem_word (TrackerLanguage *language,
const gchar *word,
gint word_length);
Modified: branches/indexer-split/src/libtracker-common/tracker-ontology.c
==============================================================================
--- branches/indexer-split/src/libtracker-common/tracker-ontology.c (original)
+++ branches/indexer-split/src/libtracker-common/tracker-ontology.c Thu Aug 14 12:38:58 2008
@@ -146,19 +146,19 @@
return;
}
- g_hash_table_destroy (service_directory_table);
+ g_hash_table_unref (service_directory_table);
service_directory_table = NULL;
- g_hash_table_destroy (service_id_table);
+ g_hash_table_unref (service_id_table);
service_id_table = NULL;
- g_hash_table_destroy (service_table);
+ g_hash_table_unref (service_table);
service_table = NULL;
- g_hash_table_destroy (mime_service);
+ g_hash_table_unref (mime_service);
mime_service = NULL;
- g_hash_table_destroy (metadata_table);
+ g_hash_table_unref (metadata_table);
metadata_table = NULL;
if (mime_prefix_service) {
Modified: branches/indexer-split/src/libtracker-common/tracker-parser.c
==============================================================================
--- branches/indexer-split/src/libtracker-common/tracker-parser.c (original)
+++ branches/indexer-split/src/libtracker-common/tracker-parser.c Thu Aug 14 12:38:58 2008
@@ -36,15 +36,18 @@
/* Need pango for CJK ranges which are : 0x3400 - 0x4DB5, 0x4E00 -
* 0x9FA5, 0x20000 - <= 0x2A6D6
*/
-#define NEED_PANGO(c) (((c) >= 0x3400 && (c) <= 0x4DB5) || ((c) >= 0x4E00 && (c) <= 0x9FA5) || ((c) >= 0x20000 && (c) <= 0x2A6D6))
-#define IS_LATIN(c) (((c) <= 0x02AF) || ((c) >= 0x1E00 && (c) <= 0x1EFF))
-#define IS_ASCII(c) ((c) <= 0x007F)
-#define IS_ASCII_ALPHA_LOWER(c) ( (c) >= 0x0061 && (c) <= 0x007A )
-#define IS_ASCII_ALPHA_HIGHER(c) ( (c) >= 0x0041 && (c) <= 0x005A )
-#define IS_ASCII_NUMERIC(c) ((c) >= 0x0030 && (c) <= 0x0039)
-#define IS_ASCII_IGNORE(c) ((c) <= 0x002C)
-#define IS_HYPHEN(c) ((c) == 0x002D)
-#define IS_UNDERSCORE(c) ((c) == 0x005F)
+#define NEED_PANGO(c) (((c) >= 0x3400 && (c) <= 0x4DB5) || \
+ ((c) >= 0x4E00 && (c) <= 0x9FA5) || \
+ ((c) >= 0x20000 && (c) <= 0x2A6D6))
+#define IS_LATIN(c) (((c) <= 0x02AF) || \
+ ((c) >= 0x1E00 && (c) <= 0x1EFF))
+#define IS_ASCII(c) ((c) <= 0x007F)
+#define IS_ASCII_ALPHA_LOWER(c) ((c) >= 0x0061 && (c) <= 0x007A)
+#define IS_ASCII_ALPHA_HIGHER(c) ((c) >= 0x0041 && (c) <= 0x005A)
+#define IS_ASCII_NUMERIC(c) ((c) >= 0x0030 && (c) <= 0x0039)
+#define IS_ASCII_IGNORE(c) ((c) <= 0x002C)
+#define IS_HYPHEN(c) ((c) == 0x002D)
+#define IS_UNDERSCORE(c) ((c) == 0x005F)
typedef enum {
TRACKER_PARSER_WORD_ASCII_HIGHER,
@@ -152,10 +155,9 @@
stop_words = tracker_language_get_stop_words (language);
- return (g_hash_table_lookup (stop_words, word) != NULL);
+ return g_hash_table_lookup (stop_words, word) != NULL;
}
-
static const gchar *
analyze_text (const gchar *text,
TrackerLanguage *language,
@@ -164,7 +166,7 @@
gboolean filter_words,
gboolean filter_numbers,
gboolean delimit_hyphen,
- gchar **index_word)
+ const gchar **index_word)
{
TrackerParserWordType word_type;
gunichar word[64];
@@ -321,10 +323,8 @@
g_free (tmp);
if (filter_words && is_stop_word (language, *index_word)) {
- g_free (*index_word);
*index_word = NULL;
}
-
}
}
}
@@ -351,7 +351,6 @@
{
const gchar *p = txt;
gchar *parsed_text;
- gchar *word = NULL;
guint32 i = 0;
gint len;
@@ -426,7 +425,10 @@
parsed_text = g_string_free (strs, FALSE);
return g_strstrip (parsed_text);
} else {
- GString *str = g_string_new (" ");
+ GString *str;
+ const gchar *word;
+
+ str = g_string_new (" ");
while (TRUE) {
i++;
@@ -442,7 +444,6 @@
if (word) {
g_string_append (str, word);
g_string_append_c (str, ' ');
- g_free (word);
}
if (!p || !*p) {
@@ -450,6 +451,8 @@
return g_strstrip (parsed_text);
}
}
+
+ g_string_free (str, TRUE);
}
return NULL;
@@ -498,20 +501,22 @@
return word_table;
}
- array = g_strsplit (txt, " ", -1);
+ array = g_strsplit (txt, " ", -1);
for (tmp = array; *tmp; tmp++) {
- if (**tmp) {
- if (!g_hash_table_lookup_extended (word_table, *tmp, &k, &v)) {
- g_hash_table_insert (word_table,
- g_strdup (*tmp),
- GINT_TO_POINTER (GPOINTER_TO_INT (v) + weight));
- } else {
- g_hash_table_insert (word_table,
- *tmp,
- GINT_TO_POINTER (GPOINTER_TO_INT (v) + weight));
- }
- }
+ if (!(**tmp)) {
+ continue;
+ }
+
+ if (!g_hash_table_lookup_extended (word_table, *tmp, &k, &v)) {
+ g_hash_table_insert (word_table,
+ g_strdup (*tmp),
+ GINT_TO_POINTER (GPOINTER_TO_INT (v) + weight));
+ } else {
+ g_hash_table_insert (word_table,
+ *tmp,
+ GINT_TO_POINTER (GPOINTER_TO_INT (v) + weight));
+ }
}
g_strfreev (array);
@@ -519,6 +524,33 @@
return word_table;
}
+static gboolean
+word_table_increment (GHashTable *word_table,
+ const gchar *index_word,
+ gint weight,
+ gint total_words,
+ gint max_words_to_index)
+{
+ gboolean update_count;
+
+ update_count = total_words <= max_words_to_index;
+
+ if (update_count) {
+ gpointer p;
+ gint count;
+
+ p = g_hash_table_lookup (word_table, index_word);
+ count = GPOINTER_TO_INT (p);
+
+ /* Take a copy the first time */
+ g_hash_table_insert (word_table,
+ count == 0 ? g_strdup (index_word) : (gchar*) index_word,
+ GINT_TO_POINTER (count + weight));
+ }
+
+ return update_count;
+}
+
GHashTable *
tracker_parser_text (GHashTable *word_table,
const gchar *txt,
@@ -531,7 +563,6 @@
gboolean delimit_words)
{
const gchar *p;
- gchar *word;
guint32 i;
/* Use this for unprocessed raw text */
@@ -551,7 +582,6 @@
}
p = txt;
- word = NULL;
i = 0;
if (text_needs_pango (txt)) {
@@ -582,10 +612,11 @@
end_word = g_utf8_offset_to_pointer (txt, i);
if (start_word != end_word) {
- /* Normalize word */
- gchar *s;
- gchar *index_word;
+ gchar *s;
+ gchar *index_word;
+ gboolean was_updated;
+ /* Normalize word */
s = g_utf8_casefold (start_word, end_word - start_word);
if (!s) {
continue;
@@ -600,19 +631,16 @@
total_words++;
- if (total_words <= max_words_to_index) {
- gint count;
+ was_updated = word_table_increment (word_table,
+ index_word,
+ weight,
+ total_words,
+ max_words_to_index);
+ g_free (index_word);
- count = GPOINTER_TO_INT (g_hash_table_lookup (word_table, index_word));
- g_hash_table_insert (word_table, index_word, GINT_TO_POINTER (count + weight));
-
- if (count != 0) {
- g_free (index_word);
- }
- } else {
- g_free (index_word);
- break;
- }
+ if (!was_updated) {
+ break;
+ }
}
word_start = i;
@@ -625,6 +653,8 @@
g_free (attrs);
} else {
+ const gchar *word;
+
while (TRUE) {
i++;
p = analyze_text (p,
@@ -639,20 +669,13 @@
if (word) {
total_words++;
- if (total_words <= max_words_to_index) {
- gint count;
-
- count = GPOINTER_TO_INT (g_hash_table_lookup (word_table, word));
- g_hash_table_insert (word_table, word, GINT_TO_POINTER (count + weight));
-
- if (count != 0) {
- g_free (word);
- }
- } else {
- g_free (word);
- break;
- }
-
+ if (!word_table_increment (word_table,
+ word,
+ weight,
+ total_words,
+ max_words_to_index)) {
+ break;
+ }
}
if (!p || !*p) {
Modified: branches/indexer-split/src/tracker-indexer/Makefile.am
==============================================================================
--- branches/indexer-split/src/tracker-indexer/Makefile.am (original)
+++ branches/indexer-split/src/tracker-indexer/Makefile.am Thu Aug 14 12:38:58 2008
@@ -1,6 +1,7 @@
SUBDIRS = modules
INCLUDES = \
+ -g \
-DSHAREDIR=\""$(datadir)"\" \
-DLIBDIR=\""$(libdir)"\" \
-DLOCALEDIR=\""$(localedir)"\" \
Modified: branches/indexer-split/src/tracker-indexer/modules/Makefile.am
==============================================================================
--- branches/indexer-split/src/tracker-indexer/modules/Makefile.am (original)
+++ branches/indexer-split/src/tracker-indexer/modules/Makefile.am Thu Aug 14 12:38:58 2008
@@ -2,6 +2,7 @@
indexer_modulesdir = $(libdir)/tracker/indexer-modules
INCLUDES = \
+ -g \
-DSHAREDIR=\""$(datadir)"\" \
-DLIBDIR=\""$(libdir)"\" \
-DLOCALEDIR=\""$(localedir)"\" \
Modified: branches/indexer-split/src/tracker-indexer/modules/files.c
==============================================================================
--- branches/indexer-split/src/tracker-indexer/modules/files.c (original)
+++ branches/indexer-split/src/tracker-indexer/modules/files.c Thu Aug 14 12:38:58 2008
@@ -194,14 +194,16 @@
if (service_type &&
(strcmp (service_type, "Text") == 0 ||
strcmp (service_type, "Development") == 0)) {
- GMappedFile *mapped_file;
+ GError *error = NULL;
- mapped_file = g_mapped_file_new (file->path, FALSE, NULL);
+ g_file_get_contents (file->path, &text, NULL, &error);
- if (mapped_file) {
- text = g_strdup (g_mapped_file_get_contents (mapped_file));
- g_mapped_file_free (mapped_file);
- }
+ if (error) {
+ g_message ("Couldn't get file contents for:'%s', %s",
+ file->path,
+ error->message);
+ g_error_free (error);
+ }
} else {
text = tracker_metadata_call_text_filter (file->path, mimetype);
}
Modified: branches/indexer-split/src/tracker-indexer/tracker-dbus.c
==============================================================================
--- branches/indexer-split/src/tracker-indexer/tracker-dbus.c (original)
+++ branches/indexer-split/src/tracker-indexer/tracker-dbus.c Thu Aug 14 12:38:58 2008
@@ -19,6 +19,8 @@
* Boston, MA 02110-1301, USA.
*/
+#include <string.h>
+
#include <dbus/dbus-glib-bindings.h>
#include <libtracker-common/tracker-log.h>
@@ -51,7 +53,7 @@
g_error_free (error);
return FALSE;
- }
+ }
if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
g_critical ("DBus service name:'%s' is already taken, "
Modified: branches/indexer-split/src/tracker-indexer/tracker-indexer-db.c
==============================================================================
--- branches/indexer-split/src/tracker-indexer/tracker-indexer-db.c (original)
+++ branches/indexer-split/src/tracker-indexer/tracker-indexer-db.c Thu Aug 14 12:38:58 2008
@@ -26,8 +26,8 @@
#include <libtracker-common/tracker-type-utils.h>
#include <libtracker-db/tracker-db-manager.h>
#include <libtracker-db/tracker-db-dbus.h>
-#include "tracker-indexer-db.h"
+#include "tracker-indexer-db.h"
guint32
tracker_db_get_new_service_id (TrackerDBInterface *iface)
@@ -75,7 +75,6 @@
return ++max;
}
-
void
tracker_db_increment_stats (TrackerDBInterface *iface,
TrackerService *service)
@@ -85,10 +84,18 @@
service_type = tracker_service_get_name (service);
parent = tracker_service_get_parent (service);
- tracker_db_interface_execute_procedure (iface, NULL, "IncStat", service_type, NULL);
+ tracker_db_interface_execute_procedure (iface,
+ NULL,
+ "IncStat",
+ service_type,
+ NULL);
if (parent) {
- tracker_db_interface_execute_procedure (iface, NULL, "IncStat", parent, NULL);
+ tracker_db_interface_execute_procedure (iface,
+ NULL,
+ "IncStat",
+ parent,
+ NULL);
}
}
@@ -101,10 +108,18 @@
service_type = tracker_service_get_name (service);
parent = tracker_service_get_parent (service);
- tracker_db_interface_execute_procedure (iface, NULL, "DecStat", service_type, NULL);
+ tracker_db_interface_execute_procedure (iface,
+ NULL,
+ "DecStat",
+ service_type,
+ NULL);
if (parent) {
- tracker_db_interface_execute_procedure (iface, NULL, "DecStat", parent, NULL);
+ tracker_db_interface_execute_procedure (iface,
+ NULL,
+ "DecStat",
+ parent,
+ NULL);
}
}
@@ -215,12 +230,12 @@
tracker_metadata_lookup (metadata, "File:Size"),
is_dir ? "1" : "0",
is_symlink ? "1" : "0",
- "0", /* offset */
+ "0", /* Offset */
tracker_metadata_lookup (metadata, "File:Modified"),
- "0", /* aux ID */
+ "0", /* Aux ID */
NULL);
- enabled = (is_dir) ?
+ enabled = is_dir ?
tracker_service_get_show_service_directories (service) :
tracker_service_get_show_service_files (service);
@@ -238,7 +253,9 @@
}
static gchar *
-db_get_metadata (TrackerService *service, guint service_id, gboolean keywords)
+db_get_metadata (TrackerService *service,
+ guint service_id,
+ gboolean keywords)
{
TrackerDBInterface *iface;
TrackerDBResultSet *result_set;
@@ -262,6 +279,7 @@
query = g_strdup_printf ("Select MetadataValue From ServiceMetadata WHERE serviceID = %d",
service_id);
}
+
result_set = tracker_db_interface_execute_query (iface, NULL, query);
g_free (query);
@@ -282,11 +300,9 @@
return g_string_free (result, FALSE);
}
-
-
void
-tracker_db_delete_service (TrackerService *service,
- guint32 service_id)
+tracker_db_delete_service (TrackerService *service,
+ guint32 service_id)
{
TrackerDBInterface *iface;
@@ -302,7 +318,11 @@
service_id_str = tracker_guint32_to_string (service_id);
/* Delete from services table */
- tracker_db_interface_execute_procedure (iface, NULL, "DeleteService1", service_id_str, NULL);
+ tracker_db_interface_execute_procedure (iface,
+ NULL,
+ "DeleteService1",
+ service_id_str,
+ NULL);
g_free (service_id_str);
}
@@ -319,22 +339,37 @@
service_id_str = tracker_guint32_to_string (service_id);
- /* Delete from ServiceMetadata, ServiceKeywordMetadata, ServiceNumberMetadata */
- tracker_db_interface_execute_procedure (iface, NULL, "DeleteServiceMetadata", service_id_str, NULL);
- tracker_db_interface_execute_procedure (iface, NULL, "DeleteServiceKeywordMetadata", service_id_str, NULL);
- tracker_db_interface_execute_procedure (iface, NULL, "DeleteServiceNumericMetadata", service_id_str, NULL);
+ /* Delete from ServiceMetadata, ServiceKeywordMetadata,
+ * ServiceNumberMetadata.
+ */
+ tracker_db_interface_execute_procedure (iface,
+ NULL,
+ "DeleteServiceMetadata",
+ service_id_str,
+ NULL);
+ tracker_db_interface_execute_procedure (iface,
+ NULL,
+ "DeleteServiceKeywordMetadata",
+ service_id_str,
+ NULL);
+ tracker_db_interface_execute_procedure (iface,
+ NULL,
+ "DeleteServiceNumericMetadata",
+ service_id_str,
+ NULL);
}
gchar *
tracker_db_get_unparsed_metadata (TrackerService *service,
- guint service_id) {
-
+ guint service_id)
+{
return db_get_metadata (service, service_id, TRUE);
}
gchar *
tracker_db_get_parsed_metadata (TrackerService *service,
- guint service_id) {
+ guint service_id)
+{
return db_get_metadata (service, service_id, FALSE);
}
@@ -351,13 +386,19 @@
iface = tracker_db_manager_get_db_interface_by_type (tracker_service_get_name (service_def),
TRACKER_DB_CONTENT_TYPE_METADATA);
-
metadata_key = tracker_ontology_metadata_key_in_service (tracker_service_get_name (service_def),
tracker_field_get_name (field_def));
+
if (metadata_key > 0) {
- gchar *query = g_strdup_printf ("SELECT KeyMetadata%d FROM Services WHERE id = '%d'",
- metadata_key, id);
- result_set = tracker_db_interface_execute_query (iface, NULL, query, NULL);
+ gchar *query;
+
+ query = g_strdup_printf ("SELECT KeyMetadata%d FROM Services WHERE id = '%d'",
+ metadata_key,
+ id);
+ result_set = tracker_db_interface_execute_query (iface,
+ NULL,
+ query,
+ NULL);
g_free (query);
} else {
gchar *id_str;
@@ -404,15 +445,14 @@
}
if (result_set) {
-
if (tracker_db_result_set_get_n_rows (result_set) > 1) {
g_warning ("More than one result in tracker_db_get_property_value");
}
-
+
if (!is_numeric) {
final_result = tracker_dbus_query_result_to_strv (result_set, 0, NULL);
} else {
- final_result = tracker_dbus_query_result_numeric_to_strv (result_set, 0, NULL);
+ final_result = tracker_dbus_query_result_numeric_to_strv (result_set, 0, NULL);
}
g_object_unref (result_set);
@@ -421,7 +461,6 @@
return final_result;
}
-
void
tracker_db_set_metadata (TrackerService *service,
guint32 id,
@@ -446,6 +485,7 @@
value,
NULL);
break;
+
case TRACKER_FIELD_TYPE_INDEX:
case TRACKER_FIELD_TYPE_STRING:
case TRACKER_FIELD_TYPE_DOUBLE:
@@ -457,6 +497,7 @@
value,
NULL);
break;
+
case TRACKER_FIELD_TYPE_INTEGER:
case TRACKER_FIELD_TYPE_DATE:
tracker_db_interface_execute_procedure (iface, NULL,
@@ -466,9 +507,11 @@
value,
NULL);
break;
+
case TRACKER_FIELD_TYPE_FULLTEXT:
tracker_db_set_text (service, id, value);
break;
+
case TRACKER_FIELD_TYPE_BLOB:
case TRACKER_FIELD_TYPE_STRUCT:
case TRACKER_FIELD_TYPE_LINK:
@@ -482,7 +525,9 @@
if (metadata_key > 0) {
tracker_db_interface_execute_query (iface, NULL,
"update Services set KeyMetadata%d = '%s' where id = %d",
- metadata_key, value, id);
+ metadata_key,
+ value,
+ id);
}
g_free (id_str);
@@ -520,6 +565,7 @@
NULL);
}
break;
+
case TRACKER_FIELD_TYPE_INDEX:
case TRACKER_FIELD_TYPE_STRING:
case TRACKER_FIELD_TYPE_DOUBLE:
@@ -529,6 +575,7 @@
tracker_field_get_id (field),
NULL);
break;
+
case TRACKER_FIELD_TYPE_INTEGER:
case TRACKER_FIELD_TYPE_DATE:
tracker_db_interface_execute_procedure (iface, NULL,
@@ -537,9 +584,11 @@
tracker_field_get_id (field),
NULL);
break;
+
case TRACKER_FIELD_TYPE_FULLTEXT:
tracker_db_delete_text (service, id);
break;
+
case TRACKER_FIELD_TYPE_BLOB:
case TRACKER_FIELD_TYPE_STRUCT:
case TRACKER_FIELD_TYPE_LINK:
@@ -583,8 +632,9 @@
}
gchar *
-tracker_db_get_text (TrackerService *service, guint32 id) {
-
+tracker_db_get_text (TrackerService *service,
+ guint32 id)
+{
TrackerDBInterface *iface;
TrackerField *field;
gchar *service_id_str, *contents = NULL;
@@ -598,11 +648,11 @@
/* Delete contents if it has! */
result_set = tracker_db_interface_execute_procedure (iface, NULL,
"GetContents",
- service_id_str, tracker_field_get_id (field),
+ service_id_str,
+ tracker_field_get_id (field),
NULL);
if (result_set) {
-
tracker_db_result_set_get (result_set, 0, &contents, -1);
g_object_unref (result_set);
}
@@ -610,12 +660,12 @@
g_free (service_id_str);
return contents;
-
}
void
-tracker_db_delete_text (TrackerService *service, guint32 id) {
-
+tracker_db_delete_text (TrackerService *service,
+ guint32 id)
+{
TrackerDBInterface *iface;
TrackerField *field;
gchar *service_id_str;
@@ -628,9 +678,9 @@
/* Delete contents if it has! */
tracker_db_interface_execute_procedure (iface, NULL,
"DeleteContent",
- service_id_str, tracker_field_get_id (field),
+ service_id_str,
+ tracker_field_get_id (field),
NULL);
g_free (service_id_str);
-
}
Modified: branches/indexer-split/src/tracker-indexer/tracker-indexer-module.c
==============================================================================
--- branches/indexer-split/src/tracker-indexer/tracker-indexer-module.c (original)
+++ branches/indexer-split/src/tracker-indexer/tracker-indexer-module.c Thu Aug 14 12:38:58 2008
@@ -122,7 +122,8 @@
gchar **basename)
{
TrackerModuleFileGetUriFunc func;
- gchar *tmp_dirname, *tmp_basename;
+ gchar *tmp_dirname;
+ gchar *tmp_basename;
tmp_dirname = tmp_basename = NULL;
@@ -136,10 +137,14 @@
if (tmp_dirname && tmp_basename) {
if (dirname) {
*dirname = tmp_dirname;
+ } else {
+ g_free (tmp_dirname);
}
if (basename) {
*basename = tmp_basename;
+ } else {
+ g_free (tmp_basename);
}
return TRUE;
Modified: branches/indexer-split/src/tracker-indexer/tracker-indexer.c
==============================================================================
--- branches/indexer-split/src/tracker-indexer/tracker-indexer.c (original)
+++ branches/indexer-split/src/tracker-indexer/tracker-indexer.c Thu Aug 14 12:38:58 2008
@@ -172,7 +172,7 @@
LAST_SIGNAL
};
-static gboolean process_func (gpointer data);
+static gboolean process_func (gpointer data);
static void check_disk_space_start (TrackerIndexer *indexer);
static guint signals[LAST_SIGNAL] = { 0, };
@@ -836,7 +836,7 @@
} else {
GList *list;
- list = (GList *) value;
+ list = value;
while (list) {
index_metadata_item (field, list->data, data);
@@ -866,15 +866,15 @@
static void
send_text_to_index (TrackerIndexer *indexer,
- gint service_id,
- gint service_type,
- const gchar *text,
- gboolean full_parsing,
- gint weight_factor)
-{
- GHashTable *parsed = NULL;
- GList *words = NULL, *iter;
- gint weight;
+ gint service_id,
+ gint service_type,
+ const gchar *text,
+ gboolean full_parsing,
+ gint weight_factor)
+{
+ GHashTable *parsed;
+ GHashTableIter iter;
+ gpointer key, value;
if (!text) {
return;
@@ -891,63 +891,100 @@
tracker_config_get_enable_stemmer (indexer->private->config),
FALSE);
} else {
+ /* We dont know the exact property weight.
+ Big value works.
+ */
parsed = tracker_parser_text_fast (parsed,
text,
- weight_factor); /* We dont know the exact property weight. Big value works */
+ weight_factor);
}
- words = g_hash_table_get_keys (parsed);
-
- for (iter = words; iter != NULL; iter = iter->next) {
- weight = GPOINTER_TO_INT (g_hash_table_lookup (parsed, (gchar *)iter->data));
+ g_hash_table_iter_init (&iter, parsed);
+ while (g_hash_table_iter_next (&iter, &key, &value)) {
tracker_db_index_add_word (indexer->private->index,
- (gchar *)iter->data,
+ key,
service_id,
service_type,
- weight);
+ GPOINTER_TO_INT (value));
}
tracker_parser_text_free (parsed);
- g_list_free (words);
}
-
static void
-index_text_with_parsing (TrackerIndexer *indexer, gint service_id, gint service_type_id, const gchar *content, gint weight_factor)
+index_text_with_parsing (TrackerIndexer *indexer,
+ gint service_id,
+ gint service_type_id,
+ const gchar *content,
+ gint weight_factor)
{
- send_text_to_index (indexer, service_id, service_type_id, content, TRUE, weight_factor);
+ send_text_to_index (indexer,
+ service_id,
+ service_type_id,
+ content,
+ TRUE,
+ weight_factor);
}
static void
-unindex_text_with_parsing (TrackerIndexer *indexer, gint service_id, gint service_type_id, const gchar *content, gint weight_factor)
+unindex_text_with_parsing (TrackerIndexer *indexer,
+ gint service_id,
+ gint service_type_id,
+ const gchar *content,
+ gint weight_factor)
{
- send_text_to_index (indexer, service_id, service_type_id, content, TRUE, -1 * weight_factor);
+ send_text_to_index (indexer,
+ service_id,
+ service_type_id,
+ content,
+ TRUE,
+ weight_factor * -1);
}
static void
-index_text_no_parsing (TrackerIndexer *indexer, gint service_id, gint service_type_id, const gchar *content, gchar weight_factor)
+index_text_no_parsing (TrackerIndexer *indexer,
+ gint service_id,
+ gint service_type_id,
+ const gchar *content,
+ gchar weight_factor)
{
- send_text_to_index (indexer, service_id, service_type_id, content, FALSE, weight_factor);
+ send_text_to_index (indexer,
+ service_id,
+ service_type_id,
+ content,
+ FALSE,
+ weight_factor);
}
static void
-unindex_text_no_parsing (TrackerIndexer *indexer, gint service_id, gint service_type_id, const gchar *content, gint weight_factor)
+unindex_text_no_parsing (TrackerIndexer *indexer,
+ gint service_id,
+ gint service_type_id,
+ const gchar *content,
+ gint weight_factor)
{
- send_text_to_index (indexer, service_id, service_type_id, content, FALSE, -1 * weight_factor);
+ send_text_to_index (indexer,
+ service_id,
+ service_type_id,
+ content,
+ FALSE,
+ weight_factor * -1);
}
static void
-update_word_foreach (gpointer key, gpointer value, gpointer user_data)
+update_word_foreach (gpointer key,
+ gpointer value,
+ gpointer user_data)
{
gchar *word;
UpdateWordsForeachData *data;
gint score;
- word = (gchar *)key;
+ word = key;
score = GPOINTER_TO_INT (value);
-
- data = (UpdateWordsForeachData *)user_data;
+
+ data = user_data;
tracker_db_index_add_word (data->index,
word,
@@ -957,9 +994,11 @@
}
static void
-update_words_no_parsing (TrackerIndexer *indexer, gint service_id, gint service_type_id, GHashTable *words)
+update_words_no_parsing (TrackerIndexer *indexer,
+ gint service_id,
+ gint service_type_id,
+ GHashTable *words)
{
-
UpdateWordsForeachData user_data;
user_data.index = indexer->private->index;
@@ -967,28 +1006,27 @@
user_data.service_type_id = service_type_id;
g_hash_table_foreach (words, update_word_foreach, &user_data);
-
-
}
-
static void
merge_word_table (gpointer key,
gpointer value,
gpointer user_data)
{
- char *word;
- int score;
GHashTable *new_table;
+ gpointer k = NULL;
+ gpointer v = NULL;
+ gchar *word;
+ gint score;
- gpointer k=0, v=0;
-
- word = (char *) key;
+ word = key;
score = GPOINTER_TO_INT (value);
new_table = user_data;
if (!g_hash_table_lookup_extended (new_table, word, &k, &v)) {
- g_hash_table_insert (new_table, g_strdup (word), GINT_TO_POINTER (0 - score));
+ g_hash_table_insert (new_table,
+ g_strdup (word),
+ GINT_TO_POINTER (0 - score));
} else {
if ((GPOINTER_TO_INT (v) - score) != 0) {
g_hash_table_insert (new_table,
@@ -1013,7 +1051,6 @@
guint32 id;
service_type = tracker_indexer_module_file_get_service_type (info->module, info->file);
-
service_def = tracker_ontology_get_service_type_by_name (service_type);
g_free (service_type);
@@ -1021,8 +1058,13 @@
return;
}
- tracker_indexer_module_file_get_uri (info->module, info->file, &dirname, &basename);
- id = tracker_db_check_service (service_def, dirname, basename);
+ tracker_indexer_module_file_get_uri (info->module,
+ info->file,
+ &dirname,
+ &basename);
+ id = tracker_db_check_service (service_def,
+ dirname,
+ basename);
g_debug ("Processing item:'%s/%s'", dirname, basename);
@@ -1052,30 +1094,33 @@
tracker_service_get_id (service_def),
text,
1);
+
/* Save in the DB */
tracker_db_set_text (service_def, id, text);
g_free (text);
}
-
} else {
-
- gchar *old_text = NULL, *new_text = NULL;
- GHashTable *old_words = NULL, *new_words = NULL;
+ gchar *old_text;
+ gchar *new_text;
/* Update case */
g_debug ("Updating file '%s'", info->file->path);
- /* TODO: Take the old metadata -> the new one, calculate difference and add the words
- *
+ /* TODO: Take the old metadata -> the new one,
+ * calculate difference and add the words.
*/
- /* Take the old text -> the new one, calculate difference and add the words */
+ /* Take the old text -> the new one, calculate
+ * difference and add the words.
+ */
old_text = tracker_db_get_text (service_def, id);
new_text = tracker_indexer_module_file_get_text (info->module, info->file);
if (old_text || new_text) {
- /* Service has/had full text */
+ GHashTable *old_words;
+ GHashTable *new_words;
+ /* Service has/had full text */
old_words = tracker_parser_text (NULL,
old_text,
1,
@@ -1096,16 +1141,23 @@
tracker_config_get_enable_stemmer (indexer->private->config),
FALSE);
- /* Merge the score of the words from one and other file
- * new_table contains the words with the updated scores
+ /* Merge the score of the words from one and
+ * other file new_table contains the words
+ * with the updated scores
*/
g_hash_table_foreach (old_words, merge_word_table, new_words);
- update_words_no_parsing (indexer, id, tracker_service_get_id (service_def), new_words);
+ update_words_no_parsing (indexer,
+ id,
+ tracker_service_get_id (service_def),
+ new_words);
tracker_parser_text_free (old_words);
tracker_parser_text_free (new_words);
}
+
+ g_free (old_text);
+ g_free (new_text);
}
g_free (dirname);
@@ -1117,13 +1169,20 @@
PathInfo *info)
{
TrackerService *service_def;
- gchar *dirname, *basename, *content, *metadata;
- const gchar *service_type = NULL;
- guint service_id, service_type_id;
+ gchar *dirname;
+ gchar *basename;
+ gchar *content;
+ gchar *metadata;
+ const gchar *service_type;
+ guint service_id;
+ guint service_type_id;
service_type = tracker_module_config_get_index_service (info->file->module_name);
- if (!tracker_indexer_module_file_get_uri (info->module, info->file, &dirname, &basename)) {
+ if (!tracker_indexer_module_file_get_uri (info->module,
+ info->file,
+ &dirname,
+ &basename)) {
return;
}
@@ -1132,7 +1191,9 @@
if (!service_type || !service_type[0]) {
gchar *name;
- /* The file is not anymore in the filesystem. Obtain the service type from the DB */
+ /* The file is not anymore in the filesystem. Obtain
+ * the service type from the DB.
+ */
service_type_id = tracker_db_get_service_type (dirname, basename);
if (service_type_id == 0) {
@@ -1161,22 +1222,38 @@
/* Get content, unindex the words and delete the contents */
content = tracker_db_get_text (service_def, service_id);
if (content) {
- unindex_text_with_parsing (indexer, service_id, service_type_id, content, 1);
+ unindex_text_with_parsing (indexer,
+ service_id,
+ service_type_id,
+ content,
+ 1);
g_free (content);
tracker_db_delete_text (service_def, service_id);
}
/* Get metadata from DB to remove it from the index */
- metadata = tracker_db_get_parsed_metadata (service_def, service_id);
- unindex_text_no_parsing (indexer, service_id, service_type_id, metadata, 1000);
+ metadata = tracker_db_get_parsed_metadata (service_def,
+ service_id);
+ unindex_text_no_parsing (indexer,
+ service_id,
+ service_type_id,
+ metadata,
+ 1000);
g_free (metadata);
- /* the weight depends on metadata, but a number high enough force deletion */
- metadata = tracker_db_get_unparsed_metadata (service_def, service_id);
- unindex_text_with_parsing (indexer, service_id, service_type_id, metadata, 1000);
+ /* The weight depends on metadata, but a number high enough
+ * force deletion.
+ */
+ metadata = tracker_db_get_unparsed_metadata (service_def,
+ service_id);
+ unindex_text_with_parsing (indexer,
+ service_id,
+ service_type_id,
+ metadata,
+ 1000);
g_free (metadata);
- /* delete service */
+ /* Delete service */
tracker_db_delete_service (service_def, service_id);
tracker_db_delete_all_metadata (service_def, service_id);
@@ -1195,15 +1272,18 @@
TrackerField *field_def;
guint service_id, i;
gchar *joined, *dirname, *basename;
+ gint len;
- g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+ g_return_val_if_fail (error == NULL, FALSE);
+ g_return_val_if_fail (*error == NULL, FALSE);
service_def = tracker_ontology_get_service_type_by_name (service_type);
if (!service_def) {
g_set_error (error,
g_quark_from_string (TRACKER_INDEXER_ERROR),
TRACKER_INDEXER_ERROR_CODE,
- "Unknown service type: '%s'", service_type);
+ "Unknown service type: '%s'",
+ service_type);
return FALSE;
}
@@ -1212,7 +1292,8 @@
g_set_error (error,
g_quark_from_string (TRACKER_INDEXER_ERROR),
TRACKER_INDEXER_ERROR_CODE,
- "Unknown field type: '%s'", property);
+ "Unknown field type: '%s'",
+ property);
return FALSE;
}
@@ -1220,23 +1301,29 @@
g_set_error (error,
g_quark_from_string (TRACKER_INDEXER_ERROR),
TRACKER_INDEXER_ERROR_CODE,
- "Field type: '%s' is embedded and not writable", property);
+ "Field type: '%s' is embedded and not writable",
+ property);
return FALSE;
}
- if (!tracker_field_get_multiple_values (field_def) && g_strv_length (values) > 1) {
+ len = g_strv_length (values);
+
+ if (!tracker_field_get_multiple_values (field_def) && len > 1) {
g_set_error (error,
g_quark_from_string (TRACKER_INDEXER_ERROR),
TRACKER_INDEXER_ERROR_CODE,
"Field type: '%s' doesnt support multiple values (trying to set %d)",
- property, g_strv_length (values));
+ property,
+ len);
return FALSE;
}
dirname = tracker_file_get_vfs_path (uri);
basename = tracker_file_get_vfs_name (uri);
- service_id = tracker_db_check_service (service_def, dirname, basename);
+ service_id = tracker_db_check_service (service_def,
+ dirname,
+ basename);
g_free (dirname);
g_free (basename);
@@ -1250,17 +1337,18 @@
}
if (!tracker_field_get_multiple_values (field_def)) {
-
/* Remove old value from DB and index */
gchar **old_contents;
- old_contents = tracker_db_get_property_values (service_def, service_id, field_def);
- if (old_contents && g_strv_length (old_contents) > 1) {
- g_critical ("Seems to be multiple values in a field that doesn allow that ('%s')",
- tracker_field_get_name (field_def));
+ old_contents = tracker_db_get_property_values (service_def,
+ service_id,
+ field_def);
+ len = g_strv_length (old_contents);
- } else if (old_contents && g_strv_length (old_contents) == 1) {
-
+ if (old_contents && len > 1) {
+ g_critical ("Seems to be multiple values in field:'%s' that doesn allow that",
+ tracker_field_get_name (field_def));
+ } else if (old_contents && len == 1) {
if (tracker_field_get_filtered (field_def)) {
unindex_text_with_parsing (indexer,
service_id,
@@ -1312,7 +1400,6 @@
return TRUE;
}
-
static gboolean
handle_metadata_remove (TrackerIndexer *indexer,
const gchar *service_type,
@@ -1331,7 +1418,8 @@
g_set_error (error,
g_quark_from_string (TRACKER_INDEXER_ERROR),
TRACKER_INDEXER_ERROR_CODE,
- "Unknown service type: '%s'", service_type);
+ "Unknown service type: '%s'",
+ service_type);
return FALSE;
}
@@ -1340,7 +1428,8 @@
g_set_error (error,
g_quark_from_string (TRACKER_INDEXER_ERROR),
TRACKER_INDEXER_ERROR_CODE,
- "Unknown field type: '%s'", property);
+ "Unknown field type: '%s'",
+ property);
return FALSE;
}
@@ -1348,7 +1437,8 @@
g_set_error (error,
g_quark_from_string (TRACKER_INDEXER_ERROR),
TRACKER_INDEXER_ERROR_CODE,
- "Field type: '%s' is embedded and cannot be deleted", property);
+ "Field type: '%s' is embedded and cannot be deleted",
+ property);
return FALSE;
}
@@ -1368,9 +1458,9 @@
return FALSE;
}
- /*
- * If we receive concrete values, we delete those rows in the db
- * Otherwise, retrieve the old values of the property and remove all their instances for the file
+ /* If we receive concrete values, we delete those rows in the
+ * db. Otherwise, retrieve the old values of the property and
+ * remove all their instances for the file
*/
if (g_strv_length (values) > 0) {
for (i = 0; values[i] != NULL; i++) {
@@ -1383,7 +1473,9 @@
} else {
gchar **old_contents;
- old_contents = tracker_db_get_property_values (service_def, service_id, field_def);
+ old_contents = tracker_db_get_property_values (service_def,
+ service_id,
+ field_def);
if (old_contents) {
tracker_db_delete_metadata (service_def,
service_id,
@@ -1395,9 +1487,7 @@
}
}
- /*
- * Now joined contains the words to unindex
- */
+ /* Now joined contains the words to unindex */
if (tracker_field_get_filtered (field_def)) {
unindex_text_with_parsing (indexer,
service_id,
@@ -1843,10 +1933,11 @@
const gchar *property,
GStrv values,
DBusGMethodInvocation *context,
- GError **error) {
+ GError **error)
+{
+ guint request_id;
+ GError *actual_error = NULL;
- guint request_id;
- GError *actual_error = NULL;
request_id = tracker_dbus_get_next_request_id ();
tracker_dbus_async_return_if_fail (TRACKER_IS_INDEXER (indexer), FALSE);
@@ -1862,7 +1953,12 @@
property,
uri);
- if (!handle_metadata_add (indexer, service_type, uri, property, values, &actual_error)) {
+ if (!handle_metadata_add (indexer,
+ service_type,
+ uri,
+ property,
+ values,
+ &actual_error)) {
tracker_dbus_request_failed (request_id,
&actual_error,
NULL);
@@ -1884,8 +1980,8 @@
const gchar *property,
GStrv values,
DBusGMethodInvocation *context,
- GError **error) {
-
+ GError **error)
+{
guint request_id;
GError *actual_error = NULL;
@@ -1903,7 +1999,12 @@
property,
uri);
- if (!handle_metadata_remove (indexer, service_type, uri, property, values, &actual_error)) {
+ if (!handle_metadata_remove (indexer,
+ service_type,
+ uri,
+ property,
+ values,
+ &actual_error)) {
tracker_dbus_request_failed (request_id,
&actual_error,
NULL);
Modified: branches/indexer-split/src/tracker-indexer/tracker-main.c
==============================================================================
--- branches/indexer-split/src/tracker-indexer/tracker-main.c (original)
+++ branches/indexer-split/src/tracker-indexer/tracker-main.c Thu Aug 14 12:38:58 2008
@@ -344,17 +344,23 @@
main_loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (main_loop);
- g_message ("Shutting down...\n");
+ g_message ("Shutdown started");
if (quit_timeout_id) {
g_source_remove (quit_timeout_id);
}
+ tracker_dbus_shutdown ();
+ tracker_db_index_manager_shutdown ();
+ tracker_db_manager_shutdown ();
+ tracker_module_config_shutdown ();
+ tracker_log_shutdown ();
+
+ g_main_loop_unref (main_loop);
g_object_unref (indexer);
g_object_unref (config);
- tracker_db_manager_shutdown ();
- tracker_module_config_shutdown ();
+ g_print ("\nOK\n\n");
return EXIT_SUCCESS;
}
Modified: branches/indexer-split/src/tracker-utils/tracker-files.c
==============================================================================
--- branches/indexer-split/src/tracker-utils/tracker-files.c (original)
+++ branches/indexer-split/src/tracker-utils/tracker-files.c Thu Aug 14 12:38:58 2008
@@ -61,10 +61,10 @@
main (int argc, char **argv)
{
- TrackerClient *client = NULL;
- ServiceType type;
- GError *error = NULL;
+ TrackerClient *client;
+ ServiceType type;
GOptionContext *context;
+ GError *error = NULL;
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
@@ -102,27 +102,34 @@
type = tracker_service_name_to_type (service);
array = tracker_files_get_by_service_type (client,
- time(NULL),
+ time (NULL),
type,
offset,
limit,
&error);
if (error) {
- g_warning ("Could not get files by service type, %s",
- error->message);
+ g_printerr ("%s:'%s', %s\n",
+ _("Could not get files by service type"),
+ type,
+ error->message);
g_error_free (error);
+
return EXIT_FAILURE;
}
if (!array) {
g_print ("%s\n",
- _("No results were found matching your query"));
+ _("No files found by that service type"));
+
return EXIT_FAILURE;
}
+ g_print ("%s:\n",
+ _("Results"));
+
for (p_strarray = array; *p_strarray; p_strarray++) {
- g_print ("%s\n", *p_strarray);
+ g_print (" %s\n", *p_strarray);
}
g_strfreev (array);
@@ -130,30 +137,36 @@
if (mimes) {
gchar **array;
- gchar **p_strarray;
+ gchar **p;
array = tracker_files_get_by_mime_type (client,
- time(NULL),
+ time (NULL),
mimes,
offset,
limit,
&error);
if (error) {
- g_warning ("Could not get files by mime type, %s",
- error->message);
+ g_printerr ("%s, %s\n",
+ _("Could not get files by MIME type"),
+ error->message);
g_error_free (error);
+
return EXIT_FAILURE;
}
if (!array) {
g_print ("%s\n",
- _("No results were found matching your query"));
+ _("No files found by those MIME types"));
+
return EXIT_FAILURE;
}
- for (p_strarray = array; *p_strarray; p_strarray++) {
- g_print ("%s\n", *p_strarray);
+ g_print ("%s:\n",
+ _("Results"));
+
+ for (p = array; *p; p++) {
+ g_print (" %s\n", *p);
}
g_strfreev (array);
Modified: branches/indexer-split/src/tracker-utils/tracker-meta-folder.c
==============================================================================
--- branches/indexer-split/src/tracker-utils/tracker-meta-folder.c (original)
+++ branches/indexer-split/src/tracker-utils/tracker-meta-folder.c Thu Aug 14 12:38:58 2008
@@ -1,5 +1,7 @@
-/* Tracker - indexer and metadata database engine
+/* -*- 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
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -17,103 +19,247 @@
* Boston, MA 02110-1301, USA.
*/
+#include "config.h"
+
+#include <stdlib.h>
#include <time.h>
#include <locale.h>
#include <glib.h>
-#include <glib-object.h>
+#include <glib/gi18n.h>
#include <libtracker/tracker.h>
-static void
-get_meta_table_data (gpointer value)
-{
- char **meta, **meta_p;
+#define MAX_FILENAME_WIDTH 35
- meta = (char **)value;
+static gchar *path;
+static gchar **fields;
- int i = 0;
- for (meta_p = meta; *meta_p; meta_p++) {
+static GOptionEntry entries[] = {
+ { "path", 'p', 0, G_OPTION_ARG_STRING, &path,
+ N_("Path to use for directory to get metadata information about"),
+ NULL,
+ },
+ { G_OPTION_REMAINING, 0, 0,
+ G_OPTION_ARG_STRING_ARRAY, &fields,
+ NULL,
+ NULL
+ },
+ { NULL }
+};
- if (i == 0) {
- g_print ("%s : ", *meta_p);
+static void
+print_header (gchar **fields_resolved)
+{
+ gint cols;
+ gint width;
+ gint i;
+
+ /* Headers */
+ g_print (" %-*.*s ",
+ MAX_FILENAME_WIDTH,
+ MAX_FILENAME_WIDTH,
+ _("Filename"));
+
+ width = MAX_FILENAME_WIDTH;
+ width += 1;
+
+ cols = g_strv_length (fields_resolved);
+
+ for (i = 0; i < cols; i++) {
+ g_print ("%s%s",
+ fields_resolved[i],
+ i < cols - 1 ? ", " : "");
+
+ width += g_utf8_strlen (fields_resolved[i], -1);
+ width += i < cols - 1 ? 2 : 0;
+ }
+ g_print ("\n");
+
+ /* Line under header */
+ g_print (" ");
+ for (i = 0; i < width; i++) {
+ g_print ("-");
+ }
+ g_print ("\n");
+}
- } else {
- g_print ("%s ", *meta_p);
- }
- i++;
+static void
+get_meta_table_data (gpointer data,
+ gpointer user_data)
+{
+ gchar **meta;
+ gchar **p;
+ gchar **fields;
+ gchar *basename;
+ gint i;
+ gint len;
+ gint cols;
+
+ meta = data;
+ fields = user_data;
+
+ basename = g_path_get_basename (*meta);
+ len = g_utf8_strlen (basename, -1);
+ cols = g_strv_length (meta);
+
+ for (p = meta, i = 0; *p; p++, i++) {
+ if (i == 0) {
+ g_print (" %-*.*s",
+ MAX (len, MAX_FILENAME_WIDTH),
+ MAX (len, MAX_FILENAME_WIDTH),
+ basename);
+
+ if (len > MAX_FILENAME_WIDTH) {
+ gint i = 0;
+
+ g_print ("\n");
+ while (i++ < MAX_FILENAME_WIDTH + 2) {
+ g_print (" ");
+ }
+ }
+
+ g_print (" (");
+ } else {
+ g_print ("%s%s",
+ *p,
+ i < cols - 1 ? ", " : "");
+ }
}
- g_print ("\n");
-}
+ g_free (basename);
+ g_print (")\n");
+}
int
main (int argc, char **argv)
{
-
- GPtrArray *out_array = NULL;
- GError *error = NULL;
- TrackerClient *client = NULL;
-
+ TrackerClient *client;
+ GOptionContext *context;
+ GError *error = NULL;
+ gchar *summary;
+ const gchar *failed = NULL;
+ gchar **fields_resolved = NULL;
+ gchar *path_in_utf8;
+ GPtrArray *array;
+ gint i, j;
+
+ bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ textdomain (GETTEXT_PACKAGE);
+
+ /* Translators: this messagge will apper immediately after the
+ * usage string - Usage: COMMAND [OPTION]... <THIS_MESSAGE>
+ */
+ context = g_option_context_new (_("Retrieve meta-data information about files in a directory"));
+
+ /* Translators: this message will appear after the usage string
+ * and before the list of options, showing an usage example.
+ */
+ summary = g_strconcat (_("To use multiple meta-data types simply list them, for example:"),
+ "\n"
+ "\n"
+ " -p ", _("PATH"), " File:Size File:Type",
+ NULL);
+
+ g_option_context_set_summary (context, summary);
+ g_option_context_add_main_entries (context, entries, NULL);
+ g_option_context_parse (context, &argc, &argv, NULL);
+ g_free (summary);
+
+ if (!path) {
+ failed = _("No path was given");
+ } else if (!fields) {
+ failed = _("No fields were given");
+ }
+
+ if (failed) {
+ gchar *help;
+
+ g_printerr ("%s\n\n", failed);
+
+ help = g_option_context_get_help (context, TRUE, NULL);
+ g_option_context_free (context);
+ g_printerr (help);
+ g_free (help);
- setlocale (LC_ALL, "");
+ return EXIT_FAILURE;
+ }
- if (argc < 2) {
- g_print ("usage - tracker-meta-folder FOLDER [Metadata1...]\n");
- return 1;
- }
+ g_option_context_free (context);
- client = tracker_connect (FALSE);
+ client = tracker_connect (FALSE);
if (!client) {
- g_print ("Could not initialize Tracker - exiting...\n");
- return 1;
+ g_printerr ("%s\n",
+ _("Could not establish a DBus connection to Tracker"));
+ return EXIT_FAILURE;
}
+ fields_resolved = g_new0 (gchar*, g_strv_length (fields) + 1);
- char **meta_fields = NULL;
-
- if (argc == 2) {
- meta_fields = g_new (char *, 1);
-
- meta_fields[0] = NULL;
+ for (i = 0, j = 0; fields && fields[i] != NULL; i++) {
+ gchar *field;
- } else if (argc > 2) {
- int i;
+ field = g_locale_to_utf8 (fields[i], -1, NULL, NULL, NULL);
- meta_fields = g_new (char *, (argc-1));
-
- for (i=0; i < (argc-2); i++) {
- meta_fields[i] = g_locale_to_utf8 (argv[i+2], -1, NULL, NULL, NULL);
- }
- meta_fields[argc-2] = NULL;
+ if (field) {
+ fields_resolved[j++] = field;
+ }
+ }
+
+ fields_resolved[j] = NULL;
+
+ path_in_utf8 = g_filename_to_utf8 (path, -1, NULL, NULL, &error);
+ if (error) {
+ g_printerr ("%s:'%s', %s\n",
+ _("Could not get UTF-8 path from path"),
+ path,
+ error->message);
+ g_error_free (error);
+ tracker_disconnect (client);
+
+ return EXIT_FAILURE;
}
- char *folder = g_filename_to_utf8 (argv[1], -1, NULL, NULL, NULL);
-
- out_array = tracker_files_get_metadata_for_files_in_folder (client,
- time(NULL),
- folder,
- meta_fields,
- &error);
+ array = tracker_files_get_metadata_for_files_in_folder (client,
+ time (NULL),
+ path_in_utf8,
+ fields_resolved,
+ &error);
- g_free (folder);
-
- g_strfreev (meta_fields);
+ g_free (path_in_utf8);
if (error) {
- g_warning ("An error has occurred : %s", error->message);
- g_error_free (error);
- }
+ g_printerr ("%s:'%s', %s\n",
+ _("Could not get meta-data for files in directory"),
+ path,
+ error->message);
+ g_error_free (error);
+ g_strfreev (fields_resolved);
+ tracker_disconnect (client);
- if (out_array) {
- g_ptr_array_foreach (out_array, (GFunc)get_meta_table_data, NULL);
- g_ptr_array_free (out_array, TRUE);
+ return EXIT_FAILURE;
}
+ if (!array) {
+ g_print ("%s\n",
+ _("No meta-data found for files in that directory"));
+ } else {
+ g_print ("%s:\n",
+ _("Results"));
+
+ print_header (fields_resolved);
+
+ g_ptr_array_foreach (array,
+ get_meta_table_data,
+ fields_resolved);
+ g_ptr_array_free (array, TRUE);
+ }
+ g_strfreev (fields_resolved);
tracker_disconnect (client);
- return 0;
+ return EXIT_SUCCESS;
}
Modified: branches/indexer-split/src/tracker-utils/tracker-search.c
==============================================================================
--- branches/indexer-split/src/tracker-utils/tracker-search.c (original)
+++ branches/indexer-split/src/tracker-utils/tracker-search.c Thu Aug 14 12:38:58 2008
@@ -245,6 +245,9 @@
g_print ("%s\n",
_("No results found matching your query"));
} else {
+ g_print ("%s:\n",
+ _("Results"));
+
for (p = strv; *p; p++) {
gchar *s;
@@ -254,7 +257,7 @@
continue;
}
- g_print ("%s\n", s);
+ g_print (" %s\n", s);
g_free (s);
}
Modified: branches/indexer-split/src/tracker-utils/tracker-tag.c
==============================================================================
--- branches/indexer-split/src/tracker-utils/tracker-tag.c (original)
+++ branches/indexer-split/src/tracker-utils/tracker-tag.c Thu Aug 14 12:38:58 2008
@@ -174,12 +174,11 @@
}
if (files) {
- /* gchar *path; */
-
files_resolved = g_new0 (gchar*, g_strv_length (files) + 1);
for (i = 0, j = 0; files[i] != NULL; i++) {
/* GFile *file; */
+ /* gchar *path; */
/* file = g_file_new_for_commandline_arg (files[i]); */
/* path = g_file_get_path (file); */
@@ -297,8 +296,8 @@
g_print ("%s\n",
_("No tags found"));
} else {
- g_print ("%s\n",
- _("All tags:"));
+ g_print ("%s:\n",
+ _("All tags"));
g_ptr_array_foreach (array, (GFunc) get_meta_table_data, NULL);
g_ptr_array_free (array, TRUE);
@@ -307,8 +306,8 @@
if ((files && list) ||
(files && (!add && !remove && !remove_all))) {
- g_print ("%s\n",
- _("Tags found:"));
+ g_print ("%s:\n",
+ _("Tags found"));
for (i = 0, j = 0; files_resolved[i] != NULL; i++) {
gchar **tags;
Modified: branches/indexer-split/src/tracker-utils/tracker-unique.c
==============================================================================
--- branches/indexer-split/src/tracker-utils/tracker-unique.c (original)
+++ branches/indexer-split/src/tracker-utils/tracker-unique.c Thu Aug 14 12:38:58 2008
@@ -212,6 +212,9 @@
g_print ("%s\n",
_("No results found matching your query"));
} else {
+ g_print ("%s:\n",
+ _("Results"));
+
g_ptr_array_foreach (array, (GFunc) get_meta_table_data, NULL);
g_ptr_array_free (array, TRUE);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]