[tracker/o_noatime] tracker-extract: Don't use g_mapped_file_new which doesn't allow O_NOATIME



commit cfb41b3abe99ff5e7782071840459646ef259c03
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]