[tracker] tracker-extract: Use posix_fadvise() when closing files



commit 1c439892a0ec0071aa3af505d5ecb7e1447f39cc
Author: Martyn Russell <martyn lanedo com>
Date:   Mon Oct 11 14:53:14 2010 +0100

    tracker-extract: Use posix_fadvise() when closing files
    
    First stab at fixing GB#575993
    This only includes ABW, JPEG, MP3, PNG, PS, OGG and TEXT so far

 src/libtracker-common/tracker-file-utils.c   |    6 ++++++
 src/tracker-extract/tracker-extract-mp3.c    |    4 ++++
 src/tracker-extract/tracker-extract-ps.c     |    3 +++
 src/tracker-extract/tracker-extract-vorbis.c |    4 ++++
 src/tracker-extract/tracker-read.c           |    6 ++++++
 5 files changed, 23 insertions(+), 0 deletions(-)
---
diff --git a/src/libtracker-common/tracker-file-utils.c b/src/libtracker-common/tracker-file-utils.c
index 5cf65bd..f33fa3d 100644
--- a/src/libtracker-common/tracker-file-utils.c
+++ b/src/libtracker-common/tracker-file-utils.c
@@ -88,6 +88,12 @@ tracker_file_close (FILE     *file,
 {
 	g_return_if_fail (file != NULL);
 
+#ifdef HAVE_POSIX_FADVISE
+	if (!need_again_soon) {
+		posix_fadvise (fileno (file), 0, 0, POSIX_FADV_DONTNEED);
+	}
+#endif /* HAVE_POSIX_FADVISE */
+
 	fclose (file);
 }
 
diff --git a/src/tracker-extract/tracker-extract-mp3.c b/src/tracker-extract/tracker-extract-mp3.c
index a78180b..e48e797 100644
--- a/src/tracker-extract/tracker-extract-mp3.c
+++ b/src/tracker-extract/tracker-extract-mp3.c
@@ -2031,6 +2031,10 @@ extract_mp3 (const gchar          *uri,
 
 	id3v1_buffer = read_id3v1_buffer (fd, size);
 
+#ifdef HAVE_POSIX_FADVISE
+	posix_fadvise (fd, 0, 0, POSIX_FADV_DONTNEED);
+#endif /* HAVE_POSIX_FADVISE */
+
 	close (fd);
 
 	if (buffer == NULL || buffer == (void*) -1) {
diff --git a/src/tracker-extract/tracker-extract-ps.c b/src/tracker-extract/tracker-extract-ps.c
index 9ff0242..704036a 100644
--- a/src/tracker-extract/tracker-extract-ps.c
+++ b/src/tracker-extract/tracker-extract-ps.c
@@ -284,6 +284,9 @@ extract_ps_gz (const gchar          *uri,
 	{
 		g_debug ("Extracting compressed PS '%s'...", uri);
 		extract_ps_from_filestream (fz, preupdate, metadata);
+#ifdef HAVE_POSIX_FADVISE
+		posix_fadvise (fdz, 0, 0, POSIX_FADV_DONTNEED);
+#endif /* HAVE_POSIX_FADVISE */
 		fclose (fz);
 	}
 
diff --git a/src/tracker-extract/tracker-extract-vorbis.c b/src/tracker-extract/tracker-extract-vorbis.c
index 213c25d..6998795 100644
--- a/src/tracker-extract/tracker-extract-vorbis.c
+++ b/src/tracker-extract/tracker-extract-vorbis.c
@@ -437,6 +437,10 @@ extract_vorbis (const char *uri,
 	g_free (vd.album_artist);
 	g_free (vd.performer);
 
+#ifdef HAVE_POSIX_FADVISE
+	posix_fadvise (fileno (f), 0, 0, POSIX_FADV_DONTNEED);
+#endif /* HAVE_POSIX_FADVISE */
+
 	/* NOTE: This calls fclose on the file */
 	ov_clear (&vf);
 }
diff --git a/src/tracker-extract/tracker-read.c b/src/tracker-extract/tracker-read.c
index be364ad..f786c09 100644
--- a/src/tracker-extract/tracker-read.c
+++ b/src/tracker-extract/tracker-read.c
@@ -17,8 +17,11 @@
  * Boston, MA  02110-1301, USA.
  */
 
+#include "config.h"
+
 #include <string.h>
 #include <unistd.h>
+#include <fcntl.h>
 
 #include <glib.h>
 #include <gio/gio.h>
@@ -272,6 +275,9 @@ tracker_read_text_from_fd (gint     fd,
 	}
 
 	/* Close the file here */
+#ifdef HAVE_POSIX_FADVISE
+	posix_fadvise (fd, 0, 0, POSIX_FADV_DONTNEED);
+#endif /* HAVE_POSIX_FADVISE */
 	fclose (fz);
 
 	/* Validate UTF-8 if something was read, and return it */



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