[gnome-online-accounts/gnome-3-20] daemon, utils: Simplify saving a GKeyFile to a path
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-online-accounts/gnome-3-20] daemon, utils: Simplify saving a GKeyFile to a path
- Date: Mon, 20 Jun 2016 15:01:20 +0000 (UTC)
commit b6e8d5cb5066d073f7120dbceee43aaa544348a9
Author: Debarshi Ray <debarshir gnome org>
Date: Wed May 4 16:59:28 2016 +0200
daemon, utils: Simplify saving a GKeyFile to a path
We can now use g_key_file_save_to_file which wraps g_key_file_to_data
and g_file_set_contents.
At the moment, g_key_file_to_data is documented as never throwing an
error. So we don't lose anything in terms of error reporting. Even if
this changes in the future, I think we can live without a separate
error message for g_key_file_to_data.
Bump minimum GLib version to 2.40.
https://bugzilla.gnome.org/show_bug.cgi?id=688041
configure.ac | 2 +-
src/daemon/goadaemon.c | 37 ++-----------------------------------
src/goabackend/goautils.c | 24 +++---------------------
3 files changed, 6 insertions(+), 57 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 24b7a30..83b18d7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -85,7 +85,7 @@ GTK_DOC_CHECK([1.3])
# Libraries
#
-PKG_CHECK_MODULES(GLIB, [glib-2.0 gio-2.0 gio-unix-2.0 >= 2.35])
+PKG_CHECK_MODULES(GLIB, [glib-2.0 gio-2.0 gio-unix-2.0 >= 2.40])
AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)
diff --git a/src/daemon/goadaemon.c b/src/daemon/goadaemon.c
index f6294e2..55d9ea2 100644
--- a/src/daemon/goadaemon.c
+++ b/src/daemon/goadaemon.c
@@ -914,23 +914,8 @@ get_all_providers_cb (GObject *source,
g_key_file_set_string (key_file, group, key, value);
}
- g_free (key_file_data);
- error = NULL;
- key_file_data = g_key_file_to_data (key_file,
- &length,
- &error);
- if (key_file_data == NULL)
- {
- g_prefix_error (&error, "Error generating key-value-file: ");
- g_dbus_method_invocation_take_error (data->invocation, error);
- goto out;
- }
-
error = NULL;
- if (!g_file_set_contents (path,
- key_file_data,
- length,
- &error))
+ if (!g_key_file_save_to_file (key_file, path, &error))
{
g_prefix_error (&error, "Error writing key-value-file %s: ", path);
g_dbus_method_invocation_take_error (data->invocation, error);
@@ -1011,8 +996,6 @@ on_account_handle_remove (GoaAccount *account,
const gchar *provider_type;
gchar *path;
gchar *group;
- gchar *data;
- gsize length;
GError *error;
provider = NULL;
@@ -1020,7 +1003,6 @@ on_account_handle_remove (GoaAccount *account,
path = NULL;
group = NULL;
key_file = NULL;
- data = NULL;
if (goa_account_get_is_locked (account))
{
@@ -1060,21 +1042,7 @@ on_account_handle_remove (GoaAccount *account,
}
error = NULL;
- data = g_key_file_to_data (key_file,
- &length,
- &error);
- if (data == NULL)
- {
- g_prefix_error (&error, "Error generating key-value-file: ");
- g_dbus_method_invocation_take_error (invocation, error);
- goto out;
- }
-
- error = NULL;
- if (!g_file_set_contents (path,
- data,
- length,
- &error))
+ if (!g_key_file_save_to_file (key_file, path, &error))
{
g_prefix_error (&error, "Error writing key-value-file %s: ", path);
g_dbus_method_invocation_take_error (invocation, error);
@@ -1119,7 +1087,6 @@ on_account_handle_remove (GoaAccount *account,
out:
g_clear_object (&provider);
- g_free (data);
g_clear_pointer (&key_file, (GDestroyNotify) g_key_file_free);
g_free (group);
g_free (path);
diff --git a/src/goabackend/goautils.c b/src/goabackend/goautils.c
index 498b8c5..b06e4ae 100644
--- a/src/goabackend/goautils.c
+++ b/src/goabackend/goautils.c
@@ -385,12 +385,8 @@ goa_utils_keyfile_remove_key (GoaAccount *account, const gchar *key)
{
GError *error;
GKeyFile *key_file;
- gchar *contents;
gchar *group;
gchar *path;
- gsize length;
-
- contents = NULL;
path = g_strdup_printf ("%s/goa-1.0/accounts.conf", g_get_user_config_dir ());
group = g_strdup_printf ("Account %s", goa_account_get_id (account));
@@ -412,10 +408,9 @@ goa_utils_keyfile_remove_key (GoaAccount *account, const gchar *key)
}
g_key_file_remove_key (key_file, group, key, NULL);
- contents = g_key_file_to_data (key_file, &length, NULL);
error = NULL;
- if (!g_file_set_contents (path, contents, length, &error))
+ if (!g_key_file_save_to_file (key_file, path, &error))
{
g_prefix_error (&error, "Error writing key-value-file %s: ", path);
g_warning ("%s (%s, %d)", error->message, g_quark_to_string (error->domain), error->code);
@@ -424,7 +419,6 @@ goa_utils_keyfile_remove_key (GoaAccount *account, const gchar *key)
}
out:
- g_free (contents);
g_key_file_free (key_file);
g_free (group);
g_free (path);
@@ -435,12 +429,8 @@ goa_utils_keyfile_set_boolean (GoaAccount *account, const gchar *key, gboolean v
{
GError *error;
GKeyFile *key_file;
- gchar *contents;
gchar *group;
gchar *path;
- gsize length;
-
- contents = NULL;
path = g_strdup_printf ("%s/goa-1.0/accounts.conf", g_get_user_config_dir ());
group = g_strdup_printf ("Account %s", goa_account_get_id (account));
@@ -462,10 +452,9 @@ goa_utils_keyfile_set_boolean (GoaAccount *account, const gchar *key, gboolean v
}
g_key_file_set_boolean (key_file, group, key, value);
- contents = g_key_file_to_data (key_file, &length, NULL);
error = NULL;
- if (!g_file_set_contents (path, contents, length, &error))
+ if (!g_key_file_save_to_file (key_file, path, &error))
{
g_prefix_error (&error, "Error writing key-value-file %s: ", path);
g_warning ("%s (%s, %d)", error->message, g_quark_to_string (error->domain), error->code);
@@ -474,7 +463,6 @@ goa_utils_keyfile_set_boolean (GoaAccount *account, const gchar *key, gboolean v
}
out:
- g_free (contents);
g_key_file_free (key_file);
g_free (group);
g_free (path);
@@ -485,12 +473,8 @@ goa_utils_keyfile_set_string (GoaAccount *account, const gchar *key, const gchar
{
GError *error;
GKeyFile *key_file;
- gchar *contents;
gchar *group;
gchar *path;
- gsize length;
-
- contents = NULL;
path = g_strdup_printf ("%s/goa-1.0/accounts.conf", g_get_user_config_dir ());
group = g_strdup_printf ("Account %s", goa_account_get_id (account));
@@ -512,10 +496,9 @@ goa_utils_keyfile_set_string (GoaAccount *account, const gchar *key, const gchar
}
g_key_file_set_string (key_file, group, key, value);
- contents = g_key_file_to_data (key_file, &length, NULL);
error = NULL;
- if (!g_file_set_contents (path, contents, length, &error))
+ if (!g_key_file_save_to_file (key_file, path, &error))
{
g_prefix_error (&error, "Error writing key-value-file %s: ", path);
g_warning ("%s (%s, %d)", error->message, g_quark_to_string (error->domain), error->code);
@@ -524,7 +507,6 @@ goa_utils_keyfile_set_string (GoaAccount *account, const gchar *key, const gchar
}
out:
- g_free (contents);
g_key_file_free (key_file);
g_free (group);
g_free (path);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]