[libgsystem] Only use fdatasync() on Linux



commit 1bd16c24706b9053d7d9c509c137fe963cd5e319
Author: Ryan Lortie <desrt desrt ca>
Date:   Sun Dec 8 19:01:17 2013 -0500

    Only use fdatasync() on Linux
    
    This function is not universally available, and since we don't have our
    own autoconf script to check for it, just assume that we have it iff
    we're on Linux.

 gsystem-file-utils.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)
---
diff --git a/gsystem-file-utils.c b/gsystem-file-utils.c
index 639caca..c758a1f 100644
--- a/gsystem-file-utils.c
+++ b/gsystem-file-utils.c
@@ -277,8 +277,8 @@ gs_file_map_readonly (GFile         *file,
  * @cancellable:
  * @error:
  *
- * Wraps the UNIX fdatasync() function, which ensures that the data in
- * @file is on non-volatile storage.
+ * Wraps the UNIX fsync() function (or fdatasync(), if available), which
+ * ensures that the data in @file is on non-volatile storage.
  */
 gboolean
 gs_file_sync_data (GFile          *file,
@@ -294,7 +294,13 @@ gs_file_sync_data (GFile          *file,
     goto out;
 
   do
-    res = fdatasync (fd);
+    {
+#ifdef __linux
+      res = fdatasync (fd);
+#else
+      res = fsync (fd);
+#endif
+    }
   while (G_UNLIKELY (res != 0 && errno == EINTR));
   if (res != 0)
     {
@@ -619,7 +625,7 @@ linkcopy_internal_attempt (GFile          *src,
       
   if (sync_data)
     {
-      /* Now, we need to fdatasync */
+      /* Now, we need to fsync */
       if (!gs_file_sync_data (tmp_dest, cancellable, error))
         goto out;
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]