[ostree] deploy: fdatasync() bootloader configuration files



commit 646c8be8dc6b99f9fed208bdc31db299a3445373
Author: Colin Walters <walters verbum org>
Date:   Tue Apr 8 18:48:08 2014 -0400

    deploy: fdatasync() bootloader configuration files
    
    Yet more data we're writing out that needs to be sync'd.

 src/libostree/ostree-bootconfig-parser.c |   61 +++++++++++-------------------
 1 files changed, 22 insertions(+), 39 deletions(-)
---
diff --git a/src/libostree/ostree-bootconfig-parser.c b/src/libostree/ostree-bootconfig-parser.c
index f002a18..ae81798 100644
--- a/src/libostree/ostree-bootconfig-parser.c
+++ b/src/libostree/ostree-bootconfig-parser.c
@@ -21,7 +21,7 @@
 #include "config.h"
 
 #include "ostree-bootconfig-parser.h"
-#include "libgsystem.h"
+#include "otutil.h"
 
 struct _OstreeBootconfigParser
 {
@@ -126,28 +126,16 @@ ostree_bootconfig_parser_get (OstreeBootconfigParser  *self,
   return g_hash_table_lookup (self->options, key);
 }
 
-static gboolean
-write_key (OstreeBootconfigParser         *self,
-           GDataOutputStream      *out,
-           const char             *key,
-           const char             *value,
-           GCancellable           *cancellable,
-           GError                **error)
+static void
+write_key (OstreeBootconfigParser    *self,
+           GString                   *buf,
+           const char                *key,
+           const char                *value)
 {
-  gboolean ret = FALSE;
-
-  if (!g_data_output_stream_put_string (out, key, cancellable, error))
-    goto out;
-  if (!g_data_output_stream_put_byte (out, self->separators[0], cancellable, error))
-    goto out;
-  if (!g_data_output_stream_put_string (out, value, cancellable, error))
-    goto out;
-  if (!g_data_output_stream_put_byte (out, '\n', cancellable, error))
-    goto out;
-
-  ret = TRUE;
- out:
-  return ret;
+  g_string_append (buf, key);
+  g_string_append_c (buf, self->separators[0]);
+  g_string_append (buf, value);
+  g_string_append_c (buf, '\n');
 }
            
 gboolean
@@ -159,19 +147,13 @@ ostree_bootconfig_parser_write (OstreeBootconfigParser   *self,
   gboolean ret = FALSE;
   GHashTableIter hashiter;
   gpointer hashkey, hashvalue;
-  gs_unref_object GOutputStream *out = NULL;
-  gs_unref_object GDataOutputStream *dataout = NULL;
+  GString *buf = g_string_new ("");
+  gs_unref_bytes GBytes *bytes = NULL;
   guint i;
   gs_unref_hashtable GHashTable *written_overrides = NULL;
 
   written_overrides = g_hash_table_new (g_str_hash, g_str_equal);
 
-  out = (GOutputStream*)g_file_replace (output, NULL, FALSE, 0, cancellable, error);
-  if (!out)
-    goto out;
-
-  dataout = g_data_output_stream_new (out);
-
   for (i = 0; i < self->lines->len; i++)
     {
       GVariant *linedata = self->lines->pdata[i];
@@ -184,15 +166,12 @@ ostree_bootconfig_parser_write (OstreeBootconfigParser   *self,
       value = g_hash_table_lookup (self->options, key);
       if (value == NULL)
         {
-          if (!g_data_output_stream_put_string (dataout, line, cancellable, error))
-            goto out;
-          if (!g_data_output_stream_put_byte (dataout, '\n', cancellable, error))
-            goto out;
+          g_string_append (buf, line);
+          g_string_append_c (buf, '\n');
         }
       else
         {
-          if (!write_key (self, dataout, key, value, cancellable, error))
-            goto out;
+          write_key (self, buf, key, value);
           g_hash_table_insert (written_overrides, (gpointer)key, (gpointer)key);
         }
     }
@@ -202,15 +181,19 @@ ostree_bootconfig_parser_write (OstreeBootconfigParser   *self,
     {
       if (g_hash_table_lookup (written_overrides, hashkey))
         continue;
-      if (!write_key (self, dataout, hashkey, hashvalue, cancellable, error))
-        goto out;
+      write_key (self, buf, hashkey, hashvalue);
     }
 
-  if (!g_output_stream_close ((GOutputStream*)dataout, cancellable, error))
+  bytes = g_string_free_to_bytes (buf);
+  buf = NULL;
+
+  if (!ot_gfile_replace_contents_fsync (output, bytes,
+                                        cancellable, error))
     goto out;
 
   ret = TRUE;
  out:
+  if (buf) g_string_free (buf, TRUE);
   return ret;
 }
 


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