deploy: fdatasync() bootloader configuration files
Yet more data we're writing out that needs to be sync'd.
This commit is contained in:
parent
18aaa49724
commit
646c8be8dc
|
|
@ -21,7 +21,7 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "ostree-bootconfig-parser.h"
|
#include "ostree-bootconfig-parser.h"
|
||||||
#include "libgsystem.h"
|
#include "otutil.h"
|
||||||
|
|
||||||
struct _OstreeBootconfigParser
|
struct _OstreeBootconfigParser
|
||||||
{
|
{
|
||||||
|
|
@ -126,28 +126,16 @@ ostree_bootconfig_parser_get (OstreeBootconfigParser *self,
|
||||||
return g_hash_table_lookup (self->options, key);
|
return g_hash_table_lookup (self->options, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static void
|
||||||
write_key (OstreeBootconfigParser *self,
|
write_key (OstreeBootconfigParser *self,
|
||||||
GDataOutputStream *out,
|
GString *buf,
|
||||||
const char *key,
|
const char *key,
|
||||||
const char *value,
|
const char *value)
|
||||||
GCancellable *cancellable,
|
|
||||||
GError **error)
|
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
g_string_append (buf, key);
|
||||||
|
g_string_append_c (buf, self->separators[0]);
|
||||||
if (!g_data_output_stream_put_string (out, key, cancellable, error))
|
g_string_append (buf, value);
|
||||||
goto out;
|
g_string_append_c (buf, '\n');
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
|
|
@ -159,19 +147,13 @@ ostree_bootconfig_parser_write (OstreeBootconfigParser *self,
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
GHashTableIter hashiter;
|
GHashTableIter hashiter;
|
||||||
gpointer hashkey, hashvalue;
|
gpointer hashkey, hashvalue;
|
||||||
gs_unref_object GOutputStream *out = NULL;
|
GString *buf = g_string_new ("");
|
||||||
gs_unref_object GDataOutputStream *dataout = NULL;
|
gs_unref_bytes GBytes *bytes = NULL;
|
||||||
guint i;
|
guint i;
|
||||||
gs_unref_hashtable GHashTable *written_overrides = NULL;
|
gs_unref_hashtable GHashTable *written_overrides = NULL;
|
||||||
|
|
||||||
written_overrides = g_hash_table_new (g_str_hash, g_str_equal);
|
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++)
|
for (i = 0; i < self->lines->len; i++)
|
||||||
{
|
{
|
||||||
GVariant *linedata = self->lines->pdata[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);
|
value = g_hash_table_lookup (self->options, key);
|
||||||
if (value == NULL)
|
if (value == NULL)
|
||||||
{
|
{
|
||||||
if (!g_data_output_stream_put_string (dataout, line, cancellable, error))
|
g_string_append (buf, line);
|
||||||
goto out;
|
g_string_append_c (buf, '\n');
|
||||||
if (!g_data_output_stream_put_byte (dataout, '\n', cancellable, error))
|
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!write_key (self, dataout, key, value, cancellable, error))
|
write_key (self, buf, key, value);
|
||||||
goto out;
|
|
||||||
g_hash_table_insert (written_overrides, (gpointer)key, (gpointer)key);
|
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))
|
if (g_hash_table_lookup (written_overrides, hashkey))
|
||||||
continue;
|
continue;
|
||||||
if (!write_key (self, dataout, hashkey, hashvalue, cancellable, error))
|
write_key (self, buf, hashkey, hashvalue);
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
goto out;
|
||||||
|
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
out:
|
out:
|
||||||
|
if (buf) g_string_free (buf, TRUE);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue