[gnome-battery-bench] Try to trigger an fsync when writing the log file



commit 886d4d8f47bf7d0f12ef92e8e5fffc0981c3747d
Author: Christian Kellner <gicmo gnome org>
Date:   Tue Mar 7 16:50:26 2017 +0100

    Try to trigger an fsync when writing the log file
    
    We pre-create the logfile in order to trigger an fsync in the
    g_file_set_contents call, which will do that on an atomic replace
    but not for new files.

 src/test-run.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
---
diff --git a/src/test-run.c b/src/test-run.c
index 8d91112..751c16d 100644
--- a/src/test-run.c
+++ b/src/test-run.c
@@ -428,7 +428,16 @@ gbb_test_run_write_to_file(GbbTestRun *run,
     json_generator_set_pretty(generator, TRUE);
     json_generator_set_root(generator, root);
 
-    gboolean success = json_generator_to_file (generator, filename, error);
+    /* Small hack to force a fsync() on the file: pre-create the file
+     * with non-zero content which will make g_file_set_contents()
+     * call fsync() since this is now an atomic replace. We don't
+     * really care this first g_file_set_contents fails.
+     */
+    g_file_set_contents(filename, "gnome-battery-bench", 20, NULL);
+    gsize len;
+    gchar *buffer = json_generator_to_data (generator, &len);
+    gboolean success = g_file_set_contents(filename, buffer, len, error);
+    g_free(buffer);
 
     g_object_unref(generator);
     json_node_free(root);


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