open(2) with the NOATIME flag is only available on Linux. Instead of

duplicating the same code all over with ifdef, factorize into a function
that opens file descriptors in a portable way.
This commit is contained in:
ajacoutot 2012-01-22 15:13:23 +00:00
parent f5d46be714
commit 488ad78d0d
10 changed files with 141 additions and 76 deletions

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.92 2012/01/02 14:11:21 ajacoutot Exp $
# $OpenBSD: Makefile,v 1.93 2012/01/22 15:13:23 ajacoutot Exp $
# XXX Binary files patch-src_tracker-control_tracker-control-general_c
# and patch-src_tracker-control_tracker-control-general_c.new differ
@ -21,7 +21,7 @@ PKGNAME-main= meta-tracker-${VERSION}
PKGNAME-evolution= evolution-meta-tracker-${VERSION}
PKGNAME-nautilus= nautilus-meta-tracker-${VERSION}
REVISION-main= 3
REVISION-main= 4
MAJ_V= ${GNOME_VERSION:C/^([0-9]+\.[0-9]+).*/\1/}
EVO_VERSION= 3.2

View File

@ -0,0 +1,45 @@
$OpenBSD: patch-src_libtracker-common_tracker-file-utils_c,v 1.3 2012/01/22 15:13:23 ajacoutot Exp $
--- src/libtracker-common/tracker-file-utils.c.orig Fri Dec 16 17:08:04 2011
+++ src/libtracker-common/tracker-file-utils.c Tue Jan 10 09:51:39 2012
@@ -50,22 +50,34 @@
static GHashTable *file_locks = NULL;
-FILE *
-tracker_file_open (const gchar *path)
+gint
+tracker_file_open_fd (const gchar *path)
{
- FILE *file;
- int fd;
+ gint fd;
g_return_val_if_fail (path != NULL, NULL);
#if defined(__linux__)
- fd = g_open (path, O_RDONLY | O_NOATIME);
+ fd = g_open (path, O_RDONLY | O_NOATIME, 0);
if (fd == -1 && errno == EPERM) {
- fd = g_open (path, O_RDONLY);
+ fd = g_open (path, O_RDONLY, 0);
}
#else
- fd = g_open (path, O_RDONLY);
+ fd = g_open (path, O_RDONLY, 0);
#endif
+
+ return fd;
+}
+
+FILE *
+tracker_file_open (const gchar *path)
+{
+ FILE *file;
+ gint fd;
+
+ g_return_val_if_fail (path != NULL, NULL);
+
+ fd = tracker_file_open_fd (path);
if (fd == -1) {
return NULL;

View File

@ -0,0 +1,11 @@
$OpenBSD: patch-src_libtracker-common_tracker-file-utils_h,v 1.1 2012/01/22 15:13:23 ajacoutot Exp $
--- src/libtracker-common/tracker-file-utils.h.orig Tue Jan 10 09:16:39 2012
+++ src/libtracker-common/tracker-file-utils.h Tue Jan 10 09:17:10 2012
@@ -32,6 +32,7 @@ G_BEGIN_DECLS
#endif
/* File utils */
+gint tracker_file_open_fd (const gchar *path);
FILE* tracker_file_open (const gchar *path);
void tracker_file_close (FILE *file,
gboolean need_again_soon);

View File

@ -1,21 +1,18 @@
$OpenBSD: patch-src_tracker-extract_tracker-extract-abw_c,v 1.6 2011/12/21 14:20:06 ajacoutot Exp $
$OpenBSD: patch-src_tracker-extract_tracker-extract-abw_c,v 1.7 2012/01/22 15:13:23 ajacoutot Exp $
https://bugzilla.gnome.org/show_bug.cgi?id=666654
--- src/tracker-extract/tracker-extract-abw.c.orig Mon Sep 26 11:26:39 2011
+++ src/tracker-extract/tracker-extract-abw.c Mon Sep 26 12:30:31 2011
@@ -180,10 +180,14 @@ tracker_extract_get_metadata (TrackerExtractInfo *info
--- src/tracker-extract/tracker-extract-abw.c.orig Fri Dec 16 16:24:23 2011
+++ src/tracker-extract/tracker-extract-abw.c Tue Jan 10 09:19:28 2012
@@ -180,10 +180,7 @@ tracker_extract_get_metadata (TrackerExtractInfo *info
f = tracker_extract_info_get_file (info);
filename = g_file_get_path (f);
+#if defined(__linux__)
fd = g_open (filename, O_RDONLY | O_NOATIME, 0);
if (fd == -1 && errno == EPERM) {
fd = g_open (filename, O_RDONLY, 0);
}
+#else
+ fd = g_open (filename, O_RDONLY, 0);
+#endif
- fd = g_open (filename, O_RDONLY | O_NOATIME, 0);
- if (fd == -1 && errno == EPERM) {
- fd = g_open (filename, O_RDONLY, 0);
- }
+ fd = tracker_file_open_fd (filename);
if (fd == -1) {
g_warning ("Could not open abw file '%s': %s\n",

View File

@ -1,21 +1,18 @@
$OpenBSD: patch-src_tracker-extract_tracker-extract-gif_c,v 1.3 2011/12/21 14:20:06 ajacoutot Exp $
$OpenBSD: patch-src_tracker-extract_tracker-extract-gif_c,v 1.4 2012/01/22 15:13:23 ajacoutot Exp $
https://bugzilla.gnome.org/show_bug.cgi?id=666654
--- src/tracker-extract/tracker-extract-gif.c.orig Mon Sep 26 11:26:47 2011
+++ src/tracker-extract/tracker-extract-gif.c Mon Sep 26 12:30:46 2011
@@ -606,10 +606,14 @@ tracker_extract_get_metadata (TrackerExtractInfo *info
--- src/tracker-extract/tracker-extract-gif.c.orig Fri Dec 16 16:24:23 2011
+++ src/tracker-extract/tracker-extract-gif.c Tue Jan 10 09:19:45 2012
@@ -606,10 +606,7 @@ tracker_extract_get_metadata (TrackerExtractInfo *info
return FALSE;
}
+#if defined(__linux__)
fd = g_open (filename, O_RDONLY | O_NOATIME, 0);
if (fd == -1 && errno == EPERM) {
fd = g_open (filename, O_RDONLY, 0);
}
+#else
+ fd = g_open (filename, O_RDONLY, 0);
+#endif
- fd = g_open (filename, O_RDONLY | O_NOATIME, 0);
- if (fd == -1 && errno == EPERM) {
- fd = g_open (filename, O_RDONLY, 0);
- }
+ fd = tracker_file_open_fd (filename);
if (fd == -1) {
g_warning ("Could not open gif file '%s': %s\n",

View File

@ -1,6 +1,6 @@
$OpenBSD: patch-src_tracker-extract_tracker-extract-mp3_c,v 1.10 2011/10/06 20:26:47 ajacoutot Exp $
--- src/tracker-extract/tracker-extract-mp3.c.orig Thu Oct 6 15:07:14 2011
+++ src/tracker-extract/tracker-extract-mp3.c Thu Oct 6 20:22:53 2011
$OpenBSD: patch-src_tracker-extract_tracker-extract-mp3_c,v 1.11 2012/01/22 15:13:23 ajacoutot Exp $
--- src/tracker-extract/tracker-extract-mp3.c.orig Fri Dec 16 16:24:23 2011
+++ src/tracker-extract/tracker-extract-mp3.c Tue Jan 10 09:32:18 2012
@@ -1049,10 +1049,10 @@ id3v2_strlen (const gchar encoding,
case 0x02:
@ -14,3 +14,30 @@ $OpenBSD: patch-src_tracker-extract_tracker-extract-mp3_c,v 1.10 2011/10/06 20:2
} else {
pos++;
}
@@ -2093,25 +2093,11 @@ tracker_extract_get_metadata (TrackerExtractInfo *info
md.size = size;
buffer_size = MIN (size, MAX_FILE_READ);
-#if defined(__linux__)
- /* Can return -1 because of O_NOATIME, so we try again after
- * without as a last resort. This can happen due to
- * permissions.
- */
- fd = g_open (filename, O_RDONLY | O_NOATIME);
- if (fd == -1 && errno == EPERM) {
- fd = g_open (filename, O_RDONLY);
+ fd = tracker_file_open_fd (filename);
- if (fd == -1) {
- return FALSE;
- }
- }
-#else
- fd = open (filename, O_RDONLY);
if (fd == -1) {
return FALSE;
}
-#endif
#ifndef G_OS_WIN32
/* We don't use GLib's mmap because size can not be specified */

View File

@ -1,21 +1,18 @@
$OpenBSD: patch-src_tracker-extract_tracker-extract-pdf_c,v 1.4 2011/12/21 14:20:06 ajacoutot Exp $
$OpenBSD: patch-src_tracker-extract_tracker-extract-pdf_c,v 1.5 2012/01/22 15:13:23 ajacoutot Exp $
https://bugzilla.gnome.org/show_bug.cgi?id=666654
--- src/tracker-extract/tracker-extract-pdf.c.orig Fri Nov 25 15:50:33 2011
+++ src/tracker-extract/tracker-extract-pdf.c Fri Nov 25 18:52:47 2011
@@ -311,10 +311,14 @@ tracker_extract_get_metadata (TrackerExtractInfo *info
--- src/tracker-extract/tracker-extract-pdf.c.orig Fri Dec 16 16:24:23 2011
+++ src/tracker-extract/tracker-extract-pdf.c Tue Jan 10 09:20:16 2012
@@ -311,10 +311,7 @@ tracker_extract_get_metadata (TrackerExtractInfo *info
file = tracker_extract_info_get_file (info);
filename = g_file_get_path (file);
+#if defined(__linux__)
fd = g_open (filename, O_RDONLY | O_NOATIME, 0);
if (fd == -1 && errno == EPERM) {
fd = g_open (filename, O_RDONLY, 0);
}
+#else
+ fd = g_open (filename, O_RDONLY, 0);
+#endif
- fd = g_open (filename, O_RDONLY | O_NOATIME, 0);
- if (fd == -1 && errno == EPERM) {
- fd = g_open (filename, O_RDONLY, 0);
- }
+ fd = tracker_file_open_fd (filename);
if (fd == -1) {
g_warning ("Could not open pdf file '%s': %s\n",

View File

@ -1,21 +1,18 @@
$OpenBSD: patch-src_tracker-extract_tracker-extract-text_c,v 1.5 2011/12/21 14:20:06 ajacoutot Exp $
$OpenBSD: patch-src_tracker-extract_tracker-extract-text_c,v 1.6 2012/01/22 15:13:23 ajacoutot Exp $
https://bugzilla.gnome.org/show_bug.cgi?id=666654
--- src/tracker-extract/tracker-extract-text.c.orig Fri Dec 16 16:37:39 2011
+++ src/tracker-extract/tracker-extract-text.c Fri Dec 16 18:02:12 2011
@@ -58,10 +58,14 @@ get_file_content (GFile *file,
+++ src/tracker-extract/tracker-extract-text.c Tue Jan 10 09:20:33 2012
@@ -58,10 +58,7 @@ get_file_content (GFile *file,
/* Get filename from URI */
path = g_file_get_path (file);
+#if defined(__linux__)
fd = g_open (path, O_RDONLY | O_NOATIME, 0);
if (fd == -1 && errno == EPERM) {
fd = g_open (path, O_RDONLY, 0);
}
+#else
+ fd = g_open (path, O_RDONLY, 0);
+#endif
- fd = g_open (path, O_RDONLY | O_NOATIME, 0);
- if (fd == -1 && errno == EPERM) {
- fd = g_open (path, O_RDONLY, 0);
- }
+ fd = tracker_file_open_fd (path);
if (fd == -1) {
g_message ("Could not open file '%s': %s",

View File

@ -1,21 +1,18 @@
$OpenBSD: patch-src_tracker-extract_tracker-extract-tiff_c,v 1.3 2011/12/21 14:20:06 ajacoutot Exp $
$OpenBSD: patch-src_tracker-extract_tracker-extract-tiff_c,v 1.4 2012/01/22 15:13:23 ajacoutot Exp $
https://bugzilla.gnome.org/show_bug.cgi?id=666654
--- src/tracker-extract/tracker-extract-tiff.c.orig Mon Sep 26 11:27:18 2011
+++ src/tracker-extract/tracker-extract-tiff.c Mon Sep 26 12:31:34 2011
@@ -291,10 +291,14 @@ tracker_extract_get_metadata (TrackerExtractInfo *info
--- src/tracker-extract/tracker-extract-tiff.c.orig Fri Dec 16 16:24:23 2011
+++ src/tracker-extract/tracker-extract-tiff.c Tue Jan 10 09:19:37 2012
@@ -291,10 +291,7 @@ tracker_extract_get_metadata (TrackerExtractInfo *info
metadata = tracker_extract_info_get_metadata_builder (info);
graph = tracker_extract_info_get_graph (info);
+#if defined(__linux__)
fd = g_open (filename, O_RDONLY | O_NOATIME, 0);
if (fd == -1 && errno == EPERM) {
fd = g_open (filename, O_RDONLY, 0);
}
+#else
+ fd = g_open (filename, O_RDONLY, 0);
+#endif
- fd = g_open (filename, O_RDONLY | O_NOATIME, 0);
- if (fd == -1 && errno == EPERM) {
- fd = g_open (filename, O_RDONLY, 0);
- }
+ fd = tracker_file_open_fd (filename);
if (fd == -1) {
g_warning ("Could not open tiff file '%s': %s\n",

View File

@ -1,21 +1,18 @@
$OpenBSD: patch-src_tracker-extract_tracker-extract-xmp_c,v 1.3 2011/12/21 14:20:06 ajacoutot Exp $
$OpenBSD: patch-src_tracker-extract_tracker-extract-xmp_c,v 1.4 2012/01/22 15:13:23 ajacoutot Exp $
https://bugzilla.gnome.org/show_bug.cgi?id=666654
--- src/tracker-extract/tracker-extract-xmp.c.orig Mon Sep 26 11:27:38 2011
+++ src/tracker-extract/tracker-extract-xmp.c Mon Sep 26 12:31:47 2011
@@ -154,10 +154,14 @@ tracker_extract_get_metadata (TrackerExtractInfo *info
--- src/tracker-extract/tracker-extract-xmp.c.orig Fri Dec 16 16:24:23 2011
+++ src/tracker-extract/tracker-extract-xmp.c Tue Jan 10 09:19:59 2012
@@ -154,10 +154,7 @@ tracker_extract_get_metadata (TrackerExtractInfo *info
preupdate = tracker_extract_info_get_preupdate_builder (info);
metadata = tracker_extract_info_get_metadata_builder (info);
+#if defined(__linux__)
fd = g_open (filename, O_RDONLY | O_NOATIME, 0);
if (fd == -1 && errno == EPERM) {
fd = g_open (filename, O_RDONLY, 0);
}
+#else
+ fd = g_open (filename, O_RDONLY, 0);
+#endif
- fd = g_open (filename, O_RDONLY | O_NOATIME, 0);
- if (fd == -1 && errno == EPERM) {
- fd = g_open (filename, O_RDONLY, 0);
- }
+ fd = tracker_file_open_fd (filename);
if (fd == -1) {
g_warning ("Could not open xmp file '%s': %s\n",