[tracker/o_noatime] tracker-extract, text: Use O_NOATIME for opening text files



commit 395b5f697c2910db61fda5a20ec20816aed7b603
Author: Philip Van Hoof <philip codeminded be>
Date:   Thu Sep 22 14:21:46 2011 +0200

    tracker-extract, text: Use O_NOATIME for opening text files

 src/tracker-extract/tracker-extract-text.c |   34 +++++++++++++++++++++------
 1 files changed, 26 insertions(+), 8 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-text.c b/src/tracker-extract/tracker-extract-text.c
index 4ae1e27..f6572d7 100644
--- a/src/tracker-extract/tracker-extract-text.c
+++ b/src/tracker-extract/tracker-extract-text.c
@@ -19,10 +19,23 @@
 
 #include "config.h"
 
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#include <errno.h>
+#include <fcntl.h>
 #include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <sys/mman.h>
 
 #include <glib.h>
+#include <glib/gstdio.h>
+
 #include <gio/gio.h>
+#include <gio/gunixinputstream.h>
 
 #include <libtracker-extract/tracker-extract.h>
 
@@ -35,9 +48,10 @@ static gchar *
 get_file_content (GFile *file,
                   gsize  n_bytes)
 {
-	GFileInputStream *stream;
+	GInputStream *stream;
 	GError *error = NULL;
-	gchar *text, *uri;
+	gchar *text, *uri, *path;
+	int fd;
 
 	/* If no content requested, return */
 	if (n_bytes == 0) {
@@ -45,28 +59,32 @@ get_file_content (GFile *file,
 	}
 
 	uri = g_file_get_uri (file);
+	path = g_file_get_path (file);
 
-	/* Get filename from URI */
-	stream = g_file_read (file, NULL, &error);
-	if (error) {
-		g_message ("Could not read file '%s': %s",
+	fd = g_open (path, O_RDONLY | O_NOATIME, 0);
+
+	if (fd == -1) {
+		g_message ("Could not open file '%s': %s",
 		           uri,
 		           error->message);
 		g_error_free (error);
 		g_free (uri);
-
 		return NULL;
 	}
 
+	/* Get filename from URI */
+	stream = g_unix_input_stream_new (fd, FALSE);
+
 	g_debug ("  Starting to read '%s' up to %" G_GSIZE_FORMAT " bytes...",
 	         uri, n_bytes);
 
 	/* Read up to n_bytes from stream. Output is always, always valid UTF-8 */
-	text = tracker_read_text_from_stream (G_INPUT_STREAM (stream),
+	text = tracker_read_text_from_stream (stream,
 	                                      n_bytes,
 	                                      TRY_LOCALE_TO_UTF8_CONVERSION);
 
 	g_object_unref (stream);
+	close (fd);
 	g_free (uri);
 
 	return text;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]