all: use g_error_matches()
authorDan Winship <danw@gnome.org>
Tue, 8 Apr 2014 16:00:09 +0000 (12:00 -0400)
committerThomas Haller <thaller@redhat.com>
Thu, 3 Mar 2016 17:54:20 +0000 (18:54 +0100)
Use g_error_matches() where we're testing error codes. In particular,
use it rather than looking at only ->code and not also ->domain, which
is just wrong.

[thaller@redhat.com: rebase and modify original patch]

clients/cli/connections.c
libnm-glib/nm-remote-settings.c
src/settings/nm-settings-connection.c

index d9b90a1..4cb85f7 100644 (file)
@@ -7898,7 +7898,7 @@ load_history_cmds (const char *uuid)
        filename = g_build_filename (g_get_home_dir (), NMCLI_EDITOR_HISTORY, NULL);
        kf = g_key_file_new ();
        if (!g_key_file_load_from_file (kf, filename, G_KEY_FILE_KEEP_COMMENTS, &err)) {
-               if (err->code == G_KEY_FILE_ERROR_PARSE)
+               if (g_error_matches (err, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_PARSE))
                        g_print ("Warning: %s parse error: %s\n", filename, err->message);
                g_key_file_free (kf);
                g_free (filename);
@@ -7933,8 +7933,8 @@ save_history_cmds (const char *uuid)
                filename = g_build_filename (g_get_home_dir (), NMCLI_EDITOR_HISTORY, NULL);
                kf = g_key_file_new ();
                if (!g_key_file_load_from_file (kf, filename, G_KEY_FILE_KEEP_COMMENTS, &err)) {
-                       if (   err->code != G_FILE_ERROR_NOENT
-                           && err->code != G_KEY_FILE_ERROR_NOT_FOUND) {
+                       if (   !g_error_matches (err, G_FILE_ERROR, G_FILE_ERROR_NOENT)
+                           && !g_error_matches (err, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_NOT_FOUND)) {
                                g_print ("Warning: %s parse error: %s\n", filename, err->message);
                                g_key_file_free (kf);
                                g_free (filename);
index fa2b325..42d90f6 100644 (file)
@@ -503,7 +503,7 @@ connection_inited (GObject *source, GAsyncResult *result, gpointer user_data)
                if (!dbus_g_error_has_name (error, "org.freedesktop.NetworkManager.Settings.PermissionDenied"))
                        g_hash_table_remove (priv->pending, path);
 
-               if (print_once && error->code == DBUS_GERROR_LIMITS_EXCEEDED) {
+               if (print_once && g_error_matches (error, DBUS_GERROR, DBUS_GERROR_LIMITS_EXCEEDED)) {
                        g_printerr ("Warning: libnm-glib:%s(): a D-Bus limit exceeded: %s. The application might not work properly.\n"
                                    "Consider increasing max_replies_per_connection limit in /etc/dbus-1/system.d/org.freedesktop.NetworkManager.conf "
                                    "like <limit name=\"max_replies_per_connection\">2048</limit>",
index 72f571f..5f444ea 100644 (file)
@@ -2163,7 +2163,7 @@ nm_settings_connection_update_timestamp (NMSettingsConnection *self,
        /* Save timestamp to timestamps database file */
        timestamps_file = g_key_file_new ();
        if (!g_key_file_load_from_file (timestamps_file, SETTINGS_TIMESTAMPS_FILE, G_KEY_FILE_KEEP_COMMENTS, &error)) {
-               if (!(error->domain == G_FILE_ERROR && error->code == G_FILE_ERROR_NOENT))
+               if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
                        _LOGW ("error parsing timestamps file '%s': %s", SETTINGS_TIMESTAMPS_FILE, error->message);
                g_clear_error (&error);
        }
@@ -2172,7 +2172,7 @@ nm_settings_connection_update_timestamp (NMSettingsConnection *self,
        tmp = g_strdup_printf ("%" G_GUINT64_FORMAT, timestamp);
        g_key_file_set_value (timestamps_file, "timestamps", connection_uuid, tmp);
        g_free (tmp);
+
        data = g_key_file_to_data (timestamps_file, &len, &error);
        if (data) {
                g_file_set_contents (SETTINGS_TIMESTAMPS_FILE, data, len, &error);