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



commit 6d0627d181b00a9ef313e7a90caf7afc664129eb
Author: Philip Van Hoof <philip codeminded be>
Date:   Thu Sep 22 10:46:25 2011 +0200

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

 src/tracker-extract/tracker-extract-msoffice.c |   40 ++++++++++++++++--------
 1 files changed, 27 insertions(+), 13 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-msoffice.c b/src/tracker-extract/tracker-extract-msoffice.c
index e28a986..a1b83de 100644
--- a/src/tracker-extract/tracker-extract-msoffice.c
+++ b/src/tracker-extract/tracker-extract-msoffice.c
@@ -21,6 +21,7 @@
 
 #include "config.h"
 
+#include <errno.h>
 #include <string.h>
 
 #include <glib.h>
@@ -35,6 +36,7 @@
 #include <gsf/gsf-infile-zip.h>
 
 #include <libtracker-common/tracker-utils.h>
+#include <libtracker-common/tracker-file-utils.h>
 #include <libtracker-common/tracker-os-dependant.h>
 
 #include <libtracker-extract/tracker-extract.h>
@@ -745,28 +747,20 @@ extract_powerpoint_content (GsfInfile *infile,
 	return all_texts ? g_string_free (all_texts, FALSE) : NULL;
 }
 
-/**
- * @brief Open specified uri for reading and initialize gsf
- * @param uri URI of the file to open
- * @return GsfInFile of the opened file or NULL if failed to open file
- */
 static GsfInfile *
-open_uri (const gchar *uri)
+open_file (const gchar *filename, FILE *file)
 {
 	GsfInput *input;
 	GsfInfile *infile;
-	gchar *filename;
-
-	filename = g_filename_from_uri (uri, NULL, NULL);
-	input = gsf_input_stdio_new (filename, NULL);
-	g_free (filename);
 
+	input = gsf_input_stdio_new_FILE (filename, file, TRUE);
+	
 	if (!input) {
 		return NULL;
 	}
 
 	infile = gsf_infile_msole_new (input, NULL);
-	g_object_unref (G_OBJECT (input));
+	g_object_unref (input);
 
 	return infile;
 }
@@ -1641,6 +1635,8 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
 	const gchar *mime_used;
 	gsize max_bytes;
 	GFile *file;
+	gchar *filename;
+	FILE *mfile;
 
 	gsf_init ();
 
@@ -1650,10 +1646,25 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
 	file = tracker_extract_info_get_file (info);
 	uri = g_file_get_uri (file);
 
-	infile = open_uri (uri);
+	filename = g_filename_from_uri (uri, NULL, NULL);
+
+	mfile = tracker_file_open (filename);
+	g_free (filename);
+
+	if (!mfile) {
+		g_warning ("Can't open file from uri '%s': %s",
+		           uri, g_strerror (errno));
+		g_free (uri);
+		return FALSE;
+	}
+
+	infile = open_file (uri, mfile);
 	if (!infile) {
 		gsf_shutdown ();
 		g_free (uri);
+		if (mfile) {
+			tracker_file_close (mfile, FALSE);
+		}
 		return FALSE;
 	}
 
@@ -1697,6 +1708,9 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
 	g_object_unref (infile);
 	g_free (uri);
 	gsf_shutdown ();
+	if (mfile) {
+		tracker_file_close (mfile, FALSE);
+	}
 
 	return TRUE;
 }



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