include PKGSYSTEM_ENABLE_FSYNC upstream implementation, except default off (#1052173)

This commit is contained in:
Rex Dieter 2014-06-26 07:10:02 -05:00
parent 45e4853b92
commit 7ecbd4c206
5 changed files with 153 additions and 23 deletions

View File

@ -0,0 +1,80 @@
From fd48920cf82402a95f658cab93db0cf3786c4d6e Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Wed, 25 Jun 2014 17:23:50 +0200
Subject: [PATCH 7/8] Split out fdatasync() usage
---
update-mime-database.c | 38 ++++++++++++++++++++++++--------------
1 file changed, 24 insertions(+), 14 deletions(-)
diff --git a/update-mime-database.c b/update-mime-database.c
index c043606..c1a6f9f 100644
--- a/update-mime-database.c
+++ b/update-mime-database.c
@@ -936,39 +936,49 @@ 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)
+static int
+sync_file(const gchar *pathname, GError **error)
{
- gboolean ret = FALSE;
- gchar *new_name = NULL;
- int len;
int fd;
- len = strlen(pathname);
-
- g_return_val_if_fail(strcmp(pathname + len - 4, ".new") == 0, FALSE);
-
- 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;
+ 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);
--
1.9.3

View File

@ -0,0 +1,47 @@
From 1f7683bfcbecbeffa802a1c361e1842db2fff4f8 Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Wed, 25 Jun 2014 17:25:50 +0200
Subject: [PATCH 8/8] Disable fdatasync() usage if PKGSYSTEM_ENABLE_FSYNC is
set
If the PKGSYSTEM_ENABLE_FSYNC envvar is set to a non-zero value,
the fdatasync() call will be skipped, at the expense of data integrity.
https://bugs.freedesktop.org/show_bug.cgi?id=70366
---
update-mime-database.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/update-mime-database.c b/update-mime-database.c
index c1a6f9f..894ac97 100644
--- a/update-mime-database.c
+++ b/update-mime-database.c
@@ -936,11 +936,25 @@ set_error_from_errno (GError **error)
g_strerror(errsv));
}
+static gboolean
+sync_enabled(void)
+{
+ const char *env;
+
+ env = g_getenv("PKGSYSTEM_ENABLE_FSYNC");
+ if (!env)
+ return TRUE;
+ return atoi(env);
+}
+
static int
sync_file(const gchar *pathname, GError **error)
{
int fd;
+ if (!sync_enabled())
+ return 0;
+
#ifdef HAVE_FDATASYNC
fd = open(pathname, O_RDWR);
if (fd == -1)
--
1.9.3

View File

@ -0,0 +1,13 @@
diff --git a/update-mime-database.c b/update-mime-database.c
index 894ac97..8626702 100644
--- a/update-mime-database.c
+++ b/update-mime-database.c
@@ -943,7 +943,7 @@ sync_enabled(void)
env = g_getenv("PKGSYSTEM_ENABLE_FSYNC");
if (!env)
- return TRUE;
+ return FALSE;
return atoi(env);
}

View File

@ -1,19 +0,0 @@
diff -up shared-mime-info-1.3/update-mime-database.c.PKGSYSTEM_FSYNC shared-mime-info-1.3/update-mime-database.c
--- shared-mime-info-1.3/update-mime-database.c.PKGSYSTEM_FSYNC 2014-03-31 09:24:23.000000000 -0500
+++ shared-mime-info-1.3/update-mime-database.c 2014-05-21 12:35:10.695476575 -0500
@@ -951,6 +951,7 @@ static gboolean atomic_update(const gcha
new_name = g_strndup(pathname, len - 4);
#ifdef HAVE_FDATASYNC
+ if (g_getenv ("PKGSYSTEM_ENABLE_FSYNC")) {
fd = open(pathname, O_RDWR);
if (fd == -1)
{
@@ -967,6 +968,7 @@ static gboolean atomic_update(const gcha
set_error_from_errno(error);
goto out;
}
+ }
#endif
#ifdef _WIN32

View File

@ -1,7 +1,7 @@
Summary: Shared MIME information database
Name: shared-mime-info
Version: 1.3
Release: 4%{?dist}
Release: 5%{?dist}
License: GPLv2+
Group: System Environment/Base
URL: http://freedesktop.org/Software/shared-mime-info
@ -21,8 +21,12 @@ Source4: shotwell-viewer-defaults.list
Patch0: 0001-Remove-sub-classing-from-OO.o-mime-types.patch
# support PKGSYSTEM_ENABLE_FSYNC
# https://bugs.freedesktop.org/show_bug.cgi?id=70366#c19
Patch1: shared-mime-info-1.3-PKGSYSTEM_FSYNC.patch
# https://bugs.freedesktop.org/show_bug.cgi?id=70366#c30
Patch1: 0007-Split-out-fdatasync-usage.patch
Patch2: 0008-Disable-fdatasync-usage-if-PKGSYSTEM_ENABLE_FSYNC-is.patch
# set PKGSYSTEM_ENABLE_FSYNC default off
#https://bugzilla.redhat.com/show_bug.cgi?id=1052173#c14
Patch3: PKGSYSTEM_ENABLE_FSYNC-default_off.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: libxml2-devel
@ -44,7 +48,9 @@ and looking up the correct MIME type in a database.
%prep
%setup -q
%patch0 -p1 -b .ooo-zip
%patch1 -p1 -b .PKGSYSTEM_FSYNC
%patch1 -p1 -b .0007
%patch2 -p1 -b .0008
%patch3 -p1 -b .PKGSYSTEM_ENABLE_FSYNC-default_off
%build
@ -92,6 +98,9 @@ rm -rf $RPM_BUILD_ROOT%{_datadir}/locale/*
%{_mandir}/man*/*
%changelog
* Thu Jun 26 2014 Rex Dieter <rdieter@fedoraproject.org> 1.3-5
- include PKGSYSTEM_ENABLE_FSYNC upstream implementation, except default off (#1052173)
* Sun Jun 08 2014 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.3-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_Mass_Rebuild