[tracker/tracker-0.10-no-atime: 12/23] tracker-extract, text: Use O_NOATIME for opening text files
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/tracker-0.10-no-atime: 12/23] tracker-extract, text: Use O_NOATIME for opening text files
- Date: Fri, 23 Sep 2011 11:04:40 +0000 (UTC)
commit e1bbc9e7de901420f79b631ed4c55489029e3164
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
Conflicts:
src/tracker-extract/tracker-extract-text.c
src/tracker-extract/tracker-extract-text.c | 42 ++++++++++++++++++----------
1 files changed, 27 insertions(+), 15 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-text.c b/src/tracker-extract/tracker-extract-text.c
index 4ad8100..9468ec8 100644
--- a/src/tracker-extract/tracker-extract-text.c
+++ b/src/tracker-extract/tracker-extract-text.c
@@ -19,9 +19,21 @@
#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 <libtracker-extract/tracker-extract.h>
@@ -45,10 +57,9 @@ static gchar *
get_file_content (const gchar *uri,
gsize n_bytes)
{
- GFile *file;
- GFileInputStream *stream;
- GError *error = NULL;
- gchar *text;
+ GError *error = NULL;
+ gchar *text, *path;
+ int fd;
/* If no content requested, return */
if (n_bytes == 0) {
@@ -56,15 +67,16 @@ get_file_content (const gchar *uri,
}
/* Get filename from URI */
- file = g_file_new_for_uri (uri);
- stream = g_file_read (file, NULL, &error);
- if (error) {
- g_message ("Could not read file '%s': %s",
+ path = g_filename_from_uri (uri, NULL, NULL);
+
+ 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_object_unref (file);
-
+ g_free (path);
return NULL;
}
@@ -72,12 +84,12 @@ get_file_content (const gchar *uri,
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),
- n_bytes,
- TRY_LOCALE_TO_UTF8_CONVERSION);
+ text = tracker_read_text_from_fd (fd,
+ n_bytes,
+ TRY_LOCALE_TO_UTF8_CONVERSION);
- g_object_unref (stream);
- g_object_unref (file);
+ close (fd);
+ g_free (path);
return text;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]