File shared-mime-info-disable-fdatasync-in-installation.patch of Package shared-mime-info.1563
From 5c8476b91d5c24ec5a44ec8bb2de42172e4cd405 Mon Sep 17 00:00:00 2001
From: Felix Zhang <fezhang@suse.com>
Date: Mon, 14 Dec 2015 16:41:54 +0800
Subject: [PATCH] disable fdatasync in installation
---
update-mime-database.c | 60 ++++++++++++++++++++++++++++++++++++++------------
1 file changed, 46 insertions(+), 14 deletions(-)
diff --git a/update-mime-database.c b/update-mime-database.c
index 86e7365..a8c6c57 100644
--- a/update-mime-database.c
+++ b/update-mime-database.c
@@ -936,39 +936,71 @@ set_error_from_errno (GError **error)
g_strerror(errsv));
}
-/* Renames pathname by removing the .new extension */
-static gboolean atomic_update(const gchar *pathname, GError **error)
+#ifdef HAVE_FDATASYNC
+static gboolean
+sync_enabled(void)
{
- gboolean ret = FALSE;
- gchar *new_name = NULL;
- int len;
- int fd;
-
- len = strlen(pathname);
+ const char *env;
- g_return_val_if_fail(strcmp(pathname + len - 4, ".new") == 0, FALSE);
+ env = g_getenv("PKGSYSTEM_ENABLE_FSYNC");
+ if (!env)
+ return TRUE;
+ return atoi(env);
+}
- new_name = g_strndup(pathname, len - 4);
+static gboolean
+install_in_progress(void)
+{
+ return (g_strcmp0 (g_getenv ("YAST_IS_RUNNING"), "instsys") == 0);
+}
+#endif
+static int
+sync_file(const gchar *pathname, GError **error)
+{
#ifdef HAVE_FDATASYNC
- fd = open(pathname, O_RDONLY);
+ int fd;
+
+ if (!sync_enabled() || install_in_progress())
+ return 0;
+
+ fd = open(pathname, O_RDWR);
if (fd == -1)
{
set_error_from_errno(error);
- goto out;
+ return -1;
}
if (fdatasync(fd) == -1)
{
set_error_from_errno(error);
- goto out;
+ return -1;
}
if (close(fd) == -1)
{
set_error_from_errno(error);
- goto out;
+ return -1;
}
#endif
+ return 0;
+}
+
+/* Renames pathname by removing the .new extension */
+static gboolean atomic_update(const gchar *pathname, GError **error)
+{
+ gboolean ret = FALSE;
+ gchar *new_name = NULL;
+ int len;
+
+ len = strlen(pathname);
+
+ g_return_val_if_fail(strcmp(pathname + len - 4, ".new") == 0, FALSE);
+
+ new_name = g_strndup(pathname, len - 4);
+
+ if (sync_file(pathname, error) == -1)
+ goto out;
+
#ifdef _WIN32
/* we need to remove the old file first! */
remove(new_name);
--
2.1.4