[tracker/o_noatime: 1/12] tracker-extract: Don't use g_mapped_file_new which doesn't allow O_NOATIME
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/o_noatime: 1/12] tracker-extract: Don't use g_mapped_file_new which doesn't allow O_NOATIME
- Date: Thu, 22 Sep 2011 12:59:42 +0000 (UTC)
commit 6a2a521c2cb684389e634505ff45a8d456c9dcb3
Author: Philip Van Hoof <philip codeminded be>
Date: Wed Sep 21 16:31:48 2011 +0200
tracker-extract: Don't use g_mapped_file_new which doesn't allow O_NOATIME
src/tracker-extract/tracker-extract-abw.c | 47 ++++++++++++++++++++++++-----
1 files changed, 39 insertions(+), 8 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-abw.c b/src/tracker-extract/tracker-extract-abw.c
index ac8d0b4..079c9a1 100644
--- a/src/tracker-extract/tracker-extract-abw.c
+++ b/src/tracker-extract/tracker-extract-abw.c
@@ -24,15 +24,21 @@
#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>
+#ifndef _O_BINARY
+#define _O_BINARY 0
+#endif
+
#include <libtracker-common/tracker-file-utils.h>
#include <libtracker-extract/tracker-extract.h>
@@ -165,12 +171,13 @@ G_MODULE_EXPORT gboolean
tracker_extract_get_metadata (TrackerExtractInfo *info)
{
TrackerSparqlBuilder *preupdate, *metadata;
- GMappedFile *file;
+ int fd;
gchar *filename, *contents;
GError *error = NULL;
gboolean retval = FALSE;
GFile *f;
gsize len;
+ struct stat st;
preupdate = tracker_extract_info_get_preupdate_builder (info);
metadata = tracker_extract_info_get_metadata_builder (info);
@@ -184,17 +191,36 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
return retval;
}
- file = g_mapped_file_new (filename, FALSE, &error);
- g_free (filename);
+ fd = g_open (filename, O_RDONLY | _O_BINARY | O_NOATIME, 0);
- if (error) {
- g_warning ("Could not mmap abw file: %s\n", error->message);
+ if (fd == -1) {
+ g_warning ("Could not mmap abw file '%s': %s\n",
+ filename,
+ g_strerror (errno));
g_error_free (error);
+ g_free (filename);
return retval;
}
- contents = g_mapped_file_get_contents (file);
- len = g_mapped_file_get_length (file);
+ if (fstat (fd, &st) == -1) {
+ g_warning ("Could not fstat abw file '%s': %s\n",
+ filename,
+ g_strerror (errno));
+ close (fd);
+ g_error_free (error);
+ g_free (filename);
+ return retval;
+ }
+
+ if (st.st_size == 0) {
+ contents = NULL;
+ len = 0;
+ } else {
+ contents = (gchar *) mmap (NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
+ len = st.st_size;
+ }
+
+ g_free (filename);
if (contents) {
GMarkupParseContext *context;
@@ -225,7 +251,12 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
g_markup_parse_context_free (context);
}
- g_mapped_file_unref (file);
+
+ if (contents) {
+ munmap (contents, len);
+ }
+
+ close (fd);
return retval;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]