summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2014-06-25 17:23:50 +0200
committerBastien Nocera <hadess@hadess.net>2014-06-25 17:23:50 +0200
commitfd48920cf82402a95f658cab93db0cf3786c4d6e (patch)
tree4404b372b92b21b7171dd9ca8b3caff3d18db7c0
parentb7154bbd3baa6ae28cd06b7f7b13f4a26b6cc03a (diff)
downloadshared-mime-info-fd48920cf82402a95f658cab93db0cf3786c4d6e.tar.gz
Split out fdatasync() usage
-rw-r--r--update-mime-database.c38
1 files changed, 24 insertions, 14 deletions
diff --git a/update-mime-database.c b/update-mime-database.c
index c043606a..c1a6f9fc 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);