From 4b1400415083a13f7b8ad8b37763ef327e3bcbe9 Mon Sep 17 00:00:00 2001 From: Rex Dieter Date: Fri, 23 May 2014 07:29:14 -0500 Subject: [PATCH] PKGSYSTEM_ENABLE_FSYNC env var opt-in to fdatasync Recent fdatasync() support in update-mime-database results in large slowdown (x40 or more slower in some cases), and it's unclear the safety benefits outweigh this cost. In the meantime, make this feature opt-in via environment variable PKGSYSTEM_ENABLE_FSYNC Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=70366 --- update-mime-database.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/update-mime-database.c b/update-mime-database.c index c043606..c9e3033 100644 --- a/update-mime-database.c +++ b/update-mime-database.c @@ -943,6 +943,7 @@ static gboolean atomic_update(const gchar *pathname, GError **error) gchar *new_name = NULL; int len; int fd; + const gchar *enable_fsync; len = strlen(pathname); @@ -951,21 +952,24 @@ static gboolean atomic_update(const gchar *pathname, GError **error) new_name = g_strndup(pathname, len - 4); #ifdef HAVE_FDATASYNC - fd = open(pathname, O_RDWR); - if (fd == -1) - { - set_error_from_errno(error); - goto out; - } - if (fdatasync(fd) == -1) - { - set_error_from_errno(error); - goto out; - } - if (close(fd) == -1) - { - set_error_from_errno(error); - goto out; + enable_fsync = g_getenv("PKGSYSTEM_ENABLE_FSYNC"); + if ( enable_fsync && (g_strcmp0(enable_fsync,"0") != 0) ) { + fd = open(pathname, O_RDWR); + if (fd == -1) + { + set_error_from_errno(error); + goto out; + } + if (fdatasync(fd) == -1) + { + set_error_from_errno(error); + goto out; + } + if (close(fd) == -1) + { + set_error_from_errno(error); + goto out; + } } #endif -- 1.9.3