state: remove support for groups and propagate save errors

There is no real use for groups in our API. Just use the name of
the file as the default group and be done with it...
Storing multiple groups with this API is problematic because it
forces flushing the file to disk multiple times, one for each group,
and it's just more performant if we use a prefix in the keys
to implement some form of logical separation.

This commit also makes the GKeyFile a temporary object. As we
always load the file from the file system in _load()
and we always replace its contents with a new dictionary in _save(),
there is no point in keeping the keyfile's internal data structures
stored in memory.

Save errors are now also propagated to adhere to the programming
practices of GObject
This commit is contained in:
George Kiagiadakis
2021-06-04 18:22:48 +03:00
parent 4948f6f2f6
commit 38f7483793
7 changed files with 66 additions and 108 deletions

View File

@@ -1123,20 +1123,20 @@ static int
state_save (lua_State *L)
{
WpState *state = wplua_checkobject (L, 1, WP_TYPE_STATE);
const gchar *group = luaL_checkstring (L, 2);
luaL_checktype (L, 3, LUA_TTABLE);
g_autoptr (WpProperties) props = wplua_table_to_properties (L, 3);
gboolean ret = wp_state_save (state, group, props);
lua_pushboolean (L, ret);
return 1;
luaL_checktype (L, 2, LUA_TTABLE);
g_autoptr (WpProperties) props = wplua_table_to_properties (L, 2);
g_autoptr (GError) error = NULL;
gboolean saved = wp_state_save (state, props, &error);
lua_pushboolean (L, saved);
lua_pushstring (L, error ? error->message : "");
return 2;
}
static int
state_load (lua_State *L)
{
WpState *state = wplua_checkobject (L, 1, WP_TYPE_STATE);
const gchar *group = luaL_checkstring (L, 2);
g_autoptr (WpProperties) props = wp_state_load (state, group);
g_autoptr (WpProperties) props = wp_state_load (state);
wplua_properties_to_table (L, props);
return 1;
}