diff options
author | Martyn Russell <martyn@lanedo.com> | 2011-09-26 11:47:51 +0100 |
---|---|---|
committer | Martyn Russell <martyn@lanedo.com> | 2011-09-26 11:47:51 +0100 |
commit | 4bd7b32d36d4e20be1b1e14f4dbccb7b66583baa (patch) | |
tree | 9c3d43a5cf7ff13f07a8445ca54a1333a7f8ad85 | |
parent | 12e99cc69a48c39d316f58ab5e88c2f72b8d72c1 (diff) | |
parent | b7fb2b1c29db4bd213053f18898d43f031ca6659 (diff) | |
download | tracker-4bd7b32d36d4e20be1b1e14f4dbccb7b66583baa.tar.gz |
Merge branch 'tracker-0.10-no-atime' into tracker-0.10
-rw-r--r-- | src/libtracker-common/tracker-file-utils.c | 38 | ||||
-rw-r--r-- | src/libtracker-common/tracker-file-utils.h | 4 | ||||
-rw-r--r-- | src/tracker-extract/tracker-extract-abw.c | 56 | ||||
-rw-r--r-- | src/tracker-extract/tracker-extract-flac.c | 2 | ||||
-rw-r--r-- | src/tracker-extract/tracker-extract-gif.c | 24 | ||||
-rw-r--r-- | src/tracker-extract/tracker-extract-jpeg.c | 2 | ||||
-rw-r--r-- | src/tracker-extract/tracker-extract-mp3.c | 6 | ||||
-rw-r--r-- | src/tracker-extract/tracker-extract-msoffice.c | 40 | ||||
-rw-r--r-- | src/tracker-extract/tracker-extract-pdf.c | 67 | ||||
-rw-r--r-- | src/tracker-extract/tracker-extract-png.c | 2 | ||||
-rw-r--r-- | src/tracker-extract/tracker-extract-ps.c | 2 | ||||
-rw-r--r-- | src/tracker-extract/tracker-extract-text.c | 45 | ||||
-rw-r--r-- | src/tracker-extract/tracker-extract-tiff.c | 29 | ||||
-rw-r--r-- | src/tracker-extract/tracker-extract-vorbis.c | 3 | ||||
-rw-r--r-- | src/tracker-extract/tracker-extract-xmp.c | 65 | ||||
-rw-r--r-- | src/tracker-extract/tracker-gsf.c | 87 |
16 files changed, 356 insertions, 116 deletions
diff --git a/src/libtracker-common/tracker-file-utils.c b/src/libtracker-common/tracker-file-utils.c index 5a939cc7e..e2891ab43 100644 --- a/src/libtracker-common/tracker-file-utils.c +++ b/src/libtracker-common/tracker-file-utils.c @@ -51,36 +51,30 @@ static GHashTable *file_locks = NULL; FILE * -tracker_file_open (const gchar *path, - const gchar *how, - gboolean sequential) +tracker_file_open (const gchar *path) { - FILE *file; - gboolean readonly; - int flags; + FILE *file; + int fd; g_return_val_if_fail (path != NULL, NULL); - g_return_val_if_fail (how != NULL, NULL); - file = fopen (path, how); - if (!file) { - return NULL; +#if defined(__linux__) + fd = g_open (path, O_RDONLY | O_NOATIME); + if (fd == -1 && errno == EPERM) { + fd = g_open (path, O_RDONLY); } +#else + fd = g_open (path, O_RDONLY); +#endif - /* Are we opening for readonly? */ - readonly = !strstr (path, "r+") && strchr (path, 'r'); - - if (readonly) { - int fd; + if (fd == -1) { + return NULL; + } - fd = fileno (file); + file = fdopen (fd, "r"); -#if defined(__linux__) - /* Make sure we set the NOATIME flag if we have permissions to */ - if ((flags = fcntl (fd, F_GETFL, 0)) != -1) { - fcntl (fd, F_SETFL, flags | O_NOATIME); - } -#endif + if (!file) { + return NULL; } return file; diff --git a/src/libtracker-common/tracker-file-utils.h b/src/libtracker-common/tracker-file-utils.h index 6c5be1e36..d3a8bc8b0 100644 --- a/src/libtracker-common/tracker-file-utils.h +++ b/src/libtracker-common/tracker-file-utils.h @@ -32,9 +32,7 @@ G_BEGIN_DECLS #endif /* File utils */ -FILE* tracker_file_open (const gchar *path, - const gchar *how, - gboolean sequential); +FILE* tracker_file_open (const gchar *path); void tracker_file_close (FILE *file, gboolean need_again_soon); goffset tracker_file_get_size (const gchar *path); diff --git a/src/tracker-extract/tracker-extract-abw.c b/src/tracker-extract/tracker-extract-abw.c index 89f048f3b..bdbaaeaaf 100644 --- a/src/tracker-extract/tracker-extract-abw.c +++ b/src/tracker-extract/tracker-extract-abw.c @@ -24,11 +24,13 @@ #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> @@ -175,11 +177,11 @@ extract_abw (const gchar *uri, TrackerSparqlBuilder *preupdate, TrackerSparqlBuilder *metadata) { - GMappedFile *file; + int fd; gchar *filename, *contents; GError *error = NULL; - gboolean retval = FALSE; gsize len; + struct stat st; filename = g_filename_from_uri (uri, NULL, &error); @@ -189,19 +191,48 @@ extract_abw (const gchar *uri, return; } - file = g_mapped_file_new (filename, FALSE, &error); - g_free (filename); + fd = g_open (filename, O_RDONLY | O_NOATIME, 0); + if (fd == -1 && errno == EPERM) { + fd = g_open (filename, O_RDONLY, 0); + } - if (error) { - g_warning ("Could not mmap abw file: %s\n", error->message); - g_error_free (error); + if (fd == -1) { + g_warning ("Could not open abw file '%s': %s\n", + filename, + g_strerror (errno)); + g_free (filename); + return; + } + + if (fstat (fd, &st) == -1) { + g_warning ("Could not fstat abw file '%s': %s\n", + filename, + g_strerror (errno)); + close (fd); + g_free (filename); return; } - contents = g_mapped_file_get_contents (file); - len = g_mapped_file_get_length (file); + if (st.st_size == 0) { + contents = NULL; + len = 0; + } else { + contents = (gchar *) mmap (NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + if (contents == NULL) { + g_warning ("Could not mmap abw file '%s': %s\n", + filename, + g_strerror (errno)); + close (fd); + g_free (filename); + return; + } + len = st.st_size; + } + + g_free (filename); if (contents) { + GError *error = NULL; GMarkupParseContext *context; AbwParserData data = { 0 }; @@ -224,13 +255,16 @@ extract_abw (const gchar *uri, g_string_free (data.content, TRUE); } - retval = TRUE; } g_markup_parse_context_free (context); } - g_mapped_file_unref (file); + if (contents) { + munmap (contents, len); + } + + close (fd); } TrackerExtractData * diff --git a/src/tracker-extract/tracker-extract-flac.c b/src/tracker-extract/tracker-extract-flac.c index a4a69c95c..74e372b38 100644 --- a/src/tracker-extract/tracker-extract-flac.c +++ b/src/tracker-extract/tracker-extract-flac.c @@ -182,7 +182,7 @@ extract_flac (const gchar *uri, } iter = FLAC__metadata_simple_iterator_new (); - success = FLAC__metadata_simple_iterator_init (iter, filename, TRUE, FALSE); + success = FLAC__metadata_simple_iterator_init (iter, filename, TRUE, TRUE); g_free (filename); if (!success) { diff --git a/src/tracker-extract/tracker-extract-gif.c b/src/tracker-extract/tracker-extract-gif.c index 52ff73c92..725a31bbf 100644 --- a/src/tracker-extract/tracker-extract-gif.c +++ b/src/tracker-extract/tracker-extract-gif.c @@ -24,6 +24,13 @@ #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 <gif_lib.h> #include <libtracker-common/tracker-common.h> @@ -544,6 +551,7 @@ extract_gif (const gchar *uri, goffset size; GifFileType *gifFile = NULL; gchar *filename; + int fd; filename = g_filename_from_uri (uri, NULL, NULL); size = tracker_file_get_size (filename); @@ -553,7 +561,20 @@ extract_gif (const gchar *uri, return; } - if ((gifFile = DGifOpenFileName (filename)) == NULL) { + fd = g_open (filename, O_RDONLY | O_NOATIME, 0); + if (fd == -1 && errno == EPERM) { + fd = g_open (filename, O_RDONLY, 0); + } + + if (fd == -1) { + g_warning ("Could not open gif file '%s': %s\n", + filename, + g_strerror (errno)); + g_free (filename); + return; + } + + if ((gifFile = DGifOpenFileHandle (fd)) == NULL) { PrintGifError (); return; } @@ -570,6 +591,7 @@ extract_gif (const gchar *uri, PrintGifError (); } + close (fd); } TrackerExtractData * diff --git a/src/tracker-extract/tracker-extract-jpeg.c b/src/tracker-extract/tracker-extract-jpeg.c index dd856cf6d..149bd3074 100644 --- a/src/tracker-extract/tracker-extract-jpeg.c +++ b/src/tracker-extract/tracker-extract-jpeg.c @@ -178,7 +178,7 @@ extract_jpeg (const gchar *uri, return; } - f = tracker_file_open (filename, "rb", FALSE); + f = tracker_file_open (filename); g_free (filename); if (!f) { diff --git a/src/tracker-extract/tracker-extract-mp3.c b/src/tracker-extract/tracker-extract-mp3.c index b2b05b5ef..fb2747799 100644 --- a/src/tracker-extract/tracker-extract-mp3.c +++ b/src/tracker-extract/tracker-extract-mp3.c @@ -2102,9 +2102,9 @@ extract_mp3 (const gchar *uri, * without as a last resort. This can happen due to * permissions. */ - fd = open (filename, O_RDONLY | O_NOATIME); - if (fd == -1) { - fd = open (filename, O_RDONLY); + fd = g_open (filename, O_RDONLY | O_NOATIME); + if (fd == -1 && errno == EPERM) { + fd = g_open (filename, O_RDONLY); if (fd == -1) { return; diff --git a/src/tracker-extract/tracker-extract-msoffice.c b/src/tracker-extract/tracker-extract-msoffice.c index aeee999ef..1637c7965 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> @@ -757,28 +759,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; } @@ -1655,6 +1649,8 @@ extract_msoffice (const gchar *uri, gchar *content = NULL; gboolean is_encrypted = FALSE; gsize max_bytes; + gchar *filename; + FILE *mfile; file = g_file_new_for_uri (uri); @@ -1679,10 +1675,24 @@ extract_msoffice (const gchar *uri, gsf_init (); - 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)); + return; + } + + infile = open_file (uri, mfile); if (!infile) { g_object_unref (file_info); gsf_shutdown (); + if (mfile) { + tracker_file_close (mfile, FALSE); + } return; } @@ -1728,6 +1738,10 @@ extract_msoffice (const gchar *uri, g_object_unref (infile); g_object_unref (file_info); gsf_shutdown (); + + if (mfile) { + tracker_file_close (mfile, FALSE); + } } TrackerExtractData * diff --git a/src/tracker-extract/tracker-extract-pdf.c b/src/tracker-extract/tracker-extract-pdf.c index 787ba7218..04052dade 100644 --- a/src/tracker-extract/tracker-extract-pdf.c +++ b/src/tracker-extract/tracker-extract-pdf.c @@ -21,13 +21,25 @@ #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 <glib/poppler.h> #include <libtracker-common/tracker-date-time.h> #include <libtracker-common/tracker-utils.h> +#include <libtracker-common/tracker-file-utils.h> #include <libtracker-extract/tracker-extract.h> @@ -291,11 +303,58 @@ extract_pdf (const gchar *uri, GPtrArray *keywords; guint i; GString *where = NULL; + gchar *filename; + int fd; + gchar *contents = NULL; + gsize len; + struct stat st; g_type_init (); - document = poppler_document_new_from_file (uri, NULL, &error); + filename = g_filename_from_uri (uri, NULL, NULL); + + fd = g_open (filename, O_RDONLY | O_NOATIME, 0); + if (fd == -1 && errno == EPERM) { + fd = g_open (filename, O_RDONLY, 0); + } + + if (fd == -1) { + g_warning ("Could not open pdf file '%s': %s\n", + filename, + g_strerror (errno)); + g_free (filename); + return; + } + + if (fstat (fd, &st) == -1) { + g_warning ("Could not fstat pdf file '%s': %s\n", + filename, + g_strerror (errno)); + close (fd); + g_free (filename); + return; + } + + if (st.st_size == 0) { + contents = NULL; + len = 0; + } else { + contents = (gchar *) mmap (NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + if (contents == NULL) { + g_warning ("Could not mmap pdf file '%s': %s\n", + filename, + g_strerror (errno)); + close (fd); + g_free (filename); + return; + } + len = st.st_size; + } + g_free (filename); + + document = poppler_document_new_from_data (contents, len, NULL, &error); + if (error) { if (error->code == POPPLER_ERROR_ENCRYPTED) { tracker_sparql_builder_predicate (metadata, "a"); @@ -651,6 +710,12 @@ extract_pdf (const gchar *uri, g_free (pd.date); g_object_unref (document); + + if (contents) { + munmap (contents, len); + } + + close (fd); } TrackerExtractData * diff --git a/src/tracker-extract/tracker-extract-png.c b/src/tracker-extract/tracker-extract-png.c index 538c4a0f6..1f832d801 100644 --- a/src/tracker-extract/tracker-extract-png.c +++ b/src/tracker-extract/tracker-extract-png.c @@ -768,7 +768,7 @@ extract_png (const gchar *uri, return; } - f = tracker_file_open (filename, "r", FALSE); + f = tracker_file_open (filename); g_free (filename); if (!f) { diff --git a/src/tracker-extract/tracker-extract-ps.c b/src/tracker-extract/tracker-extract-ps.c index fcd24a4fe..a9f0649df 100644 --- a/src/tracker-extract/tracker-extract-ps.c +++ b/src/tracker-extract/tracker-extract-ps.c @@ -222,7 +222,7 @@ extract_ps (const gchar *uri, gchar *filename; filename = g_filename_from_uri (uri, NULL, NULL); - f = tracker_file_open (filename, "r", TRUE); + f = tracker_file_open (filename); g_free (filename); if (!f) { diff --git a/src/tracker-extract/tracker-extract-text.c b/src/tracker-extract/tracker-extract-text.c index 4ad81008d..b1db4fca5 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,19 @@ 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 && errno == EPERM) { + fd = g_open (path, O_RDONLY, 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 +87,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; } diff --git a/src/tracker-extract/tracker-extract-tiff.c b/src/tracker-extract/tracker-extract-tiff.c index d86781f15..d177c3c5f 100644 --- a/src/tracker-extract/tracker-extract-tiff.c +++ b/src/tracker-extract/tracker-extract-tiff.c @@ -20,6 +20,17 @@ #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 <glib/gstdio.h> #include <tiffio.h> @@ -269,6 +280,7 @@ extract_tiff (const gchar *uri, GPtrArray *keywords; guint i; GString *where = NULL; + int fd; #ifdef HAVE_LIBIPTCDATA gchar *iptc_offset; @@ -282,9 +294,23 @@ extract_tiff (const gchar *uri, filename = g_filename_from_uri (uri, NULL, NULL); - if ((image = TIFFOpen (filename, "r")) == NULL){ + fd = g_open (filename, O_RDONLY | O_NOATIME, 0); + if (fd == -1 && errno == EPERM) { + fd = g_open (filename, O_RDONLY, 0); + } + + if (fd == -1) { + g_warning ("Could not open tiff file '%s': %s\n", + filename, + g_strerror (errno)); + g_free (filename); + return; + } + + if ((image = TIFFFdOpen (fd, filename, "r")) == NULL){ g_warning ("Could not open image:'%s'\n", filename); g_free (filename); + close (fd); return; } @@ -774,6 +800,7 @@ extract_tiff (const gchar *uri, tracker_exif_free (ed); tracker_xmp_free (xd); tracker_iptc_free (id); + close (fd); } TrackerExtractData * diff --git a/src/tracker-extract/tracker-extract-vorbis.c b/src/tracker-extract/tracker-extract-vorbis.c index 0108fcce2..53b5a8839 100644 --- a/src/tracker-extract/tracker-extract-vorbis.c +++ b/src/tracker-extract/tracker-extract-vorbis.c @@ -111,7 +111,8 @@ extract_vorbis (const char *uri, gint time; filename = g_filename_from_uri (uri, NULL, NULL); - f = tracker_file_open (filename, "r", FALSE); + + f = tracker_file_open (filename); g_free (filename); if (!f) { diff --git a/src/tracker-extract/tracker-extract-xmp.c b/src/tracker-extract/tracker-extract-xmp.c index 21ac36bc6..d80df9f9d 100644 --- a/src/tracker-extract/tracker-extract-xmp.c +++ b/src/tracker-extract/tracker-extract-xmp.c @@ -19,6 +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> @@ -134,14 +149,54 @@ extract_xmp (const gchar *uri, TrackerSparqlBuilder *metadata) { TrackerXmpData *xd = NULL; - GError *error = NULL; gchar *filename; gchar *contents; - gsize length; + gsize length = 0; + int fd; + struct stat st; + filename = g_filename_from_uri (uri, NULL, NULL); - if (g_file_get_contents (filename, &contents, &length, &error)) { + fd = g_open (filename, O_RDONLY | O_NOATIME, 0); + if (fd == -1 && errno == EPERM) { + fd = g_open (filename, O_RDONLY, 0); + } + + if (fd == -1) { + g_warning ("Could not open xmp file '%s': %s\n", + filename, + g_strerror (errno)); + g_free (filename); + return; + } + + if (fstat (fd, &st) == -1) { + g_warning ("Could not fstat xmp file '%s': %s\n", + filename, + g_strerror (errno)); + close (fd); + g_free (filename); + return; + } + + if (st.st_size == 0) { + contents = NULL; + length = 0; + } else { + contents = (gchar *) mmap (NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + if (contents == NULL) { + g_warning ("Could not mmap xmp file '%s': %s\n", + filename, + g_strerror (errno)); + close (fd); + g_free (filename); + return; + } + length = st.st_size; + } + + if (contents) { gchar *original_uri; original_uri = find_orig_uri (filename); @@ -159,9 +214,11 @@ extract_xmp (const gchar *uri, g_free (original_uri); tracker_xmp_free (xd); - g_free (contents); + + munmap (contents, length); } + close (fd); g_free (filename); } diff --git a/src/tracker-extract/tracker-gsf.c b/src/tracker-extract/tracker-gsf.c index 9d73236eb..b33aeba99 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); + 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); } } |