bootconfig: Add ostree_bootconfig_parser_write_at
authorColin Walters <walters@verbum.org>
Tue, 21 Apr 2015 02:23:39 +0000 (22:23 -0400)
committerColin Walters <walters@verbum.org>
Sat, 19 Dec 2015 13:24:51 +0000 (08:24 -0500)
This fd-relative API will be used by later libostree porting in the
deploy code path.

src/libostree/ostree-bootconfig-parser.c
src/libostree/ostree-bootconfig-parser.h

index 6320b5bbe2bd85da6e29c15a47b6648129a41120..661e759da11e19af7946298aff29caf35e82370a 100644 (file)
@@ -158,18 +158,18 @@ write_key (OstreeBootconfigParser    *self,
   g_string_append (buf, value);
   g_string_append_c (buf, '\n');
 }
-           
+
 gboolean
-ostree_bootconfig_parser_write (OstreeBootconfigParser   *self,
-                                GFile            *output,
-                                GCancellable     *cancellable,
-                                GError          **error)
+ostree_bootconfig_parser_write_at (OstreeBootconfigParser   *self,
+                                   int                       dfd,
+                                   const char               *path,
+                                   GCancellable             *cancellable,
+                                   GError                  **error)
 {
   gboolean ret = FALSE;
   GHashTableIter hashiter;
   gpointer hashkey, hashvalue;
   GString *buf = g_string_new ("");
-  g_autoptr(GBytes) bytes = NULL;
   guint i;
   g_autoptr(GHashTable) written_overrides = NULL;
 
@@ -205,18 +205,28 @@ ostree_bootconfig_parser_write (OstreeBootconfigParser   *self,
       write_key (self, buf, hashkey, hashvalue);
     }
 
-  bytes = g_string_free_to_bytes (buf);
-  buf = NULL;
-
-  if (!ot_gfile_replace_contents_fsync (output, bytes,
-                                        cancellable, error))
+  if (!glnx_file_replace_contents_at (dfd, path, (guint8*)buf->str, buf->len,
+                                      GLNX_FILE_REPLACE_NODATASYNC,
+                                      cancellable, error))
     goto out;
 
   ret = TRUE;
  out:
-  if (buf) g_string_free (buf, TRUE);
+  if (buf)
+    g_string_free (buf, TRUE);
   return ret;
 }
+           
+gboolean
+ostree_bootconfig_parser_write (OstreeBootconfigParser   *self,
+                                GFile            *output,
+                                GCancellable     *cancellable,
+                                GError          **error)
+{
+  return ostree_bootconfig_parser_write_at (self,
+                                            AT_FDCWD, gs_file_get_path_cached (output),
+                                            cancellable, error);
+}
 
 static void
 ostree_bootconfig_parser_finalize (GObject *object)
index 7ff2235078e4ab1750b4dbb5212584a09888ea77..47dac9c9ad5d782f40284bfd6516eae128b14061 100644 (file)
@@ -52,6 +52,12 @@ gboolean ostree_bootconfig_parser_write (OstreeBootconfigParser   *self,
                                          GCancellable     *cancellable,
                                          GError          **error);
 
+gboolean ostree_bootconfig_parser_write_at (OstreeBootconfigParser   *self,
+                                            int                       dfd,
+                                            const char               *path,
+                                            GCancellable             *cancellable,
+                                            GError                  **error);
+
 void ostree_bootconfig_parser_set (OstreeBootconfigParser  *self,
                                    const char      *key,
                                    const char      *value);