tracker r2076 - in branches/indexer-split: . src/tracker-indexer/modules
- From: mr svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r2076 - in branches/indexer-split: . src/tracker-indexer/modules
- Date: Thu, 14 Aug 2008 16:14:43 +0000 (UTC)
Author: mr
Date: Thu Aug 14 16:14:43 2008
New Revision: 2076
URL: http://svn.gnome.org/viewvc/tracker?rev=2076&view=rev
Log:
* src/tracker-indexer/modules/files.c: Don't just use
g_file_get_contents() because some files might be quite big.
Instead only get the maximum size we would normally index for each
file which is "Text" or a "Development" file.
Modified:
branches/indexer-split/ChangeLog
branches/indexer-split/src/tracker-indexer/modules/files.c
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 16:14:43 2008
@@ -23,6 +23,7 @@
#include <glib.h>
#include <glib/gstdio.h>
+#include <gio/gio.h>
#include <libtracker-common/tracker-config.h>
#include <libtracker-common/tracker-file-utils.h>
@@ -182,6 +183,64 @@
}
gchar *
+get_file_content (const gchar *path)
+{
+ GFile *file;
+ GFileInputStream *stream;
+ GError *error = NULL;
+ gssize bytes_read;
+ gssize bytes_remaining;
+ gchar buf[1048576];
+
+ file = g_file_new_for_path (path);
+ stream = g_file_read (file, NULL, &error);
+
+ if (error) {
+ g_message ("Couldn't get file file:'%s', %s",
+ path,
+ error->message);
+ g_error_free (error);
+ g_object_unref (file);
+
+ return NULL;
+ }
+
+ /* bytes_max = tracker_config_get_max_text_to_index (config); */
+ bytes_remaining = sizeof (buf);
+ memset (buf, 0, bytes_remaining);
+
+ /* NULL termination */
+ bytes_remaining--;
+
+ for (bytes_read = -1; bytes_read != 0 && !error; ) {
+ bytes_read = g_input_stream_read (G_INPUT_STREAM (stream),
+ buf,
+ bytes_remaining,
+ NULL,
+ &error);
+ bytes_remaining -= bytes_read;
+ }
+
+ if (error) {
+ g_message ("Couldn't get read input stream for:'%s', %s",
+ path,
+ error->message);
+ g_error_free (error);
+ g_object_unref (file);
+
+ return NULL;
+ }
+
+ g_object_unref (file);
+
+ g_debug ("Read %d bytes from file:'%s'\n",
+ sizeof (buf) - bytes_remaining,
+ path);
+
+ return g_strdup (buf);
+}
+
+gchar *
tracker_module_file_get_text (TrackerFile *file)
{
gchar *mimetype, *service_type;
@@ -194,16 +253,7 @@
if (service_type &&
(strcmp (service_type, "Text") == 0 ||
strcmp (service_type, "Development") == 0)) {
- GError *error = NULL;
-
- g_file_get_contents (file->path, &text, NULL, &error);
-
- if (error) {
- g_message ("Couldn't get file contents for:'%s', %s",
- file->path,
- error->message);
- g_error_free (error);
- }
+ text = get_file_content (file->path);
} else {
text = tracker_metadata_call_text_filter (file->path, mimetype);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]