[tracker] tracker-extract: Use O_NOATIME for files opened by libgsf (ie. EPub files)
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker] tracker-extract: Use O_NOATIME for files opened by libgsf (ie. EPub files)
- Date: Thu, 22 Sep 2011 15:39:08 +0000 (UTC)
commit 26c332b481c0bafda87cf5d230d5e5287f7e1b91
Author: Philip Van Hoof <philip codeminded be>
Date: Wed Sep 21 17:17:55 2011 +0200
tracker-extract: Use O_NOATIME for files opened by libgsf (ie. EPub files)
src/tracker-extract/tracker-gsf.c | 87 +++++++++++++++++++++----------------
1 files changed, 50 insertions(+), 37 deletions(-)
---
diff --git a/src/tracker-extract/tracker-gsf.c b/src/tracker-extract/tracker-gsf.c
index 9d73236..a715d6c 100644
--- a/src/tracker-extract/tracker-gsf.c
+++ b/src/tracker-extract/tracker-gsf.c
@@ -17,10 +17,13 @@
* Boston, MA 02110-1301, USA.
*/
+#include <errno.h>
#include <string.h>
#include <glib.h>
+#include <libtracker-common/tracker-file-utils.h>
+
#include <gsf/gsf.h>
#include <gsf/gsf-infile.h>
#include <gsf/gsf-input-stdio.h>
@@ -87,6 +90,7 @@ tracker_gsf_parse_xml_in_zip (const gchar *zip_file_uri,
GsfInfile *infile = NULL;
GsfInput *src = NULL;
GsfInput *member = NULL;
+ FILE *file;
g_debug ("Parsing '%s' XML file from '%s' zip archive...",
xml_filename, zip_file_uri);
@@ -96,49 +100,58 @@ tracker_gsf_parse_xml_in_zip (const gchar *zip_file_uri,
NULL, &error)) == NULL) {
g_warning ("Can't get filename from uri '%s': %s",
zip_file_uri, error ? error->message : "no error given");
- }
- /* Create a new Input GSF object for the given file */
- else if ((src = gsf_input_stdio_new (filename, &error)) == NULL) {
- g_warning ("Failed creating a GSF Input object for '%s': %s",
- zip_file_uri, error ? error->message : "no error given");
- }
- /* Input object is a Zip file */
- else if ((infile = gsf_infile_zip_new (src, &error)) == NULL) {
- g_warning ("'%s' Not a zip file: %s",
- zip_file_uri, error ? error->message : "no error given");
- }
- /* Look for requested filename inside the ZIP file */
- else if ((member = find_member (infile, xml_filename)) == NULL) {
- g_warning ("No member '%s' in zip file '%s'",
- xml_filename, zip_file_uri);
- }
- /* Load whole contents of the internal file in the xml buffer */
- else {
- guint8 buf[XML_BUFFER_SIZE];
- size_t remaining_size, chunk_size, accum;
+ } else { /* Create a new Input GSF object for the given file */
+
+ file = tracker_file_open (filename, "rb", FALSE);
+ if (!file) {
+ g_warning ("Can't open file from uri '%s': %s",
+ zip_file_uri, g_strerror (errno));
+ } else if ((src = gsf_input_stdio_new_FILE (filename, file, TRUE)) == NULL) {
+ g_warning ("Failed creating a GSF Input object for '%s': %s",
+ zip_file_uri, error ? error->message : "no error given");
+ }
+ /* Input object is a Zip file */
+ else if ((infile = gsf_infile_zip_new (src, &error)) == NULL) {
+ g_warning ("'%s' Not a zip file: %s",
+ zip_file_uri, error ? error->message : "no error given");
+ }
+ /* Look for requested filename inside the ZIP file */
+ else if ((member = find_member (infile, xml_filename)) == NULL) {
+ g_warning ("No member '%s' in zip file '%s'",
+ xml_filename, zip_file_uri);
+ }
+ /* Load whole contents of the internal file in the xml buffer */
+ else {
+ guint8 buf[XML_BUFFER_SIZE];
+ size_t remaining_size, chunk_size, accum;
- /* Get whole size of the contents to read */
- remaining_size = (size_t) gsf_input_size (GSF_INPUT (member));
+ /* Get whole size of the contents to read */
+ remaining_size = (size_t) gsf_input_size (GSF_INPUT (member));
- /* Note that gsf_input_read() needs to be able to read ALL specified
- * number of bytes, or it will fail */
- chunk_size = MIN (remaining_size, XML_BUFFER_SIZE);
+ /* Note that gsf_input_read() needs to be able to read ALL specified
+ * number of bytes, or it will fail */
+ chunk_size = MIN (remaining_size, XML_BUFFER_SIZE);
- accum = 0;
- while (!error &&
- accum <= XML_MAX_BYTES_READ &&
- chunk_size > 0 &&
- gsf_input_read (GSF_INPUT (member), chunk_size, buf) != NULL) {
+ accum = 0;
+ while (!error &&
+ accum <= XML_MAX_BYTES_READ &&
+ chunk_size > 0 &&
+ gsf_input_read (GSF_INPUT (member), chunk_size, buf) != NULL) {
- /* update accumulated count */
- accum += chunk_size;
+ /* update accumulated count */
+ accum += chunk_size;
- /* Pass the read stream to the context parser... */
- g_markup_parse_context_parse (context, buf, chunk_size, &error);
+ /* Pass the read stream to the context parser... */
+ g_markup_parse_context_parse (context, buf, chunk_size, &error);
- /* update bytes to be read */
- remaining_size -= chunk_size;
- chunk_size = MIN (remaining_size, XML_BUFFER_SIZE);
+ /* update bytes to be read */
+ remaining_size -= chunk_size;
+ chunk_size = MIN (remaining_size, XML_BUFFER_SIZE);
+ }
+ }
+
+ if (file) {
+ tracker_file_close (file, FALSE);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]