mirror of
https://github.com/flatpak/flatpak.git
synced 2026-10-25 00:49:28 -04:00
gvdb: Add gvdb_table_get_content
This is useful if you want to apply outstanding changes to a table withough immediately persisting it to disk.
This commit is contained in:
1 parent
a9ffa4960d
commit
2d0866cac8
2 files changed
+29
-8
No files matched your search
+24
-8
@@ -499,23 +499,39 @@ file_builder_serialise (FileBuilder *fb,
|
||||
return result;
|
||||
}
|
||||
|
||||
GBytes *
|
||||
gvdb_table_get_content (GHashTable *table,
|
||||
gboolean byteswap)
|
||||
{
|
||||
struct gvdb_pointer root;
|
||||
FileBuilder *fb;
|
||||
GString *str;
|
||||
GBytes *res;
|
||||
|
||||
fb = file_builder_new (byteswap);
|
||||
file_builder_add_hash (fb, table, &root);
|
||||
str = file_builder_serialise (fb, root);
|
||||
|
||||
res = g_bytes_new_take (str->str, str->len);
|
||||
g_string_free (str, FALSE);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gvdb_table_write_contents (GHashTable *table,
|
||||
const gchar *filename,
|
||||
gboolean byteswap,
|
||||
GError **error)
|
||||
{
|
||||
struct gvdb_pointer root;
|
||||
GBytes *content;
|
||||
gboolean status;
|
||||
FileBuilder *fb;
|
||||
GString *str;
|
||||
|
||||
fb = file_builder_new (byteswap);
|
||||
file_builder_add_hash (fb, table, &root);
|
||||
str = file_builder_serialise (fb, root);
|
||||
content = gvdb_table_get_content (table, byteswap);
|
||||
|
||||
status = g_file_set_contents (filename, str->str, str->len, error);
|
||||
g_string_free (str, TRUE);
|
||||
status = g_file_set_contents (filename, g_bytes_get_data (content, NULL), g_bytes_get_size (content), error);
|
||||
|
||||
g_bytes_unref (content);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -52,4 +52,9 @@ gboolean gvdb_table_write_contents (GHashTa
|
||||
gboolean byteswap,
|
||||
GError **error);
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
GBytes * gvdb_table_get_content (GHashTable *table,
|
||||
gboolean byteswap);
|
||||
|
||||
|
||||
#endif /* __gvdb_builder_h__ */
|
||||
Reference in new issue
Block a user