From c447dfbb9d5da76f1826027b3fdbdaa7d45fca63 Mon Sep 17 00:00:00 2001 From: Armin K Date: Fri, 6 Dec 2013 17:56:11 +0100 Subject: [PATCH] Add an environment variable to disable fdatasync() It takes a long time to run update-mime-database when fdatasync() is initiated. It takes longer time when update-mime-database is ran several times using package manager post-install trigers. For package managers that run fdatasync() themself, use PKGSYSTEM_DISABLE_FSYNC environment variable to prevent running fdatasync() several times. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=70366 --- update-mime-database.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/update-mime-database.c b/update-mime-database.c index 90c915b..872eb48 100644 --- a/update-mime-database.c +++ b/update-mime-database.c @@ -951,21 +951,23 @@ 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; + if (!g_getenv ("PKGSYSTEM_DISABLE_FSYNC")) { + 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.8.5.1